Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions docs/en/architecture_design.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,17 @@ The request processing generally includes the following processes:

The service exit process generally includes the following processes:

1. Wait for all requests received by the server to be processed(To avoid being unable to exit due to waiting, the default maximum waiting time is set to 5 seconds.It can be configured through server::stop_max_wait_time);
2. Stop the listening and reading events of the server network connection;
3. Close the server network connections;
4. Call the `Destroy` method of the `TrpcApp` business subclass to stop the dynamic resources created by the business (for example: started threads);
5. Stop the dynamic resources created by the plugins (for example: threads started inside the plugins);
6. Stop the framework runtime environment runtime;
7. Release the resources inside the runtime environment of the framework;
8. Release the internal resources of the framework operating environment TrpcServer;
9. Release the internal resources of the framework operating environment TrpcClient;
10. The program exits;
1. Unregister all services from the name service to prevent future traffic from being routed to this node;
2. Disable the readable event for connections, including:a. Disable the readable event for the listening socket to avoid creating new connections,b. Disable the readable event for the connected socket to avoid receiving new requests from that socket;
3. Wait for all requests received by the server to be processed(To avoid being unable to exit due to waiting, the default maximum waiting time is set to 5 seconds.It can be configured through server::stop_max_wait_time);
4. Close the server network connections;
5. Call the `Destroy` method of the `TrpcApp` business subclass to stop the dynamic resources created by the business (for example: started threads);
6. Stop the dynamic resources created by the plugins (for example: threads started inside the plugins);
7. Stop the framework runtime environment runtime;
8. Release the resources inside the runtime environment of the framework;
9. Release the internal resources of the framework operating environment TrpcServer;
10. Release the internal resources of the framework operating environment TrpcClient;
11. The program exits;

## Client

Expand Down
21 changes: 11 additions & 10 deletions docs/zh/architecture_design.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,17 @@ Server 启动过程, 大致包括以下流程:

服务退出过程, 大致包括以下流程:

1. 等待服务端接收的请求都处理完成(为避免因等待无法退出,默认最多等待5秒钟,可通过yaml中的server::max_wait_time配置);
2. 停止服务端网络连接的监听和读事件;
3. 关闭服务端网络连接;
4. 调用 `TrpcApp` 业务子类的 `Destroy` 方法, 停止业务创建的动态资源(比如: 起的线程);
5. 停止插件创建的动态资源(比如: 插件内部起的线程);
6. 停止框架运行环境runtime;
7. 释放框架运行环境 runtime 内部的资源;
8. 释放框架运行环境 TrpcServer 内部的资源;
9. 释放框架运行环境 TrpcClient 内部的资源;
10. 程序退出;
1. 向名字服务反注册所有service,避免下次流量路由到此节点;
2. 禁用连接可读事件,包括 a.禁用监听socket的可读事件,避免创建新连接;b.禁用已连接socket的可读事件,避免收到该socket的新请求;
3. 等待服务端接收的请求都处理完成(为避免因等待无法退出,默认最多等待5秒钟,可通过yaml中的server::max_wait_time配置);
4. 关闭服务端网络连接;
5. 调用 `TrpcApp` 业务子类的 `Destroy` 方法, 停止业务创建的动态资源(比如: 起的线程);
6. 停止插件创建的动态资源(比如: 插件内部起的线程);
7. 停止框架运行环境runtime;
8. 释放框架运行环境 runtime 内部的资源;
9. 释放框架运行环境 TrpcServer 内部的资源;
10. 释放框架运行环境 TrpcClient 内部的资源;
11. 程序退出;

## 客户端

Expand Down
15 changes: 15 additions & 0 deletions trpc/server/trpc_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,21 @@ void TrpcServer::Stop() {
}
}

// Disable the readable event for the listening socket to avoid creating new connections
// Disable the readable event for the connected socket to avoid receiving new requests
std::vector<ServiceAdapterPtr> stop_listened_adapters;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update doc?

for (const auto& iter : service_adapters_) {
TRPC_LOG_DEBUG(iter.first << " start to StopListen...");
auto stop_listened_adapter_it =
std::find(stop_listened_adapters.begin(), stop_listened_adapters.end(), iter.second);
if (stop_listened_adapter_it != stop_listened_adapters.end()) {
continue;
}

iter.second->StopListen(true);
stop_listened_adapters.push_back(iter.second);
}

uint64_t begin_stop_time = trpc::time::GetMilliSeconds();
while (FrameStats::GetInstance()->GetServerStats().GetReqConcurrency() > 0) {
TRPC_LOG_DEBUG("current ReqConcurrency:" << FrameStats::GetInstance()->GetServerStats().GetReqConcurrency()
Expand Down