feat(sched): 接入 coco v2.2.0 新特性 — 热栈复用 + P 绑定 + 版本日志
This commit is contained in:
parent
242a6c7822
commit
fd66e71f1a
14
server.c
14
server.c
@ -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) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user