Thread blocking
Closed this issue · 2 comments
dddenis commented
Hey,
I've been experimenting with the app and encountered the following issue:
Although the app is mostly async, there are several blocking calls:
When execution reaches any of these calls, it will block the thread.
Let's take a look at the first example (inside run_metadata_collector
function):
- This stage is reached after every iteration of the metadata collector.
- The thread is being blocked for the duration of
cfg.collect_interval
, which is 15s be default. run_metadata_collector
is joined with theread_file
async branch:
hasura-metric-adapter/metrics/src/main.rs
Lines 162 to 166 in 0ab0c6e
- Now the
read_file
is unable to continue, until the thread is unblocked byrun_metadata_collector
. - This results in logs being processed by
read_file
in short bursts every 15s and not as soon as they arrive.
The effect this has on the app's behavior when hasura generates lots of logs depends on where the logs are redirected to:
- normal file - the metrics adapter can't keep up and reports the logs metrics with delay, giving incorrect representation of the system state.
- named pipe - as soon as the pipe's buffer is filled, it blocks the writer process (hasura) until the reader process (metrics adapter) frees the buffer by reading more lines.
The named pipe case is the most troublesome, as it results in hasura requests being throttled. I think it is the cause of this issue: #31.
Reproduction case:
- Clone the repo.
- Start docker compose.
- Go to the
Data
tab in the hasura console (http://localhost:8080/console/data/) - Create an empty table (e.g. table
test
with single columnid
). - Go to the
API
tab in the hasura console (http://localhost:8080/console/api/api-explorer). - Prepare a simple request to the table created above in the GraphiQL, e.g.:
query MyQuery {
test {
id
}
}
- Open the browser network tab and start constantly sending requests with
Ctrl+Enter
. - After a short while the requests will stop resolving in the network tab as the named pipe buffer is filled with unprocessed logs due to metric adapter's thread being blocked.
- At this point the whole hasura console will stop working correctly and will get back to normal only when the metric adapter catches up with the accumulated logs.
dddenis commented