telegraf icon indicating copy to clipboard operation
telegraf copied to clipboard

[Bug Report] Gathering is a blocking operation

Open allen13 opened this issue 10 years ago • 4 comments

Bug report

The current gathering loop prevents two gathers from the same plugin from happening concurrently if one takes longer than the interval to return.

Use case:

API response time gathering

Example Interval Format: +gather-start-time:response-time->next interval

Current behavior:

Gathers block the next interval which changes the regularity of points 10s interval +0s:20s->+20s:4s

Desired behavior:

Intervals run concurrently from each other 10s interval +0s:20s->+10s:4s->+20s:4s

Proposal:

This is a result of this commit which addressed an issue where plugins were getting stuck. This might resurface if gathers were allowed to run concurrently without constraint.

It may be possible to repurpose the timeout. Currently it just logs an error independently of the blocking gathers. Intervals could spawn concurrently but could stop spawning if none of the previous gathers have returned within the timeout timeframe.

Example with an interval of 1s and timeout of 3s: +0s:?s->+1s:?s->+2s:?s->timeout reached, waiting for one of previous threads to return before allowing next gather. Timeout window will also reset once a thread returns.

allen13 avatar Jul 13 '16 19:07 allen13

I don't think that a slow gather changes the regularity of the gather timestamps? It should happen like this:

:00 :10 :31 <-- this one was delayed 11s :40 <-- this one goes back to the :10 intervals

sparrc avatar Jul 14 '16 00:07 sparrc

also this was done by design to avoid many gathers from backing up on hung services. There isn't a practical way to "cancel" hung gather goroutines safely so I'd rather not continue spawning new ones.

sparrc avatar Jul 14 '16 00:07 sparrc

I personally don't think this would be a good idea. Many (most?) of the plugins aren't designed to handle multiple simultaneous Gather() calls. There's no protection of shared variables, so there'd be race conditions abound. Additionally measurements could overlap and skew results.

I can't think of any problem which simultaneous Gather() operations would solve that doesn't have a different better solution. Could you provide an example?

phemmer avatar Jul 14 '16 00:07 phemmer

@sparrc I definitely see the issue with continuing to spawn hung processes, which is why I proposed limiting instead of a complete unlock. I do realize Telegraf is designed to handle the most general use cases possible which is why I deliberated creating an issue here. I was specifically assigned to make gathers happen continuously for api call response times. I have already created a forked solution, but I wanted to test the waters and see if anyone else would find this functionality useful. I'll leave this issue open till the end of the week and if no one see's any value in it I will close it out

allen13 avatar Jul 14 '16 01:07 allen13