Skip to content
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 consume too slow #100

Open
rxy1212 opened this issue May 31, 2023 · 13 comments · May be fixed by #101
Open

reader consume too slow #100

rxy1212 opened this issue May 31, 2023 · 13 comments · May be fixed by #101
Labels
bug Something isn't working

Comments

@rxy1212
Copy link

rxy1212 commented May 31, 2023

I just do nothing but consume the message, and I find I can only consume about 30 messages per second. Do I miss some configs in the reader?

async def main():
    reader = await ansq.create_reader(
        topic=NSQ_TOPIC,
        channel=NSQ_CHANNEL,
        lookupd_http_addresses=LOOKUPD_HTTP_ADDRESSES_TEST
    )

    async for message in reader.messages():
        await message.fin()

    await reader.close()
@atugushev
Copy link
Collaborator

atugushev commented May 31, 2023

I suppose this happens due to max_in_flinght=1 per connection:

https://github.com/list-family/ansq/blob/71a8a73a385613532607707a78727ff1cab09582/ansq/tcp/reader.py#L128-L135C7

Feel free to send a PR with set_max_in_flight() enhancement. Relevant code is here:

https://github.com/list-family/ansq/blob/71a8a73a385613532607707a78727ff1cab09582/ansq/tcp/reader.py#L137C35-L144

As a naive implementation we could call conn.set_max_in_flight(N) for each connections on reader.set_max_in_flight(N). What do you think?

@rxy1212
Copy link
Author

rxy1212 commented May 31, 2023

Actually, I'm not very familiar with asynchronous programming. I feel that ansq is already the easiest to use asynchronous nsq package in python so far. But if the consumption efficiency of ansq is so weak, basically, I can't use it in production environment.
By the way, I noticed that you updated ansq to v0.2.1 yesterday, what's new in the current version?

@atugushev
Copy link
Collaborator

atugushev commented May 31, 2023

Temporary workaround is to increase manually RDY via:

for conn in reader.connnections:
    await conn.rdy(2500)

By the way, I noticed that you updated ansq to v0.2.1 yesterday, what's new in the current version?

See the releases page for details.

Actually, I'm not very familiar with asynchronous programming. I feel that ansq is already the easiest to use asynchronous nsq package in python so far. But if the consumption efficiency of ansq is so weak, basically, I can't use it in production environment.

Thanks anyway for the issue. Much appreciated. I'll try to come up with a naive solution later on my spare time.

@atugushev atugushev added the bug Something isn't working label May 31, 2023
@rxy1212
Copy link
Author

rxy1212 commented Jun 1, 2023

Thanks for your work. Good luck!

@magniff
Copy link
Contributor

magniff commented Jun 1, 2023

Here's what i've found in some of my tests:

log2 RDY Seconds
0 667
1 274
2 167
3 84
4 43
5 23
6 21
7 22

The higher RDY does indeed imply higher throughput, though, mind it got saturated at RDY ~ 64-128. Of course the actual point of saturation will depend on the scenario.

@atugushev
Copy link
Collaborator

@magniff nice demonstration! Yeah, RDY is a key concept that tunes the performance and throughput of a client, see docs.

For the data protocol, we made a key design decision that maximizes performance and throughput by pushing data to the client instead of waiting for it to pull. This concept, which we call RDY state, is essentially a form of client-side flow control.

@atugushev atugushev linked a pull request Jun 3, 2023 that will close this issue
@atugushev
Copy link
Collaborator

atugushev commented Jun 3, 2023

@rxy1212 could you check #101? Does it work for you?

pip install 'git+https://github.com/atugushev/ansq@set-max-in-flight#egg=ansq'

@rxy1212
Copy link
Author

rxy1212 commented Jun 5, 2023

@atugushev I don't know what's wrong, but I can't install ansq with "pip install 'git+https://github.com/atugushev/ansq@set-max-in-flight#egg=ansq'"

@atugushev
Copy link
Collaborator

@rxy1212 what's the error?

@rxy1212
Copy link
Author

rxy1212 commented Jun 12, 2023

pip install 'git+https://github.com/atugushev/ansq@set-max-in-flight#egg=ansq'
Collecting ansq
  Cloning https://github.com/atugushev/ansq (to revision set-max-in-flight) to /tmp/pip-install-2nnxqqju/ansq_55a7f5e47b9549909853031f14db2476
  Running command git clone --filter=blob:none --quiet https://github.com/atugushev/ansq /tmp/pip-install-2nnxqqju/ansq_55a7f5e47b9549909853031f14db2476
  fatal: unable to access 'https://github.com/atugushev/ansq/': Encountered end of file
  error: subprocess-exited-with-error

  × git clone --filter=blob:none --quiet https://github.com/atugushev/ansq /tmp/pip-install-2nnxqqju/ansq_55a7f5e47b9549909853031f14db2476 did not run successfully.
  │ exit code: 128
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× git clone --filter=blob:none --quiet https://github.com/atugushev/ansq /tmp/pip-install-2nnxqqju/ansq_55a7f5e47b9549909853031f14db2476 did not run successfully.
│ exit code: 128
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

But general packages installed with pip work well

@atugushev
Copy link
Collaborator

@rxy1212 does git clone https://github.com/atugushev/ansq work for you?

@rxy1212
Copy link
Author

rxy1212 commented Jun 20, 2023

@atugushev I got this output

Cloning into 'ansq'...
fatal: unable to access 'https://github.com/atugushev/ansq/': Empty reply from server

@atugushev
Copy link
Collaborator

@rxy1212 seems like you need a VPN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants