Bug #22943 syscall pruning in libmysql
Submitted: 3 Oct 2006 15:10 Modified: 21 Feb 2007 3:26
Reporter: Georg Richter Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:all OS:Windows (Windows)
Assigned to: Magnus BlÄudd CPU Architecture:Any
Tags: performance, setsockopt

[3 Oct 2006 15:10] Georg Richter
Description:
The vio_timeout function is called from net_real_write for every 
packet that is sent, it's probably not optimal to set the receive 
timeout on every write.

On Windows platform this slows down the performance between client and server.

How to repeat:
-

Suggested fix:
-
[3 Oct 2006 16:21] Jim Winstead
Bug #22947 was marked as a duplicate of this bug.
[10 Oct 2006 3:36] Mark Callaghan
This is also a problem for my_real_read on Linux (I assume it is a problem for write as well, but I have not checked the code.

vio_timeout has been changed between 4.1.14 and 4.1.21 so that it calls setsockopt each time it is called and my_real_read calls vio_timeout each time it is called (when NO_ALARM is not defined). These calls to setsockopt are expensive and most of them can probably be avoided.

Version 4.1.14 vio_timeout:

void vio_timeout(Vio *vio __attribute__((unused)),
                 uint which __attribute__((unused)),
                 uint timeout __attribute__((unused)))
{
#ifdef __WIN__
  ulong wait_timeout= (ulong) timeout * 1000;
  (void) setsockopt(vio->sd, SOL_SOCKET,
        which ? SO_SNDTIMEO : SO_RCVTIMEO, (char*) &wait_timeout,
        sizeof(wait_timeout));
#endif /* __WIN__ */
}

Version 4.1.21 vio_timeout:

void vio_timeout(Vio *vio, uint which, uint timeout)
{
#if defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO)

#ifdef __WIN__

  /* Windows expect time in milliseconds as int. */
  int wait_timeout= (int) timeout * 1000;

#else  /* ! __WIN__ */

  /* POSIX specifies time as struct timeval. */
  struct timeval wait_timeout;
  wait_timeout.tv_sec= timeout;
  wait_timeout.tv_usec= 0;

#endif /* ! __WIN__ */

  (void) setsockopt(vio->sd, SOL_SOCKET, which ? SO_SNDTIMEO : SO_RCVTIMEO,
                    (char*) &wait_timeout, sizeof(wait_timeout));

#endif /* defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO) */
}
[29 Jan 2007 13:31] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/18941

ChangeSet@1.2599, 2007-01-29 14:31:48+01:00, msvensson@pilot.mysql.com +11 -0
  Bug#22943 syscall pruning in libmysql
   - Set the timeout values only where needed
[14 Feb 2007 14:59] Chad MILLER
Available in 4.1.23, 5.0.36, and 5.1.16-beta.
[21 Feb 2007 3:26] Paul DuBois
Noted in 4.1.23, 5.0.36, 5.1.16 changelogs.

The number of setsockopt() calls performed for reads and writes to
the network socket was reduced to decrease system call overhead.