5.8.1.10 锁定探针

每当 MySQL 使用 table 的相应锁定机制(由 table 的引擎类型定义)为 table 请求外部锁定时,都会调用锁定探针。共有三种不同类型的锁,即读锁,写锁和解锁操作。使用探针,您可以确定外部锁定例程的持续时间(即存储引擎实施锁定所花费的时间,包括 await 另一个锁定释放的任何时间)以及锁定/解锁过程的总持续时间。 。

handler-rdlock-start(database, table)
handler-rdlock-done(status)

handler-wrlock-start(database, table)
handler-wrlock-done(status)

handler-unlock-start(database, table)
handler-unlock-done(status)
  • handler-rdlock-start:在指定的databasetable上请求读锁定时触发。

  • handler-wrlock-start:在指定的databasetable上请求写锁定时触发。

  • handler-unlock-start:在指定的databasetable上发出解锁请求时触发。

  • handler-rdlock-done:读取锁定请求完成时触发。如果锁定操作成功,则status为 0,否则为>0

  • handler-wrlock-done:写锁定请求完成时触发。如果锁定操作成功,则status为 0,否则为>0

  • handler-unlock-done:解锁请求完成时触发。如果解锁操作成功,则status为 0,否则为>0

您可以使用数组来监视单个 table 的锁定和解锁,然后使用以下脚本来计算整个 table 锁定的持续时间:

#!/usr/sbin/dtrace -s

#pragma D option quiet

mysql*:::handler-rdlock-start
{
   self->rdlockstart = timestamp;
   this->lockref = strjoin(copyinstr(arg0),strjoin("@",copyinstr(arg1)));
   self->lockmap[this->lockref] = self->rdlockstart;
   printf("Start: Lock->Read   %s.%s\n",copyinstr(arg0),copyinstr(arg1));
}

mysql*:::handler-wrlock-start
{
   self->wrlockstart = timestamp;
   this->lockref = strjoin(copyinstr(arg0),strjoin("@",copyinstr(arg1)));
   self->lockmap[this->lockref] = self->rdlockstart;
   printf("Start: Lock->Write  %s.%s\n",copyinstr(arg0),copyinstr(arg1));
}

mysql*:::handler-unlock-start
{
   self->unlockstart = timestamp;
   this->lockref = strjoin(copyinstr(arg0),strjoin("@",copyinstr(arg1)));
   printf("Start: Lock->Unlock %s.%s (%d ms lock duration)\n",
          copyinstr(arg0),copyinstr(arg1),
          (timestamp - self->lockmap[this->lockref])/1000000);
}

mysql*:::handler-rdlock-done
{
   printf("End:   Lock->Read   %d ms\n",
          (timestamp - self->rdlockstart)/1000000);
}

mysql*:::handler-wrlock-done
{
   printf("End:   Lock->Write  %d ms\n",
          (timestamp - self->wrlockstart)/1000000);
}

mysql*:::handler-unlock-done
{
   printf("End:   Lock->Unlock %d ms\n",
          (timestamp - self->unlockstart)/1000000);
}

在执行时,您应该获得有关锁定过程本身的持续时间以及特定 table 上的锁定的信息:

Start: Lock->Read   test.t2
End:   Lock->Read   0 ms
Start: Lock->Unlock test.t2 (25743 ms lock duration)
End:   Lock->Unlock 0 ms
Start: Lock->Read   test.t2
End:   Lock->Read   0 ms
Start: Lock->Unlock test.t2 (1 ms lock duration)
End:   Lock->Unlock 0 ms
Start: Lock->Read   test.t2
End:   Lock->Read   0 ms
Start: Lock->Unlock test.t2 (1 ms lock duration)
End:   Lock->Unlock 0 ms
Start: Lock->Read   test.t2
End:   Lock->Read   0 ms