Skip to content

Conversation

@EvonX
Copy link

@EvonX EvonX commented Feb 24, 2020

adding profiling support with pyliveupdate

Testing Plan:

> pip install pyliveupdate
> pylu-controller -l
> FP.profile(['zerver.decorator.**', 'zerver.lib.rate_limiter.**', 'zerver.lib.rest.**', 'zerver.middleware.**', 'zerver.tornado.event_queue.**', 'zerver.tornado.handlers.**', 'zerver.tornado.views.**'])
> exit
> pylu-processlogs

GIFs or Screenshots:
Profiling results for zulip#13917

Screen Shot 2020-02-24 at 12 11 19 PM

manage.py Outdated
# pyliveupdate integration
from pyliveupdate import *
UpdateStub().start()
from pyliveupdatescripts import *
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do this without using * imports? I guess I also don't see how this works -- does the behavior change just because of what was imported?

Copy link
Author

@EvonX EvonX Feb 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've modified it.

Sorry I haven't make it clear. These three lines of code will start a profiling-tub thread in Zulip, which will listen for a profiling-controller's commands to dynamically modify Zulip's code for profiling. So in order to make the behavior change, you may need to run a standalone profiling controller with pylu-controller -l. This will start a controller shell, in which you can type command like FP.profile(['zerver.lib.rate_limiter.**', 'zerver.lib.rest.**']) to start profiling a set of functions and FP.revert(1) to stop profiling without restarting Zulip. We have a demo here https://asciinema.org/a/304465. Hope it can help.

Please let me know if there is any questions.

timabbott pushed a commit that referenced this pull request Apr 10, 2020
If we had a rule like "max 3 requests in 2 seconds", there was an
inconsistency between is_ratelimited() and get_api_calls_left().
If you had:
request #1 at time 0
request #2 and #3 at some times < 2

Next request, if exactly at time 2, would not get ratelimited, but if
get_api_calls_left was called, it would return 0. This was due to
inconsistency on the boundary - the check in is_ratelimited was
exclusive, while get_api_calls_left uses zcount, which is inclusive.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants