1
0
mirror of https://github.com/actix/examples synced 2024-12-18 00:13:57 +01:00
examples/data-factory/README.md

28 lines
1.1 KiB
Markdown
Raw Normal View History

# Usage:
2022-03-06 01:43:10 +01:00
This is an example demonstrating the construction of async state with `App::data_factory`
2020-06-22 15:16:25 +02:00
## Reason:
2022-03-06 01:43:10 +01:00
Use of a `data_factory` would make sense in these situations:
2022-03-06 01:43:10 +01:00
- When async state does not necessarily have to be shared between workers/threads.
2020-06-22 15:16:25 +02:00
2022-03-06 01:43:10 +01:00
- When an async state would spawn tasks on `actix-rt`. If state was centralized there could be a possibility the tasks get an unbalanced distribution on the workers/threads (`actix-rt` would spawn tasks on local thread whenever it's called)
2020-06-22 15:16:25 +02:00
## Requirement:
2022-03-06 01:43:10 +01:00
- `rustc 1.58 stable`
- `redis` server listen on `127.0.0.1:6379`(or use `REDIS_URL` env argument when starting the example)
2020-06-22 15:16:25 +02:00
## Endpoints:
2022-03-06 01:43:10 +01:00
2020-06-22 15:16:25 +02:00
- 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:
2022-03-06 01:43:10 +01:00
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.