In my implementation we found no need to establish a new connection after a
lock timeout but just retried on the existing connection. We did instigate
a sleep timeout of 10 ms which theoretically increased on each iteration
but we never had to try a third time even under very heavy load.

On 2012-10-12 10:02 AM, "Reindl Harald" <h.rei...@thelounge.net> wrote:



Am 12.10.2012 15:39, schrieb Markus Falb:

> With a low timeout the connection will be terminated sooner, but if the
> application retries anot...
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());
      }
     }

Reply via email to