코딩Coding/Rust❤️Optimization❤️

Rust_concurrency❤️최적화 - Rayon을 써야 할 때와 tokio를 써야 할 상황 알아 보기 &❤️futures concurrency

내인생PLUS 2022. 5. 17. 18:52
728x90

Rayon 기초

https://youtu.be/gof_OEv71Aw

 




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/tutorial

 

Tutorial | 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/tutorial

 

Tutorial | 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

https://youtu.be/D1NAREuicNs







내장되어 있는 std

futures -> 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

https://youtu.be/QlPDI9IsSXU










Rust ❤️Asynchronous Programming

 

https://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


 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

반응형