Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在wsl中 timer skyent.now异常 #2013

Closed
fanyh opened this issue Dec 25, 2024 · 3 comments
Closed

在wsl中 timer skyent.now异常 #2013

fanyh opened this issue Dec 25, 2024 · 3 comments

Comments

@fanyh
Copy link
Contributor

fanyh commented Dec 25, 2024

环境

wsl ubuntu 24.04

问题描述

在 wsl 中 skynet.now 的时间会相对系统时间越来越慢; 在linux(centos) 系统下不存在这个问题

ps: 对比测试发现wsl ubuntu 24.04 下: CLOCK_REALTIME 与 CLOCK_MONOTONIC 表现不太符合预期

重新步骤

code

local skynet = require "skynet"
local start = os.time()
while true do
    skynet.sleep(100)
    skynet.error(skynet.now .. "vs" .. os.time() - start)
end

log

[:01000009] 584vs5
[:01000009] 684vs6
[:01000009] 784vs7
[:01000009] 884vs8
[:01000009] 984vs9
[:01000009] 1084vs10
[:01000009] 1184vs14

c debug code

void skynet_timer_init(void) {
    ...
    struct timespec ti;
    clock_gettime(CLOCK_MONOTONIC, &ti);
    TI->t1 = (uint32_t)ti.tv_sec;
}

uint64_t skynet_now(void) {
    struct timespec ti;
    clock_gettime(CLOCK_MONOTONIC, &ti);

    struct timespec ti1;
    clock_gettime(CLOCK_REALTIME, &ti1);
    skynet_error(NULL, "pass:%d real:%d", ((uint32_t)ti.tv_sec - TI-> t1), ((uint32_t)ti1.tv_sec - TI->starttime));
    return TI->current;
}

c log

[:01000009] 1084vs10
[:00000000] pass:10 real:10
...
[:00000000] pass:10 real:11
[:00000000] pass:10 real:11
[:00000000] pass:10 real:11
[:00000000] pass:10 real:11
[:00000000] pass:10 real:11
[:00000000] pass:10 real:11
[:00000000] pass:10 real:11
[:00000000] pass:10 real:11
[:00000000] pass:10 real:11
[:00000000] pass:11 real:11
...
[:00000000] pass:11 real:13
...
[:00000000] pass:11 real:14
...
[:01000009] 1184vs14
@cloudwu
Copy link
Owner

cloudwu commented Dec 25, 2024

建议把这个问题报告给 wsl 项目。

@cloudwu
Copy link
Owner

cloudwu commented Dec 25, 2024

我不确定是否和这个问题相关:microsoft/WSL#10006

@fanyh
Copy link
Contributor Author

fanyh commented Dec 26, 2024

根据wsl 改善方案(重启wsl对时)操作了下; 然并卵。
但是根据他们的问题描述(休眠会导致 CLOCK_MONOTONIC异常),采用重启(windows)大法,暂时隐藏了这个问题

btw: 重启后CLOCK_MONOTONIC又快了 ...

wsl本来也并非我们的标准环境,这个问题就先这样。

感谢云大侠

@fanyh fanyh closed this as completed Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants