-
Rust_concurrency❤️최적화 - Rayon을 써야 할 때와 tokio를 써야 할 상황 알아 보기 &❤️futures concurrency코딩Coding/Rust❤️Optimization❤️ 2022. 5. 17. 18:52728x90
Rayon 기초
rayon
https://github.com/rayon-rs/rayon
GitHub - rayon-rs/rayon: Rayon: A data parallelism library for Rust
Rayon: A data parallelism library for Rust. Contribute to rayon-rs/rayon development by creating an account on GitHub.
github.com
예문
https://youtu.be/_AQDYmZRmRc
에러 관리
https://youtu.be/FJl0mQ_gNE4
tokio를 쓰면 안 되는 3가지 case
이럴 경우는 tokio보다는 rayon을 써야 더 빠르다
When not to use Tokio
Although Tokio is useful for many projects that need to do a lot of things simultaneously, there are also some use-cases where Tokio is not a good fit.- Speeding up CPU-bound computations by running them in parallel on several threads. Tokio is designed for IO-bound applications where each individual task spends most of its time waiting for IO. If the only thing your application does is run computations in parallel, you should be using rayon. That said, it is still possible to "mix & match" if you need to do both
- Reading a lot of files. Although it seems like Tokio would be useful for projects that simply need to read a lot of files, Tokio provides no advantage here compared to an ordinary threadpool. This is because operating systems generally do not provide asynchronous file APIs.
- Sending a single web request. The place where Tokio gives you an advantage is when you need to do many things at the same time. If you need to use a library intended for asynchronous Rust such as reqwest, but you don't need to do a lot of things at once, you should prefer the blocking version of that library, as it will make your project simpler. Using Tokio will still work, of course, but provides no real advantage over the blocking API. If the library doesn't provide a blocking API, see the chapter on bridging with sync code.
출처 https://tokio.rs/tokio/tutorialTutorial | Tokio - An asynchronous Rust runtime
Tutorial Tokio is an asynchronous runtime for the Rust programming language. It provides the building blocks needed for writing networking applications. It gives the flexibility to target a wide range of systems, from large servers with dozens of cores to
tokio.rs
tokio의 장점
tokio
https://tokio.rs/Tokio - An asynchronous Rust runtime
Tokio's APIs are memory-safe, thread-safe, and misuse-resistant. This helps prevent common bugs, such as unbounded queues, buffer overflows, and task starvation.
tokio.rs
tokio tutorial
https://tokio.rs/tokio/tutorialTutorial | Tokio - An asynchronous Rust runtime
Tutorial Tokio is an asynchronous runtime for the Rust programming language. It provides the building blocks needed for writing networking applications. It gives the flexibility to target a wide range of systems, from large servers with dozens of cores to
tokio.rs
빅 O Big-O차트 그림으로 이해하기 14분 ~
Rust Code로 빅 O(Big-O Complexity Chart) 이해하기 14분 부터 보면 됨
https://youtu.be/6IhopmZhWQI
출처: https://economiceco.tistory.com/13738 [경제PLUS]
빅 O Big-O 차트 보는 방법RustConf 2021 - Writing the Fastest GBDT Library in Rust by Isabella Tromba
내장되어 있는 stdfutures -> tokio 에서도 나온다 다 연결되네 ㅋ
Future Trait가 있다. ㅎㅎㅎ
https://rust-lang.github.io/async-book/02_execution/02_future.html
The Future Trait - Asynchronous Programming in Rust
The Future trait is at the center of asynchronous programming in Rust. A Future is an asynchronous computation that can produce a value (although that value may be empty, e.g. ()). A simplified version of the future trait might look something like this: #!
rust-lang.github.io
Futures concurrency
Rust ❤️Asynchronous Programminghttps://rust-lang.github.io/async-book/01_getting_started/01_chapter.html
Getting Started - Asynchronous Programming in Rust
Welcome to Asynchronous Programming in Rust! If you're looking to start writing asynchronous Rust code, you've come to the right place. Whether you're building a web server, a database, or an operating system, this book will show you how to use Rust's asyn
rust-lang.github.io
반응형'코딩Coding > Rust❤️Optimization❤️' 카테고리의 다른 글
Rust Concurrency최적화❤️러스트에 Futures Concurrency가 std에 들어오면 대박이겠다. ㅎㅎ join 따로 안해도 그냥 동시실행. ㅎㅎ (0) 2022.05.24 The Important of Not Over-Optimizing in Rust❤️- Lily Mara (0) 2022.05.22 Rust tokio::task::spawn_blocking()? What is it good for? (0) 2022.05.18 Should you use to_string() or .to_owned? Intro to Rust Micro-benchmarking w/ Criterion: (0) 2022.05.18 GraphQL❤️이 더 빠른 이유..(이 영상을 보고 나면 REST API 를 못쓰게 됩니다.-노마드 코더 Nomad Coders) (0) 2022.05.15 Rust최적화❤️Conditional Compilation with Cargo Features❤️ (0) 2022.05.15 Rust) inline_const (0) 2022.05.10 Rust]_뭐가 빠른지 비교할때 쓰는 cargo bench__최적화할 기능이 뭔지 Rust를 잘 찾아보자 (0) 2022.05.02