Giter Club home page Giter Club logo

Comments (7)

cyanray avatar cyanray commented on June 12, 2024

EDIT: 这是错误的解决方案,正确的解决方案在下面👇

呀……
这个BUG是因为WebScoket库的select函数的超时时间设置的太小了。

临时解决方法:
这一行

tv.tv_usec = 20 * 1000;

改成

tv.tv_usec = 200 * 1000;

在wsl上测试了一下,有明显改善。

from mirai-cpp.

Slontia avatar Slontia commented on June 12, 2024

呀……
这个BUG是因为WebScoket库的select函数的超时时间设置的太小了。

临时解决方法:
这一行

tv.tv_usec = 20 * 1000;

改成

tv.tv_usec = 200 * 1000;

在wsl上测试了一下,有明显改善。

十分感谢您的回复,但我这边似乎似乎并没能生效。我后面又尝试把tv.tv_sec改成20和200,发现这个数字只是延迟了CPU打满的时间,但20s和200s一过,CPU利用率还是飙升到了90+%。

通过perf看了CPU打满时,修改tv.tv_sec前后的变化,发现没有明显差异:
image

from mirai-cpp.

cyanray avatar cyanray commented on June 12, 2024

呀……
这个BUG是因为WebScoket库的select函数的超时时间设置的太小了。
临时解决方法:
这一行

tv.tv_usec = 20 * 1000;

改成

tv.tv_usec = 200 * 1000;

在wsl上测试了一下,有明显改善。

十分感谢您的回复,但我这边似乎似乎并没能生效。我后面又尝试把tv.tv_sec改成20和200,发现这个数字只是延迟了CPU打满的时间,但20s和200s一过,CPU利用率还是飙升到了90+%。

通过perf看了CPU打满时,修改tv.tv_sec前后的变化,发现没有明显差异:
image

需要完全清理cmake缓存再重新编译,因为这个文件的改动可能不会被cmake发现。

from mirai-cpp.

cyanray avatar cyanray commented on June 12, 2024

sorry, 还真的没有任何改变。
我再仔细研究下……

from mirai-cpp.

cyanray avatar cyanray commented on June 12, 2024

select 函数的超时时间用 struct timeval 来表示。
而且 select 函数有可能会修改这个 timeval 的值。(这个应该是看操作系统的,Windows 好像没这个情况)
所以正确的做法是在调用 select 函数之前,初始化 struct timeval

修改后的 WebSocketClient.cpp 应该差不多是这样:

......
struct timeval tv;
-tv.tv_sec = 0;
-tv.tv_usec = 200 * 1000;
while (status == Status::Open)
{
+	tv.tv_sec = 0;
+	tv.tv_usec = 200 * 1000;
	FD_SET(sock, &fds_read);
	int ret = select((int)(sock + 1), &fds_read, NULL, NULL, &tv);
	if (ret < 0)
......

希望这个就是最终答案🤔

from mirai-cpp.

cyanray avatar cyanray commented on June 12, 2024

😵消息回复延迟十分严重可能是因为另一个BUG #70

from mirai-cpp.

Slontia avatar Slontia commented on June 12, 2024

感谢!目前我这边测试,CPU占用高和消息延时的问题都解决了~

from mirai-cpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.