Commit f746f8e
authored
fix(CubeProxy): initialize random seed in worker phase (#138)
In OpenResty, all worker processes inherit the same state from the
master process. Without explicitly seeding the random number generator
in the init_worker phase, each worker starts with the same default
seed. This results in math.random() producing the exact same sequence
of numbers across all workers.
Seeding with (ngx.now() * 1000 + ngx.worker.id()) ensures that each
worker has a unique, time-varying seed. This is essential for features
like cache TTL jitter to work as intended and avoid synchronized
cache expiration stampedes.
Signed-off-by: novahe <heqianfly@gmail.com>1 parent 09101b2 commit f746f8e
1 file changed
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
1 | 8 | | |
2 | 9 | | |
3 | 10 | | |
| |||
0 commit comments