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

Question - async/await stream to many users using just 1 thread #71

Open
vegarringdal opened this issue Jan 8, 2023 · 2 comments
Open

Comments

@vegarringdal
Copy link

Im very new to rust, so my question/sample code might be weird.

Im trying to build a small rest api with actix, where I stream large result sets back to client
But atm when I loop resultset with next it will pretty much block the thread for any new request ( I will only have 1 thread)

Since I use .fetch_array_size(100).prefetch_rows(100) it would be useful if each request only worked with 100 rows then let other requests do little work etc. In this way I could stream back result to many clients, just a little slower..

Tried to wrap rows.next() in async, but its still blocking. (at least I tried...:joy:)
https://github.com/vegarringdal/rust/blob/try_async/apitest/src/main.rs#L26-L30

Is what Im trying to do possible ?

@vegarringdal
Copy link
Author

think I might have found a workaround, by adding a delay
updated the code

@sakshatshinde
Copy link

sakshatshinde commented Oct 4, 2023

@vegarringdal Look into Tokio's spawn_blocking

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

No branches or pull requests

2 participants