Comments (7)
EDIT: 这是错误的解决方案,正确的解决方案在下面👇
呀……
这个BUG是因为WebScoket库的select函数的超时时间设置的太小了。
临时解决方法:
把这一行的
tv.tv_usec = 20 * 1000;
改成
tv.tv_usec = 200 * 1000;
在wsl上测试了一下,有明显改善。
from mirai-cpp.
呀……
这个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前后的变化,发现没有明显差异:
from mirai-cpp.
呀……
这个BUG是因为WebScoket库的select函数的超时时间设置的太小了。
临时解决方法:
把这一行的tv.tv_usec = 20 * 1000;改成
tv.tv_usec = 200 * 1000;在wsl上测试了一下,有明显改善。
十分感谢您的回复,但我这边似乎似乎并没能生效。我后面又尝试把tv.tv_sec改成20和200,发现这个数字只是延迟了CPU打满的时间,但20s和200s一过,CPU利用率还是飙升到了90+%。
需要完全清理cmake缓存再重新编译,因为这个文件的改动可能不会被cmake发现。
from mirai-cpp.
sorry, 还真的没有任何改变。
我再仔细研究下……
from mirai-cpp.
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.
😵消息回复延迟十分严重可能是因为另一个BUG #70
from mirai-cpp.
感谢!目前我这边测试,CPU占用高和消息延时的问题都解决了~
from mirai-cpp.
Related Issues (20)
- 发送语音消息时VoiceMessage::length_未初始化导致mirai-api-http可能返回400
- websocket 连接正常,但是无法触发事件处理函数 HOT 11
- 希望能给GroupMessage添加一个GroupId HOT 2
- 新增一系列无异常的 Try* 模式的接口
- 有关LostConnectionCallback的一些问题 HOT 3
- 目前的项目在使用mirai-cpp,可否在readme做下推广呢? HOT 1
- 关于MessageChain == 比较的问题 [Bug?] HOT 1
- 更新cpp-httplib以保证线程安全 HOT 1
- 拼写错误,解析json失败 HOT 1
- 将 const std::string& 替换为 std::string_view 以简化代码
- 在使用httplib::Client时出现错误 HOT 6
- 有时QQ客户端收不到消息 HOT 2
- 有关VoiceMessage的问题 HOT 2
- Command.Member->Group.GID 可能为空 HOT 3
- MFC开发 HOT 1
- 分享一个非常蒻的Bot HOT 1
- 关于VoiceMessage.Url() HOT 3
- 关于MessageChain().Add<VoiceMessage>(); HOT 9
- 无法上传文件 HOT 3
- mirai-cpp-template的main函数中的端口设置似乎不起作用
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mirai-cpp.