I have the following setup:
1. In each request's `log_by_lua`, I record stats into a per-worker table. This typically involves operations like:
worker_stats['num_requests'] += 1
worker_stats['total_request_time'] += ...
2. I'm using a per-worker background task to periodically send those stats to another server.
local last_batch = worker_stats
worker_stats = {}
send_stats_to_server(last_batch)
// schedule this to run again in 100ms with nginx.timer.at
To make sure the data is correct, I need certain operations to be atomic. In the `log_by_lua` I need the increment operations to be individually atomic, but it would be nice if the whole block of increment operations were atomic. In the background task, I need the first two lines to be atomic.
Are things already guaranteed to be atomic (within the worker) as long as I don't explicitly yield or perform I/O? If not, is there something I can do to make sure my stats are tracked precisely?
Thanks!