Comments (8)
Checking with async-std or gio as another runtime might also be interesting here. The performance is going to depend on the runtime too.
from async-tungstenite.
Async code will generally be slower in the small scale than sync code. There's a lot more book-keeping that has to be done compared to simply blocking a thread.
Async code starts to become better performance-wise once you have a lot of operations in parallel and running a whole OS thread for each of them would consume too many resources.
Async code also has the advantage of easier to read and maintain code since the async/await syntax was introduced.
Apart from that your code example does not seem to do much at all, I'd expect any performance differences here to be irrelevantly small unless something's going really wrong. What numbers do you measure and how?
The comparison with Python is not too useful in this regard because Python is effectively single-threaded by the use of the global interpreter lock. By running async code in Python you can do lots of operations in parallel while actually blocking would potentially block everything.
That said, I'm sure there might be some parts in this crate that can be optimized further. I'd recommend doing some profiling to find the bottlenecks if this is a concern for you.
from async-tungstenite.
~700 is still a pretty small number - try spawning 10k connections simultaneously (if you even manage to create 10k threads on your computer) :-)
from async-tungstenite.
In addition to what @Patryk27 said, CPU usage is not the only thing you want to measure really. Those 717 threads are going to use up a lot of OS resources compared to 5 threads :)
from async-tungstenite.
Ive tried recently scaling this up to 714 connections with 714 threads vs 714 tokio::spawn() tasks to try to make this more 'large' scale.
The numbers I measured are of my mac using Activity Monitor.
Threaded
Cpu Usage: 4-6%
Threads: 717
Async
Cpu Usage: 5-7%
Threads: 5
It still seems to have a similar results. I guess my testing methodology may not be sound since I assumed that in the threaded version these connections are mostly just waiting for a websocket message to be received, so I was thinking that the async implementation would run faster.
What would be a much better test for proving this ?
from async-tungstenite.
Thanks for the help. After scaling I started to see differences at 2856 websocket connections. If i try to double that, the threads fail with the following error
Number of markets 5712
thread 'main' panicked at 'failed to spawn thread: Os { code: 35, kind: WouldBlock, message: "Resource temporarily unavailable" }', src/libcore/result.rs:1165:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
at 2856 ws connections it seems like the async implementation seems to be running at half the cpu usage and only consuming 4 threads :-)
Threaded
Cpu Usage: 20-35
Threads: 2858
Async
Cpu Usage: 10-20%
Threads: 4
from async-tungstenite.
Will have a shot at this, and come back with some performance results
from async-tungstenite.
@araa47 what have you found out? You might want to have a look at the memory usage, there will be a real difference there. You can reduce the stack size of threads to make them lighter though. You can also change the max number of threads on your system, eg. for linux.
from async-tungstenite.
Related Issues (20)
- Inspecting the steam buffer HOT 3
- "thread 'async-std/runtime' panicked" when running "echo-server" example HOT 1
- Support fragmented messages HOT 3
- How to close connection gracefully after WebSocketStream.split()? HOT 2
- [Question]: How to optimise the memory usage for websocket client HOT 5
- could not find `async_std` in `async_tungstenite` HOT 6
- Support for the `smol` runtime HOT 1
- Add vendored feature for dependency crates so that statically linked OpenSSL can be used HOT 1
- ResetWithoutClosingHandshake when server sends more frequent messages. HOT 1
- Can't find `tungstenite::client::IntoClientRequest` HOT 5
- how to close websocket after it has been moved into select? HOT 12
- Task wakes too often in release mode when used with `async_std` HOT 11
- max connect just 50 onely HOT 2
- How to add TLS support to a websocket server for wss to work? HOT 2
- Disable certificate validation HOT 2
- How to disable logging for compact? HOT 5
- Avoid webpki-roots as a default dependency when tokio-rustls is used HOT 5
- Is it possible to flush all buffered messages before closing the stream? HOT 5
- Cloning `WebSocketStream`s HOT 1
- Initial report: stack overflow on windows with 0.15 HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from async-tungstenite.