[zeromq-dev] potential fix for issue #50

Martin Sustrik sustrik at 250bpm.com
Sat Feb 12 14:51:15 CET 2011


Hi Chuck,

> I started mucking around with the code in mailbox::send() to fix the assertion that OSX users (like me) oftentimes get in high-volume situations.
>
> For one, getsockopt() returns 0 on OSX! So the line to expand the SNDBUF doesn't work:
>
>    new_sndbuf = old_sndbuf * 2;
>
> Obviously, 0 times anything is 0 so the expansion fails.
>
> The other weird thing on OSX is that when getsockopt() does return a valid value, it's in kilobytes instead of bytes. That is, it will return 32 when it should return 32768.
>
> So I rewrote the logic to expand the buffer like so:
>
>    new_sndbuf = (old_sndbuf == 0) ? 32768 : (old_sndbuf * 2048);
>
> It works. I no longer get the assertion.
>
> However, that code will likely break horribly on linux.

1. Solving the getsockopt()=0 issue

What I think should be done is to specify the initial buffer size 
explicitly in config.hpp (say 64kB). mailbox_t would set the buffer size 
when created and remember the actual buffer size. That way there would 
be able to know the buffer size without calling getsockopt().

2. The B/kB issue should be solved like this:

#ifdef ZMQ_HAVE_OSX
     buffer_size = initial_buffer_size
#else
     buffer_size = initial_buffer_size * 1024
#endif

Martin



More information about the zeromq-dev mailing list