-
Notifications
You must be signed in to change notification settings - Fork 679
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
Strange workers behaviour #1010
Comments
That exceptions counter is pretty scaring, expecially because you do not have the exception in the logs. I would attach a strace to the busy processes to understand what is going on and disable ignore-write-errors just to be sure it is an unreported network issue |
thanks for the quick reply. I was thinking on adding |
Yes reload-on-exception would help, but honestly i think it would be better to understand what is going on :) |
definitely 👍 thanks for the support. I will come back with some straces |
Gonna clean some of the straces: |
stracing some of the unactive workers some have what seems to be normal output:
however others just sit at:
|
so when the issue happens, I go killing workers which are idle and outputing:
after I kill each one, they become active and RPS starts going up. |
when the number of workers is really low (i.e:3) then when the app is just started all of the workers strace outputs what the previous comment mentioned. |
A healthy idle worker output looks like:
|
it turned out that pymongo's |
the strace you reported shows a GIL deadlock and the mongoclient is heavily thread based. Maybe you initialize it before fork() ? |
I initialized |
I am not sure it is supported by mongoclient, i fear the socket will be clobbered. I think initializing a new pool for each worker is the best approach |
gonna try it, saw similar posts regarding: uwsgi + gevent + pymongo |
Quick summary & solution for anybody having a similar issue: Stack: python, flask, uwsgi, pymongo Symptoms
Cause of the problem
SolutionAfter trying various things/settings, the only way to avoid it, is to create a mongoClient per worker/request. Probably a heads up for any other lib using threads. |
Just as a note, if you do not want to change your app code, you can use the --lazy-apps option that will load the app one time per worker |
I am having a similar issue that appears to be caused by pymongo, however, I cannot figure out why. I am seeing workers slowly start hanging, no exceptions, no responses, they just seem to stop and then once all the workers reach this state, my app goes down since there are no more workers to respond to requests. I am using the following:
Using strace on a hanging worker shows only:
This is the exact same for every hanging worker and using gdb, I discovered the following:
Thus, I am fairly certain the issue is due to sharing a single pymongo client across all the workers. I am using the from mongoengine import connect, connection
print 'Existing Connections:', connection._connections
if MONGO_REPLICA:
connect(MONGO_DB, host=MONGO_IP, replicaSet=MONGO_REPLICA)
else:
connect(MONGO_DB, port=MONGO_PORT, host=MONGO_IP)
print 'New Connections:', connection._connections
print 'Module ID:', id(connection)
print 'Connection Dict ID:', id(connection._connections)
print 'New Connection ID:', id(connection._connections['default']) This prints the following when starting uwsgi (I have truncated it but it is the same for every worker):
My guess is that it has something to do with the pymongo client being stored in a module-level global dictionary in mongoengine but I am not understanding why every uwsgi process is using the same instance of the module, dictionary, and client (as noted by the same memory address). I am running uwsgi with the following options:
|
Hi, try adding --enable-threads from the strace (and if i remember correctly) the mongoclient spawns a thread in background |
Hmm adding I haven't been able to reliably reproduce the actual hanging of the processes as it seems to occur randomly so I'll try letting it run for a while with |
Hi @unbit, I am still seeing my application hanging on connections with the mongoclient. Do you have any other insight into why I am seeing every uwsgi process use the same memory address? When running the django development server I see the following:
I'll admit I'm not entirely familiar with how multiple processes/threads are handled and how different what the development server is doing compared to uwsgi but I do know there are 2 processes for the development server and each has a different instance of the module/dict/mongoclient which is what I would expect from uwsgi as well... |
stumbled into this after trying to figure out a phantom consistent ~3% CPU usage from my supposedly idle docker container (which has python, uwsgi, and the pymongo pip module). strace output for just a couple of seconds (against one of the workers) show
App works great, except for the phantom CPU usage leak. Adding |
Ive been using uwsgi for a while. Lately Im seeing the following problem (to diagnose Im using uwsgitop):
Exception
column show thousands of exceptions. I cant see anything unusual onuwsgi.log
. Is there any hint where to see those exceptions?Thank you in advance.
in the screeshot:
527
,598
exceptions..Here is my
.ini
fileThe text was updated successfully, but these errors were encountered: