What are the drawbacks of disabling the output_buffer?

55 views
Skip to first unread message

marin prcela

unread,
May 6, 2019, 9:36:22 AM5/6/19
to nsq-users
By default connections to nsqd are buffered (output_buffer_size 16k) and flushed at some timeout (output_buffer_timeout 250ms).
https://github.com/nsqio/go-nsq/blob/master/config.go#L165

When timeout is set to low values (<25ms) then nsqd CPU raises.

On the other hand, when buffering is disabled the CPU is almost the same as with 250ms buffering timeout (in my case). With the difference that messages are delivered instantly! :)

I can see that the implementation uses bufio.NewWriterSize for writing to tcp connection.

Why are tcp writes buffered?
What are the drawbacks of disabling the buffer?

Matt Reiferson

unread,
May 6, 2019, 12:47:28 PM5/6/19
to marin prcela, nsq-users
Hi Marin,

> On the other hand, when buffering is disabled the CPU is almost the same as with 250ms buffering timeout (in my case)

Depending on the number of connections configured that way, you might not see any difference (it's really only an issue with many connections).

> Why are tcp writes buffered?

To reduce the number of syscalls and improve throughput.

> What are the drawbacks of disabling the buffer?

You likely won't be able to achieve peak throughput. This may not matter to your particular use case though, the defaults are meant to be a happy medium.

Hope this helps.

Thanks,

Matt

marin prcela

unread,
May 13, 2019, 4:38:57 AM5/13/19
to nsq-users
Thank you for your answer!
That cleared things up.

On Monday, May 6, 2019 at 6:47:28 PM UTC+2, Matt Reiferson wrote:
Hi Marin,

> On the other hand, when buffering is disabled the CPU is almost the same as with 250ms buffering timeout (in my case)

Depending on the number of connections configured that way, you might not see any difference (it's really only an issue with many connections).

> Why are tcp writes buffered?

To reduce the number of syscalls and improve throughput.

> What are the drawbacks of disabling the buffer?

You likely won't be able to achieve peak throughput. This may not matter to your particular use case though, the defaults are meant to be a happy medium.

Hope this helps.

Thanks,

Matt

Reply all
Reply to author
Forward
0 new messages