Rust Parallelism&Concurrency

link







외부 자료



Async Rust여기에 정리중|🔝|

Green Thread그린쓰레드 이해하기|🔝|


Rc, Arc 그림, 표로 잘 정리됨.|🔝|


1 Hour Dive into Asynchronous Rust | Ardan Labs|🔝|


OpenTeleMetry(Rust)|🔝|

https://opentelemetry.io/docs/languages/rust/getting-started/


Tokio-Console : It's like "htop" for async|🔝|

cargo install tokio-console


What is Pinning?|🔝|

  • Rust's memory model strictly ensures that references must still exist, won't move, and won't be bropped while still in use.
    • 러스트의 메모리 모델은 참조가 여전히 존재해야 하고, 움직이지 않아야 하며, 사용 중에도 끊어지지 않도록 엄격하게 보장합니다.
  • That's great for avoiding common memory bugs.
    • 일반적인 메모리 버그를 방지하는 데 좋습니다.
  • It's tricky in a highly asynchronous environment, tasks may depend upon other tasks - which typically move around quite a bit.
    • 매우 비동기적인 환경에서는 작업이 까다롭기 때문에 작업은 다른 작업에 따라 달라질 수 있습니다. 이 작업은 일반적으로 상당히 많이 움직입니다.
  • Pinning lets you tell Rust that a variable needs to stick around - in the same place - untile you unpin it.
    • Pinning피닝을 사용하면 Rust에게 변수를 풀 때까지 같은 위치에 있어야 한다는 것을 알 수 있습니다.
      • A stream that relies upon another stream will typically pin its access to the previous stream.
        • 다른 스트림에 의존하는 스트림은 일반적으로 이전 스트림에 대한 액세스를 고정합니다.
      • A select operation may need to pin entries for the same reason.
        • 선택 작업에서 동일한 이유로 항목을 고정해야 할 수도 있습니다.
      • Asynchronously calling yourself-recursion - requires pinning the iterations.
        • 비동기적으로 자신을 호출하려면 반복을 고정해야 합니다.

출처 : 59min30sec__1 Hour Dive into Asynchronous Rust


OpenTelemetry|🔝|

# Cargo.toml
[dependencies]
opentelemetry = "0.22"
opentelemetry_sdk = "0.22"
opentelemetry-stdout = { version = "0.3", features = ["trace"] }
use opentelemetry::{
    global,
    sdk::trace::TracerProvider,
    trace::{Tracer, TracerProvider as _},
};

fn main() {
    // Create a new trace pipeline that prints to stdout
    let provider = TracerProvider::builder()
        .with_simple_exporter(opentelemetry_stdout::SpanExporter::default())
        .build();
    let tracer = provider.tracer("readme_example");

    tracer.in_span("doing_work", |cx| {
        // Traced app logic here...
    });

    // Shutdown trace pipeline
    global::shutdown_tracer_provider();
}

use std::{thread, time::Duration};

use opentelemetry::{
    global,
    trace::{TraceContextExt, Tracer},
    Key, KeyValue,
};
use uptrace::UptraceBuilder;

#[tokio::main]
async fn main() {
    UptraceBuilder::new()
        //.with_dsn("")
        .with_service_name("myservice")
        .with_service_version("1.0.0")
        .with_deployment_environment("testing")
        .configure_opentelemetry()
        .unwrap();

    let tracer = global::tracer("app_or_crate_name");

    tracer.in_span("root-span", |cx| {
        thread::sleep(Duration::from_millis(5));

        tracer.in_span("GET /posts/:id", |cx| {
            thread::sleep(Duration::from_millis(10));

            let span = cx.span();
            span.set_attribute(Key::new("http.method").string("GET"));
            span.set_attribute(Key::new("http.route").string("/posts/:id"));
            span.set_attribute(Key::new("http.url").string("http://localhost:8080/posts/123"));
            span.set_attribute(Key::new("http.status_code").i64(200));
        });

        tracer.in_span("SELECT", |cx| {
            thread::sleep(Duration::from_millis(20));

            let span = cx.span();
            span.set_attribute(KeyValue::new("db.system", "mysql"));
            span.set_attribute(KeyValue::new(
                "db.statement",
                "SELECT * FROM table LIMIT 100",
            ));
        });

        let span = cx.span();
        println!(
            "https://app.uptrace.dev/traces/{}",
            span.span_context().trace_id().to_string()
        );
    });

    global::shutdown_tracer_provider();
}

Concurrency와 Parallelism이해하기|🔝|

https://spacebike.tistory.com/22

Multithreading for Beginners | freeCodeCamp.org|🔝|

rust -memory-container|🔝|

https://github.com/usagi/rust-memory-container-cs


  • small size ver.

rust-memory-container-cs-small-dark-back-high-contrast


Ownership Concept Diagram|🔝|

rust-ownvership

출처:

https://www.reddit.com/r/rust/comments/mgh9n9/ownership_concept_diagram/?utm_source=share&utm_medium=ios_app&utm_name=iossmf


Screenshot 2023-01-21 at 10 56 20 AM
220607자바(Java)vs러스트비교하면서 러스트오너쉽개념이해기본syntax연습하기part3_#java #rust #ownership


출처

Rust for Java Developers 3/3 - Understanding Ownership

Rust소유권 규칙Ownership Rules & Borrowing rules

Rust) shared reference ❤️ unique reference



Send & Mutex | Özgün Özerk|🔝|


Compact and efficient synchronization primitives for Rust. Also provides an API for creating custom synchronization primitives.|🔝|


C언어 러스트 이해하기

Async Engine in C | Tsoding Daily|🔝|