Am 12.10.2012 15:39, schrieb Markus Falb: > With a low timeout the connection will be terminated sooner, but if the > application retries another connection is taken. I could have raised the > timeout with the same effect on the db side (1 process is waiting) but > maybe more performant (no new connection necessary) and with simpler > logic on the application side (no retry logic) > > Maybe you imply that there is some kind of sleep before the retry, so > that other statements could be fulfilled? > > I still don't get it
usually if you implement a db-layer with reconnect on error
you will also make a sleep before re-connect
below the relevant snippet of my since years used mysql-layer
this is from the connect-method, the query()-method itself
does disconect/connect on recoverable errors and try the same
query again after a succesfull re-connect
the intention here was to allow restart mysqld at every time
without breaking webserver-requests, usually you do not recognize
the short lag, and yes - this sort of error-handling relaxes locks
$rw = @mysqli_real_connect($this->conn, $this->host, $this->user,
$this->pwd, $this->db, $this->port, '', $flags);
if(!$rw)
{
for($retry=1; $retry<=240; $retry++)
{
$this->conn = @mysqli_init();
if($this->ssl)
{
if($this->ssl_crt === '')
{
$this->ssl_crt = 'dummy.crt';
}
/** SSL aktivieren */
$this->conn->ssl_set($this->ssl_key, $this->ssl_crt, $this->ssl_ca,
NULL, NULL);
}
$rw = @mysqli_real_connect($this->conn, $this->host, $this->user,
$this->pwd, $this->db, $this->port, '',
$flags);
if($rw)
{
$this->conn = @mysqli_init();
if($this->ssl)
{
if($this->ssl_crt === '')
{
$this->ssl_crt = 'dummy.crt';
}
$this->conn->ssl_set($this->ssl_key, $this->ssl_crt, $this->ssl_ca,
NULL, NULL);
}
$rw = @mysqli_real_connect($this->conn, $this->host, $this->user,
$this->pwd, $this->db, $this->port, '',
$flags);
break;
}
usleep(62500);
}
if(!$rw)
{
$this->conn = 0;
$this->error(mysqli_connect_error());
}
}
signature.asc
Description: OpenPGP digital signature
