AsyncMysqlClientStats::callbackDelayMicrosAvg

Average delay between when a callback is scheduled in the MySQL client and when it's actually ran, in microseconds

public function callbackDelayMicrosAvg(): float;

The callback can be from creating a connection, inducing an error condition, executing a query, etc.

This returns an exponentially-smoothed average.

Returns

  • float - A float representing the average callback delay on this MySQL client.

Examples

The following example describes how to get the average delay time between when a callback is scheduled (in this case, performing the connection) and when the callback actual ran (in this case, when the connection was actually established) via AsyncMysqlClientStats::callbackDelayMicrosAvg.

require __DIR__.'/../../__includes/async_mysql_connect.inc.php';

use \Hack\UserDocumentation\API\Examples\AsyncMysql\ConnectionInfo as CI;

async function connect(
  \AsyncMysqlConnectionPool $pool,
): Awaitable<\AsyncMysqlConnection> {
  return await $pool->connect(
    CI::$host,
    CI::$port,
    CI::$db,
    CI::$user,
    CI::$passwd,
  );
}
async function get_delay(): Awaitable<?float> {
  $pool = new \AsyncMysqlConnectionPool(darray[]);
  $conn = await connect($pool);
  $delay = $conn->connectResult()?->clientStats()?->callbackDelayMicrosAvg();
  $conn->close();
  return $delay;
}

function run(): void {
  $d = \HH\Asio\join(get_delay());
  \var_dump($d);
}

run();
Output
float(11.98046875)