Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Apr 2010 14:49:32 -0500
From:      Dan Nelson <dnelson@allantgroup.com>
To:        Joerg Bruehe <joerg@mysql.com>
Cc:        Greg 'groggy' Lehey <grog@lemis.com>, FreeBSD-Questions <freebsd-questions@freebsd.org>
Subject:   Re: Need info about FreeBSD and interrupted system calls for MySQL code
Message-ID:  <20100429194932.GI14572@dan.emsphone.com>
In-Reply-To: <4BD9D098.8010201@mysql.com>
References:  <4BD9D098.8010201@mysql.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Apr 29), Joerg Bruehe said:
> For some long, unknown time, the MySQL code contains a variable
> "net_retry_count" which is by default set to 10 (ten) for all platforms,
> but to 1000000 (1 million) for FreeBSD (during configure phase).
> 
> The source code comment about this variable reads
>        If a read on a communication port is interrupted, retry this many
>        times before giving up.
> 
> The documentation (manual) has this sentence in addition:
>        This value should be set quite high on FreeBSD because internal
>        interrupts are sent to all threads.
> 
> I read that as
> "On FreeBSD, a thread may receive many more interrupts than on other
> platforms, so an operation which may take some time (like network I/O)
> may be interrupted much more often than on other platforms, and hence
> the retry count should be higher."
> 
> I trust that this comment was valid at the time it was written -
> is it still true for current versions of FreeBSD, or did things change?

I'm pretty sure this is a holdover from when FreeBSD only had a user
pthreads package (libc_r).  libc calls that would normally block got
converted into non-blocking versions and a select() loop would execute
threads as the events they were waiting on occurred.  Incoming signals would
cause all threads waiting on read() to return EINTR.  If you have other
threads doing work and sending/receiving signals, this can add up to a lot
of extra EINTR's.

FreeBSD 5.0 (released in 2003) was the first version to have kernel-based
pthread support, so the original reason for raising net_retry_count has long
since disappeared.

A related question might be, though:  Should that variable even exist? 
EINTR isn't technically a failure, and most programs that read from sockets
simply wrap their read()s in a loop that retries when EINTR is received. 
Only mysql actually counts the number of times through the loop.

-- 
	Dan Nelson
	dnelson@allantgroup.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100429194932.GI14572>