Skip to content

Use LocalPoolHandle to use multiple cpu core #159

Answered by khvzak
yongman asked this question in Q&A
Discussion options

You must be logged in to vote

A single Lua instance can utilize only a single core so a common practice is use a Lua instance per core and loadbalance work between VMs.
If speak about accepting incoming tcp connections and balancing them between workers you can use approach described in https://docs.rs/tokio/latest/tokio/task/struct.LocalSet.html#use-inside-tokiospawn

  1. create a set of workers that uses mpsc channel to accept tasks
  2. create a main listener and start listening for connections
  3. send new connection to a next worker

Given that Lua perfectly integrates with Rust async, one lua VM can process thousands connections simultaneously.

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@khvzak
Comment options

@khvzak
Comment options

@yongman
Comment options

@yongman
Comment options

@yongman
Comment options

Answer selected by yongman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants