[WebAssembly/Rust] Lunatic이란? / 사용법
Lunatic 이란?
브라우저의 가상머신에서, 엄청나게 많은 작업을, 동시에 실행 수 있도록 만든 WebAssembly 라이브러리 (런타임)
탄생 배경
Erlang의 무수히 많은 프로세스
여기서 말하는 프로세스는, OS가 다루는 프로세스가 아니라
가상머신위에서 동작하는 가상의 프로세스를 뜻한다.
( 가상 프로세스가 좋은 이유 : 추후 작성 예정 )
WebAssembly의 확장성, 호환성, 유연성
웹 어셈블리는, 브라우저 가상머신위에서 동작가능하여 javascript와 합칠 수 있고,
C, Rust 와 같은 low-level 언어로 작성된 코드를, 웹 어셈블리로 바꿔서 사용할 수 있으므로,
자신이 원하는 언어로 작성할 수 있다.
장점
WebAssembly로 컴파일 할 수 있는 모든 언어를 통해,
가상 프로세스를 활용할 수 있다.
(ex : Rust의 속도, 보안 + Erlang의 엄청난 작업량, 죽지 않는 서비스)
사용법 (Rust)
현재 루나틱은, Rust를 통한 Api 를 제공하고 있다.
루나틱 런타임 설치하기
cargo install lunatic-runtime
루나틱 Rust 라이브러리 설치하기
cargo add runatic
새로운 Rust 프로젝트 만들기
cargo new lunatic-hi
cd lunatic-hi
루나틱 프로젝트 설정하기
# Rust를 WebAssembly로 컴파일하기 위한 설정
lunatic init
루나틱 예제 코드 ( main.rs )
use lunatic::spawn;
#[lunatic::main]
fn main() {
for _ in 0..2000 {
// 가상 프로세스 생성하기
spawn!(|| {
println!("Hello world!");
});
}
}
// 루나틱에서 테스트 코드 작성하기
#[lunatic::test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
실행
cargo run
추가 정보
루나틱 기반 웹 프레임워크 submillisecond
GitHub - lunatic-solutions/submillisecond: A lunatic web framework
A lunatic web framework. Contribute to lunatic-solutions/submillisecond development by creating an account on GitHub.
github.com
Elixir Pheonix 의 루나틱 버전 submillisecond-live-view
가상 웹 소켓을 사용하여, 수천개의 웹 소켓 연결을 유지 할 수 있다 ㅋㅋ
GitHub - lunatic-solutions/submillisecond-live-view: Live view for the submillisecond web framework
Live view for the submillisecond web framework. Contribute to lunatic-solutions/submillisecond-live-view development by creating an account on GitHub.
github.com
루나틱 깃허브
GitHub - lunatic-solutions/lunatic: Lunatic is an Erlang-inspired runtime for WebAssembly
Lunatic is an Erlang-inspired runtime for WebAssembly - GitHub - lunatic-solutions/lunatic: Lunatic is an Erlang-inspired runtime for WebAssembly
github.com