-
Notifications
You must be signed in to change notification settings - Fork 493
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
Fix/buffersize Causing high memory usage #354
Conversation
update - fix-file-upload
fix client version
Keeping track of original master
@x00b Have a look I Started with : Now i made a lot of QR requests, arround 300 request then i viewed the memory Alloc = 23 MiB��TotalAlloc = 80 MiB�����Sys = 38 MiB���� # NumGC = 223� What do you think? |
The default GC behavior can cause this unnecessary spikes, i think it might be related to golang/go#14812 and maybe https://blog.twitch.tv/en/2019/04/10/go-memory-ballast-how-i-learnt-to-stop-worrying-and-love-the-heap-26c2462549a2/ too. I know that this PR really fix the high memory usage but the GC might be necessary to control directly in the application. But lets keep investigating it. |
Do you have any idea or method of controlling GC in the application? |
I went to const (
defaultReadBufferSize = 4096
defaultWriteBufferSize = 4096
) |
@gabstv Than you for your reply, I am not sure I followed you correctly. So what is the purpose of adding 4096 value? |
When we set buffer size to zero gorilla/websocket change it to 4096, that's what he said. But the default value is working fine. There's no need to increase it like it was and i think not even changing this PR to use other value instead of zero(so websocket doesn't set a higher default size) value) |
Today I decide to make a very ruff test.
Note that each request will cost 1 MB! is that reasonable? Have look to the top ` 5769 root 20 0 2072048 1.8g 7924 R 21.5 1.4 12:41.30 wa-api But I believe we have to utilize GC somehow in the base lib. |
Are you disconnecting/deleting the Wac after Qrcode timeout? About the ErrConnectionFailed... Try implementing the HandlerError logic, if you search the issues here you see that this Err is handled pretty well with handler error About the base lib implementing a GC call by default doesn't matter until we find exactly where those bugs are. I am having whatsapp conn issues too. But don't think might be related to this PR but with latest whatsapp web updates(which by the way is going to add new features). |
@x00b Great I found how to disconnect if the Wac.Info is nill which means it is not logged in, then i do disconnect for the Wac. I test the benchmark "More than 10k Qr scan" How I did that: along with this simple func
and I note that when I tried to restore the sessions the wac kept connected "it is not logged in but keeps connected", every 15 seconds I do a newConnection to check if the mobile is online or not! THANKS! |
@x00b
|
It might be something in your code i think. Probably an infinite for {} loop that is running in a goroutine or something like that that is causing a high memory usage and the garbage collector cannot work properly(clean the not-used memory). If you have an infinite for loop, it might be the cause... Never do infinite for{} loop in Go |
Websocket buffer size was causing high memory usage during ws conn, issues tracking:
Suggest in #282 , discussion in #328 and benchmark/testing in #350
ps: re-opening pr