-
Notifications
You must be signed in to change notification settings - Fork 127
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
reader: don't use Decimal class to calculate backoff #155
Conversation
Ok, I'll fix the tests... give me a few minutes. |
f992f78
to
0da3ece
Compare
- Profiling indicates lots of time spent here, reduced 50000 messages from 23s to 18s (not raw NSQ, with custom layering on top)
0da3ece
to
0afef30
Compare
Ok, tests should pass this time. Because of the way backoff is used, I changed it around to use integers instead of floating point numbers, but the public API (get_interval()) still returns a floating point number. Slightly less speedup because of the conversion in get_interval, but still a huge win (20%). |
You could probably get it to work with plain floats, with just a tweak: in the success case, instead of using |
As I said, this is still a 20% speedup over the current release, so I'm not too concerned. Knock yourself out if you want to get that extra 0.5%. 👍 |
I'm still really confused as to how it spent 20% of its time here - do you have any more logs or results you can paste from your profiling? Backoff shouldn't be calculated so frequently? |
I don't have anything I can release publicly, but if you want I can put together a quick raw NSQ test that should duplicate the results. First thing of course, is the Decimal class is slow compared to raw integers or floats. This is python after all, and this seems to be called in a critical section (or at least as shown below -- multiple times per message). Looking at my profiling data, it shows that
If that's unexpected, perhaps the backoff code needs some restructuring and we'd see even more performance boost. :) |
Alright, I put together a test using just NSQ that demonstrates the performance difference. It's not totally realistic, but good enough. :) See this gist. Using this raw nsq reader/writer, and a local nsqd (no lookupd) on my macbook pro without power, I get:
Tornado 4.3 for both. |
Thanks, I'm very surprised at this, but then again I've unfortunately never actually paid attention to some of these details. What this tells me is that the problem isn't |
Well. I'm open to someone refactoring the internals so that it's even faster. 👍 However, I don't feel comfortable enough with the way NSQ works to do the refactoring correctly, and this provides a sizable speed boost for me now. I'll leave it to you. |
see #156, thanks for digging into this! |
It's not immediately clear why the Decimal class is being used here, when it seems like pure floats are just as good.
from 23s to 18s (not raw NSQ timing, with custom layering on top)
Haven't ran the tests yet, going to let Travis do that for me :)