feat(sched): 接入 coco v2.2.0 新特性 — 热栈复用 + P 绑定 + 版本日志

This commit is contained in:
xfy911 2026-06-07 09:49:26 +08:00
parent 242a6c7822
commit fd66e71f1a

View File

@ -953,6 +953,9 @@ static void accept_loop(void *arg) {
log_info("单线程模式"); log_info("单线程模式");
} }
log_info("静态资源根目录: %s", ctx->config.root_dir); log_info("静态资源根目录: %s", ctx->config.root_dir);
log_info("coco 协程库版本: %s", coco_version());
log_info("coco 协程库版本: %s", coco_version());
log_info("coco 协程库版本: %s", coco_version());
if (ctx->config.max_connections > 0) { if (ctx->config.max_connections > 0) {
log_info("最大并发连接数: %u", ctx->config.max_connections); log_info("最大并发连接数: %u", ctx->config.max_connections);
@ -1056,12 +1059,17 @@ static void accept_loop(void *arg) {
atomic_load(&g_active_connections)); atomic_load(&g_active_connections));
if (ctx->config.threaded) { if (ctx->config.threaded) {
/* 多线程模式:使用 coco_go_with_opts 创建工作协程128KB 栈 */ /* 多线程模式:使用 coco_go_with_opts 创建工作协程
* stack_size = 0 使128KB
* p_id = client_fd % num_workers P
* CPU
*/
uint32_t worker_idx = client_fd % num_workers;
coco_go_opts_t opts = { coco_go_opts_t opts = {
.stack_size = 1024 * 1024, .stack_size = 0, /* 默认:使用共享热栈 */
.context = NULL, .context = NULL,
.priority = -1, .priority = -1,
.p_id = -1 .p_id = (int)worker_idx
}; };
coco_coro_t *coro = coco_go_with_opts(client_handler, conn, &opts); coco_coro_t *coro = coco_go_with_opts(client_handler, conn, &opts);
if (!coro) { if (!coro) {