1
0
mirror of https://github.com/actix/examples synced 2024-11-27 16:02:57 +01:00
examples/async_data_factory
2020-09-12 16:49:45 +01:00
..
src v3 examples (#364) 2020-09-12 16:49:45 +01:00
Cargo.toml v3 examples (#364) 2020-09-12 16:49:45 +01:00
README.md fixes according to reviews 2020-06-28 06:15:34 +08:00

Usage:

This is an example on constructing async state with App::data_factory

Reason:

data_factory would make sense in these situations:

  • When async state not necessarily have to be shared between workers/threads.

  • When async state would spawn tasks on actix-rt. If we centralized the state there could be a possibility the tasks get a very unbalanced distribution on the workers/threads (actix-rt would spawn tasks on local thread whenever it's called)

Requirement:

  • rustc 1.43 stable
  • redis server listen on 127.0.0.1:6379(or use REDIS_URL env argument when starting the example)

Endpoints:

  • use a work load generator(e.g wrk) to benchmark the end points:

      http://127.0.0.1:8080/pool   prebuilt shared redis pool
      http://127.0.0.1:8080/pool2  data_factory redis pool
    

Context:

The real world difference can be vary by the work you are doing but in general it's a good idea to spread your identical async tasks evenly between threads and have as little cross threads synchronization as possible.