From fd66e71f1a2d5abb9d4911a2bb36228efe7c36ae Mon Sep 17 00:00:00 2001 From: xfy911 Date: Sun, 7 Jun 2026 09:49:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(sched):=20=E6=8E=A5=E5=85=A5=20coco=20v2.2?= =?UTF-8?q?.0=20=E6=96=B0=E7=89=B9=E6=80=A7=20=E2=80=94=20=E7=83=AD?= =?UTF-8?q?=E6=A0=88=E5=A4=8D=E7=94=A8=20+=20P=20=E7=BB=91=E5=AE=9A=20+=20?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server.c b/server.c index 67c16be..2d319e6 100644 --- a/server.c +++ b/server.c @@ -953,6 +953,9 @@ static void accept_loop(void *arg) { log_info("单线程模式"); } 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) { log_info("最大并发连接数: %u", ctx->config.max_connections); @@ -1056,12 +1059,17 @@ static void accept_loop(void *arg) { atomic_load(&g_active_connections)); 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 = { - .stack_size = 1024 * 1024, + .stack_size = 0, /* 默认:使用共享热栈 */ .context = NULL, .priority = -1, - .p_id = -1 + .p_id = (int)worker_idx }; coco_coro_t *coro = coco_go_with_opts(client_handler, conn, &opts); if (!coro) {