You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FROM gcr.io/google-appengine/python
# Create a virtualenv for dependencies. This isolates these packages from
# system-level packages.
# Use -p python3 or -p python3.7 to select python version. Default is version 2.
RUN virtualenv -p python3 /env
# Setting these environment variables are the same as running
# source /env/bin/activate.
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH
# Copy the application's requirements.txt and run pip to install all
# dependencies into the virtualenv.
ADD requirements.txt /app/requirements.txt
RUN pip install --upgrade pip
RUN pip install -r /app/requirements.txt
# Add the application source code.
ADD . /app
# Run a WSGI server to serve the application. gunicorn must be declared as
# a dependency in requirements.txt.
CMD gunicorn -c gunicorn.conf.py -b :$PORT main:app
Yes, I can confirm that - even with this error printed very often on stderr
there is still some collected profile visible on Google StackDriver Profiler UI
For each profile type, select a 10 minutes in Timespan, and check the profile count shown in the root node. The root node has the profile count displayed as "... averaged over n profiles". Please report what the n is.
If the service is not running currently, please set the end time to a time when the service was running by clicking "Now" and setting the end time.
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/googlecloudprofiler/pythonprofiler.py", line 180, in _handler
if not self._started or self._in_handler:
BlockingIOError: [Errno 11] Resource temporarily unavailable"
I think the problem is that the app enabled signal wakeup fd somewhere. When the profiler profiles, it triggers a SIGALRM/SIGPROF signal every 10ms. Since too many signals arrive too quickly, it may cause the fd’s buffer to be full, see https://docs.python.org/3/library/signal.html#signal.set_wakeup_fd:
There are two common ways to use this function. In both approaches, you use the fd to wake up when a signal arrives, but then they differ in how they determine which signal or signals have arrived.
In the first approach, we read the data out of the fd’s buffer, and the byte values give you the signal numbers. This is simple, but in rare cases it can run into a problem: generally the fd will have a limited amount of buffer space, and if too many signals arrive too quickly, then the buffer may become full, and some signals may be lost. If you use this approach, then you should set warn_on_full_buffer=True, which will at least cause a warning to be printed to stderr when signals are lost.
In the second approach, we use the wakeup fd only for wakeups, and ignore the actual byte values. In this case, all we care about is whether the fd’s buffer is empty or non-empty; a full buffer doesn’t indicate a problem at all. If you use this approach, then you should set warn_on_full_buffer=False, so that your users are not confused by spurious warning messages.
This will not affect the profiler. But if the app definitely needs to access the signal numbers as described in the first approach above, you probably should not use the profiler.
@jqll I apologies, I missed this message until now. I stopped using cloud profiler due to this and a few other reasons. Has anything changed on this issue since September? If it hasn't been diagnosed or resolved I'm happy to add it back in and see if I'm still seeing the problem!
@kalyanac I'm running a pretty basic Django app on GAE Standard, and I just searched through all of my code and all the dependencies and nothing is calling set_wakeup_fd.
Heh, I was just arriving at that conclusion - it's gunicornitself that's doing it, which is the default server that Google App Engine Standard uses! None of the rest of the code I'm using in my project (directly or indirectly) does it.
So it looks like right now there's no way to use google-cloud-profiler reliably on App Engine Standard. Unless we switch to a different non-default server?
@kalyanac Because of ☝️ meaning that you can't use one Google product (this package) on another (Google App Engine Standard with Python 3) without this happening, it kinda feels like a bug that should still be open. Maybe GAE offers a patched version of gunicorn? Or this package has a workaround for this case?
Reacted by Ernesto Chavez Sanchez and Damien Raude-Morvan
@mgrdcm This is not specific to gunicorn, any package or user code could set the same.
I appreciate your point regarding App Engine. We will post an update if we figure out a way to address this.
Not a fix, but I switched to using the New Relic agent on GAE Standard Python 3 and it works wonderfully. Their new free tier is pretty generous, and so far I'm able to stay within it for my use case.
Activity
kalyanac commentedon Jun 22, 2020
@drazzib Thank you for reporting this. This is not a known issue. We will try to reproduce this issue.
kalyanac commentedon Jun 22, 2020
Can you share your
app.yaml,requirements.txt,Dockerfile? I tried with Quickstart apps on Profiling Python applications | Cloud Profiler | Google Cloud and did not see that messages.drazzib commentedon Jun 23, 2020
app.yaml:requirements.txt:Dockerfile:drazzib commentedon Jun 24, 2020
Hi @kalyanac & @jqll !
I've just seen that a new 1.1.2 release has been pushed to PyPI repository which contains 17d58aa commit.
Is this relevant for issue discussed above ?
kalyanac commentedon Jun 24, 2020
Hi @drazzib, No the new release is not related to this issue. We are still having trouble reproducing this error.
kalyanac commentedon Jun 24, 2020
Are you seeing any profiles collected despite these messages?
drazzib commentedon Jun 24, 2020
Yes, I can confirm that - even with this error printed very often on stderr
there is still some collected profile visible on Google StackDriver Profiler UI
kalyanac commentedon Jun 25, 2020
Thank you for the response. Few more questions:
kalyanac commentedon Jul 1, 2020
Gentle ping.
drazzib commentedon Jul 5, 2020
Hi @kalyanac , sorry for the delay.
20.91 ms (100%), averaged over 11 profiles10 s (100%), averaged over 9 profileskalyanac commentedon Jul 6, 2020
Hi @drazzib, it seems like the agent is uploading profiles at a rate we expect it to. So we don't anticipate any loss of profile data at the moment.
We'll try to reproduce this issue and root cause the source of the message.
radyz commentedon Jul 6, 2020
I just started having this same issue today with my CloudRun service
Libs:
google-cloud-profiler = 1.1.2
gunicorn = 20.0.4
Django = 3
kalyanac commentedon Jul 6, 2020
@radyz thanks for reporting it.
jqll commentedon Jul 6, 2020
Thanks for reporting the issue.
I think the problem is that the app enabled signal wakeup fd somewhere. When the profiler profiles, it triggers a SIGALRM/SIGPROF signal every 10ms. Since too many signals arrive too quickly, it may cause the fd’s buffer to be full, see https://docs.python.org/3/library/signal.html#signal.set_wakeup_fd:
This will not affect the profiler. But if the app definitely needs to access the signal numbers as described in the first approach above, you probably should not use the profiler.
4 remaining items
mgrdcm commentedon Dec 13, 2020
@jqll I apologies, I missed this message until now. I stopped using cloud profiler due to this and a few other reasons. Has anything changed on this issue since September? If it hasn't been diagnosed or resolved I'm happy to add it back in and see if I'm still seeing the problem!
kalyanac commentedon Jan 7, 2021
We have documented this in our known issues section of the documentation.
Closing because there is no further action expected on this issue.
mgrdcm commentedon Jan 8, 2021
@kalyanac I'm running a pretty basic Django app on GAE Standard, and I just searched through all of my code and all the dependencies and nothing is calling
set_wakeup_fd.kalyanac commentedon Jan 8, 2021
It is probably set by one of the Django or any other imports Django uses.
kalyanac commentedon Jan 8, 2021
Here is an example from gunicorn
mgrdcm commentedon Jan 8, 2021
Heh, I was just arriving at that conclusion - it's
gunicornitself that's doing it, which is the default server that Google App Engine Standard uses! None of the rest of the code I'm using in my project (directly or indirectly) does it.So it looks like right now there's no way to use
google-cloud-profilerreliably on App Engine Standard. Unless we switch to a different non-default server?mgrdcm commentedon Jan 9, 2021
@kalyanac Because of ☝️ meaning that you can't use one Google product (this package) on another (Google App Engine Standard with Python 3) without this happening, it kinda feels like a bug that should still be open. Maybe GAE offers a patched version of
gunicorn? Or this package has a workaround for this case?kalyanac commentedon Jan 20, 2021
@mgrdcm This is not specific to
gunicorn, any package or user code could set the same.I appreciate your point regarding App Engine. We will post an update if we figure out a way to address this.
zackarydev commentedon Mar 9, 2021
Has anyone discovered a temporary fix for this other than disabling the profiler?
wyk9787 commentedon Mar 9, 2021
You can find the current solution here: https://cloud.google.com/profiler/docs/troubleshooting#python-blocking. I will also update the README to mention this.
mgrdcm commentedon Mar 10, 2021
Not a fix, but I switched to using the New Relic agent on GAE Standard Python 3 and it works wonderfully. Their new free tier is pretty generous, and so far I'm able to stay within it for my use case.