Performance / Efficiency

How well is execution scheduled, time spent, and resources used.

Maturity Levels

Sequential: One thing at a time.
  • Very simple for troubleshooting.
  • Usually already good enough.

No (extra) threads, no threading problems.

Coarse parallelism: Make a thread per task.

"More threads means more speed right?"

Only if you design for it.

This is like having one person allocated to each task. If your task breakdown is not good, then a person will be idling.

Granular concurrency: Task hopping.

When a threads needs to wait for something to be done for a given task, it can switch to another task – assuming the task switched to can be worked on by different threads.

API Implications

  • Use async to operate concurrently.
  • Use multiple threads for parallelism.
  • Shared data must be behind appropriate RwLocks.
  • Can hurt API ergonomics.
  • Potential for deadlock if not designed well.

choochoo:

  • Uses Pin<Box<dyn Future .. >> for the function return types – tasks cannot be worked on by different threads.
  • Uses tokio as the async executor.

Live Demo

rm -rf /tmp/choochoo/demo/station_{b,c,d,e,f,g,h} /tmp/server/app.zip
time ./target/release/examples/demo
time ./target/release/examples/demo --concurrent