-
Notifications
You must be signed in to change notification settings - Fork 173
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
Performance problems #54
Comments
You can take a look at the You are right that there is room for improvements in the current roundtrip time, for example locally I'm getting the following:
While a similar test but for the Ruby library, the numbers are a bit higher:
I have some pending updates to do around the request/response handling from the library to follow the new style of request/response done like in the Go library, so will take a look at revising performance again soon. |
@wallyqs nice to hear that you are working on performance improvements. In our company we are interesting in nats and python client. Maybe you can share any estimates you have with us? Thanks! |
Right now I'm planning a couple of releases, one minor release at the end of this month |
Nice! Can't wait for updates! |
@wallyqs does this diff may have a chance?
Before this diff:
After this diff:
Br, |
Also, it make sense to use |
About random, better to use
|
Thanks for the tips, the |
We can also use
Code for benchmarks: import timeit
if __name__ == '__main__':
print('random.SystemRandom() x 10000 times:\n%ss' % timeit.timeit(
stmt='"%x" % random.SystemRandom().getrandbits(256)',
setup='import random',
number=10000,
))
print('random.getrandbits() x 10000 times:\n%ss' % timeit.timeit(
stmt='"%x" % random.getrandbits(256)',
setup='import random',
number=10000,
))
print('os.urandom() x 10000 times:\n%ss' % timeit.timeit(
stmt='binascii.hexlify(os.urandom(32)).decode()',
setup='import os, binascii',
number=10000,
)) |
Ah, OK - with pre-created
Updated code: print('random.SystemRandom() x 100000 times:\n%ss' % timeit.timeit(
stmt='"%x" % sysrandom.getrandbits(256)',
setup='import random; sysrandom = random.SystemRandom()',
number=100000,
)) |
Thanks everyone for the feedback in this issue. In the next release v0.7.0 the inbox generation will be around twice as fast (although think implementation at https://github.com/nats-io/asyncio-nats/blob/master/nats/aio/nuid.py could be further optimized). print('NUID based inboxes x 100,000 times:\n%ss' % timeit.timeit(
stmt='inbox = INBOX_PREFIX[:]; inbox.extend(nuid.next())',
setup='from nats.aio.nuid import NUID; INBOX_PREFIX = bytearray(b"_INBOX."); nuid = NUID();',
number=100000,
))
print('Old style inboxes x 100,000 times:\n%ss' % timeit.timeit(
stmt='new_inbox()',
setup='from nats.aio.utils import new_inbox',
number=100000,
)) Results:
|
Hi!
I want to get know NATS + asyncio-nats-client RPS (request-response case). The test scenario is simple:
server.py
client.py
How to run:
I cant' get more than 1000 requests/responses in 1 second on my MacBook Pro (2.3 GHz Intel Core i5). Maybe I do something wrong or it's library limitations?
Thanks
The text was updated successfully, but these errors were encountered: