第13问:pt-table-checksum 到底会不会影响业务性能?

本文通过实验证明,pt-table-checksum在合理配置下,对业务性能的影响极小。通过对工具内部机制的深入剖析,如调整innodb锁等待时间、使用RR隔离级别、数据块校验等,确保了业务流量的平稳运行。

问题

用 pt-table-checksum 时,会不会影响业务性能?

实验

实验开始前,给大家分享一个小经验:任何性能评估,不要相信别人的评测结果,要在自己的环境上测试,并**(大概)知晓原理**。

我们先建一对主从:

然后用 mysqlslap 跑一个持续的压力:

开另外一个会话,将 master 上的 general log 打开:

然后通过 pt-table-checksum 进行一次比较:

查看 master 的 general log,由于 mysqlslap 的影响,general log 中有很多内容,我们找到与 pt-table-checksum 相关的线程:

将该线程的操作单独列出来:

操作比较多,我们一点一点来说明:

这里工具调小了 innodb 锁等待时间。使得之后的操作,只要在 innodb 上稍微有锁等待,就会马上放弃操作,对业务影响很小。

另外工具调小了 wait_timeout 时间,倒是没有特别的作用。

工具将隔离级别调整为了 RR 级别,事务的维护代价会比 RC 要高,不过后面我们会看到工具使用的每个事务都很小,加上之前提到 innodb 锁等待时间调到很小,对线上业务产生的成本比较小。

RR 级别是数据对比的基本要求。

工具通过一系列操作,了解表的概况。工具是一个数据块一个数据块进行校验,这里获取了第一个数据块的下边界。

接下来工具获取了下一个数据块的下边界,每个 SQL 前都会 EXPLAIN 一下,看一下执行成本,非常小心翼翼。

之后工具获取了一个数据块的 checksum,这个数据块不大,如果跟业务流量有冲突,会马上出发 innodb 的锁超时,立刻退让。

以上是 pt-table-checksum 的一些设计,可以看到这几处都是精心维护了业务流量不受影响。

工具还设计了其他的一些机制保障业务流量,比如参数 --max-load 和 --pause-file 等,还有精心设计的数据块划分方法,索引选择方法等。大家根据自己的情况配合使用即可达到很好的效果。

总结

本期我们介绍了简单分析 pt-table-checksum 是否会影响业务流量,坊间会流传工具的各种参数建议或者不建议使用,算命的情况比较多,大家都可以用简单的实验来分析其中机制。

还是那个观点,性能测试不能相信道听途说,得通过实验去分析。


关于 MySQL 的技术内容,你们还有什么想知道的吗?赶紧留言告诉小编吧!

给你调试信息,这是一个NVMP平台编写的IPC(网络摄像头),编译烧录进摄像头,串口连接IPC,上电启动,给出的调试信息。 帮我按块分析调试信息,我是初学者,看看能帮我从这里学到什么 NDI>Tdma1 ini_ver 0x30210906 ETH trim = 00001BF4 speed 000003A5 Non S3 >ddr3 WT = 0E310067 dma ok UNZOK! Loader Start ... LD_VER 04.00.00 566_DRAM1_933_1024Mb 12/26/2022 08:39:56 No card inserted Pad driving increased SPI NAND MID=000000C8 DEV=00000001 read fdt tmp_addr 0x02000000 LdCtrl2 0x00000000 uboot_addr 0x06000000 uboot_size 0x01FC0000 nodep 0x001038A0 NVT_LINUX_SMP_OFFfdt 0x00100000 shm 0x00300000 jump 0x06000000 U-Boot 2019.04 (Aug 13 2025 - 18:18:09 +0800), Build: jenkins-VIGI-IPC_REPO_1.7_NT9856X_DBG-632 CPU: Novatek NT @ 960 MHz DRAM: 128 MiB Relocation to 0x07efd000, Offset is 0x01efd000 sp at 07bf5e00 nvt_shminfo_init: The fdt buffer addr: 0x07bfb3c8 ARM CA9 global timer had already been initiated otp_init! 120MHz otp_timing_reg= 0xff6050 CONFIG_MEM_SIZE = 0x08000000 CONFIG_NVT_UIMAGE_SIZE = 0x00800000 CONFIG_NVT_ALL_IN_ONE_IMG_SIZE = 0x02000000 CONFIG_UBOOT_SDRAM_BASE = 0x06000000 CONFIG_UBOOT_SDRAM_SIZE = 0x01fc0000 CONFIG_LINUX_SDRAM_BASE = 0x01100000 CONFIG_LINUX_SDRAM_SIZE = 0x04f00000 CONFIG_LINUX_SDRAM_START = 0x05800000 NAND: drv_nand_reset: spi flash pinmux 0x0 ecc-mode = <0> nand chip_sel = <0> id = 0xc8 0x01 0x7f 0x7f use flash on-die ecc nvt spinand 4-bit mode @ 40000000 Hz 128 MiB MMC: mmc_nvt_parse_driving: sdio pinmux 0x5 NVT_MMC0: 0 fdt init fail return 48 misc_init_r: boot time: 282220(us) DTS find cpu freq clock 960MHz Set CPU clk 960MHz nvt_dts_config_parsing: Label: loader PartitionOffset=0 PartitionSize=40000 nvt_dts_config_parsing: Label: fdt PartitionOffset=40000 PartitionSize=100000 nvt_dts_config_parsing: Label: fdt_restore PartitionOffset=140000 PartitionSize=100000 nvt_dts_config_parsing: Label: uboot PartitionOffset=240000 PartitionSize=100000 nvt_dts_config_parsing: Label: factory_info PartitionOffset=340000 PartitionSize=80000 nvt_dts_config_parsing: Label: pt_table PartitionOffset=3c0000 PartitionSize=180000 nvt_dts_config_parsing: Label: pt_table_restore PartitionOffset=540000 PartitionSize=180000 nvt_dts_config_parsing: Label: ubi1 PartitionOffset=6c0000 PartitionSize=3000000 misc_init_r: boot time: 426194(us) Net: na51089_eth_initialize 1.0.0.3 eth_parse_phy_intf: led-inv len -1 eth_parse_phy_intf: inv-led 0 eth_parse_phy_intf: phy-intf 0x2 phy interface: INTERNAL MII eth_na51089 ir-cut gpio init Hit any key to stop autoboot: 0 factory boot running found str mtdparts=spi_nand.0:256k(loader),1m(fdt),1m(fdt_restore),1m(uboot),512k(factory_info),1536k(pt_table),1536k(pt_table_restore),48m(ubi1) found str mtdparts=spi_nand.0:256k(loader),1m(fdt),1m(fdt_restore),1m(uboot),512k(factory_info),1536k(pt_table),1536k(pt_table_restore),48m(ubi1) NAND read: device 0 offset 0x3c0000, size 0x188 392 bytes read: OK NAND read: device 0 offset 0x3c0000, size 0x10dc 4316 bytes read: OK NAND read: device 0 offset 0x540000, size 0x10dc 4316 bytes read: OK pt table is ok,read it finish partition loader skip,not check NAND read: device 0 offset 0x40000, size 0x5000 20480 bytes read: OK check partition fdt from 0x40000 to 0x5000.....ok partition fdt_restore skip,not check partition uboot skip,not check partition factory_info skip,not check partition pt_table skip,not check partition pt_table_restore skip,not check found str spi_nand.0:256k(loader),1m(fdt),1m(fdt_restore),1m(uboot),512k(factory_info),1536k(pt_table),1536k(pt_table_restore),48m(ubi1) ubi0: attaching mtd8 ubi0: scanning is finished now load lum:ubi1_bootloader(len:15),id:0,peb:22528 now load lum:ubi1_isp(len:8),id:1,peb:22528 now load lum:ubi1_kernel_linux(len:17),id:2,peb:22528 now load lum:ubi1_rootfs_squashfs(len:20),id:3,peb:22528 now load lum:ubi1_uc(len:7),id:4,peb:22528 ubi0: attached mtd8 (name "ubi1", size 48 MiB) ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048 ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096 ubi0: good PEBs: 384, bad PEBs: 0, corrupted PEBs: 0 ubi0: user volume: 5, internal volumes: 1, max. volumes count: 128 ubi0: max/mean erase counter: 4/2, WL threshold: 4096, image sequence number: 708394894 ubi0: available PEBs: 27, total reserved PEBs: 357, PEBs reserved for bad PEB handling: 20 Read 157208 bytes from volume ubi1_bootloader to 010010dc check ubi partition ubi1_bootloader len 0x26618.....ok Read 38092 bytes from volume ubi1_isp to 010010dc Read 524288 bytes from volume ubi1_isp to 010010dc check ex_pack ubi1_isp .....ok Read 1838776 bytes from volume ubi1_kernel_linux to 010010dc check ubi partition ubi1_kernel_linux len 0x1c0eb8.....ok Read 15073280 bytes from volume ubi1_rootfs_squashfs to 010010dc check ubi partition ubi1_rootfs_squashfs len 0xe60000.....ok partition ubi_4 skip,not check partition lte skip,not check Uip boot... Firmware check pass! Read 157208 bytes from volume ubi1_bootloader to 01000000 [XZ] !!!reserved 0x 1000000 length=0x 1000000 for xz!! XZ params: in_addr 0x1000040, in_size 0x50000, out_addr 0x4040000, out_size 0x100000 XZ: uncompress ret 7, size = 427874 normal_boot: fe 3 0 ea 14 f0 9f e5; 64 72 69 76 69 6e 67 0 ## Starting application at 0x04040000 ... U-Boot 2019.04 (Jul 25 2025 - 15:00:22 +0800), Build: jenkins-VIGI-IPC_REPO_1.7_NT9856X_DBG-544 CPU: Novatek NT @ 960 MHz DRAM: 128 MiB Relocation to 0x05f7c000, Offset is 0x01f3c000 sp at 05c74e00 nvt_shminfo_init: The fdt buffer addr: 0x05c7a3c8 ARM CA9 global timer had already been initiated otp_init! 120MHz otp_timing_reg= 0xff6050 CONFIG_MEM_SIZE = 0x08000000 CONFIG_NVT_UIMAGE_SIZE = 0x00800000 CONFIG_NVT_ALL_IN_ONE_IMG_SIZE = 0x02000000 CONFIG_UBOOT_SDRAM_BASE = 0x04040000 CONFIG_UBOOT_SDRAM_SIZE = 0x01fc0000 CONFIG_LINUX_SDRAM_BASE = 0x01100000 CONFIG_LINUX_SDRAM_SIZE = 0x04f00000 CONFIG_LINUX_SDRAM_START = 0x03840000 NAND: drv_nand_reset: spi flash pinmux 0x0 ecc-mode = <0> nand chip_sel = <0> id = 0xc8 0x01 0x7f 0x7f use flash on-die ecc nvt spinand 4-bit mode @ 40000000 Hz 128 MiB MMC: mmc_nvt_parse_driving: sdio pinmux 0x5 NVT_MMC0: 0 fdt init fail return 48 misc_init_r: boot time: 3828561(us) DTS find cpu freq clock 960MHz Set CPU clk 960MHz nvt_dts_config_parsing: Label: loader PartitionOffset=0 PartitionSize=40000 nvt_dts_config_parsing: Label: fdt PartitionOffset=40000 PartitionSize=100000 nvt_dts_config_parsing: Label: fdt_restore PartitionOffset=140000 PartitionSize=100000 nvt_dts_config_parsing: Label: uboot PartitionOffset=240000 PartitionSize=100000 nvt_dts_config_parsing: Label: factory_info PartitionOffset=340000 PartitionSize=80000 nvt_dts_config_parsing: Label: pt_table PartitionOffset=3c0000 PartitionSize=180000 nvt_dts_config_parsing: Label: pt_table_restore PartitionOffset=540000 PartitionSize=180000 nvt_dts_config_parsing: Label: ubi1 PartitionOffset=6c0000 PartitionSize=3000000 misc_init_r: boot time: 3972621(us) ir-cut gpio init uboot running Hit any key to stop autoboot: 0 do_nvt_boot_cmd: boot time: 4283418(us) NAND read: device 0 offset 0x3c0000, size 0x188 392 bytes read: OK NAND read: device 0 offset 0x3c0000, size 0x10dc 4316 bytes read: OK ubi0: attaching mtd8 ubi0: scanning is finished now load lum:ubi1_bootloader(len:15),id:0,peb:22528 now load lum:ubi1_isp(len:8),id:1,peb:22528 now load lum:ubi1_kernel_linux(len:17),id:2,peb:22528 now load lum:ubi1_rootfs_squashfs(len:20),id:3,peb:22528 now load lum:ubi1_uc(len:7),id:4,peb:22528 ubi0: attached mtd8 (name "ubi1", size 48 MiB) ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048 ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096 ubi0: good PEBs: 384, bad PEBs: 0, corrupted PEBs: 0 ubi0: user volume: 5, internal volumes: 1, max. volumes count: 128 ubi0: max/mean erase counter: 4/2, WL threshold: 4096, image sequence number: 708394894 ubi0: available PEBs: 27, total reserved PEBs: 357, PEBs reserved for bad PEB handling: 20 Read 1838776 bytes from volume ubi1_kernel_linux to 03840000 do_nvt_boot_cmd: boot time: 4854462(us) do_nvt_boot_cmd: bootargs:earlyprintk console=ttyS0,115200 rootwait nprofile_irq_duration=on ro mtdparts=spi_nand.0 ubi.mtd=8 root=/dev/mtdblock12 rootfstype=squashfs noinitrd init=/etc/preinit loglevel=1 bootts=3740150,4858720 resume_addr=0x00300088 user_debug=0xff Image Name: Linux-4.19.91 Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 1838712 Bytes = 1.8 MiB Load Address: 00008000 Entry Point: 00008000 Linux Image is at 3840000, uboot fdt image is at 5c7a3c8, loader tmp fdt address is at 100000 bootm 3840000 - 5c7a3c8 do_nvt_boot_cmd: boot time: 4909527(us) do_nvt_boot_cmd: Uboot boot time: start: 3740150 us ending: 4858720 us ## Booting kernel from Legacy Image at 03840000 ... Image Name: Linux-4.19.91 Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 1838712 Bytes = 1.8 MiB Load Address: 00008000 Entry Point: 00008000 Verifying Checksum ... OK ## Flattened Device Tree blob at 05c7a3c8 Booting using the fdt blob at 0x5c7a3c8 Loading Kernel Image Loading Device Tree to 047f8000, end 047ff0af ... OK Starting kernel ... ACTLR: 0x00000004 ACTLR: 0x00000044 Disable MMU Clear MMU Uboot L2 cache aux val: 0x72420000 Uboot L2 cache prefetch ctrl val: 0x70800000 Uboot L2 cache ctrl val: 0x00000000 Done Uncompressing Linux... done, booting the kernel. Please press Enter to activate this console. (c540-4g_1.20) login: (c540-4g_1.20) login: (c540-4g_1.20) login: Monitor: enable print. timer handle excute times 24, interval 1 timer handle excute times 3, interval 1 timer handle excute times 236, interval 1 Registered character driver x-motor Registered character driver y-motor ------------------tour dump--------------------- [1] en=0 spot_num=0 id=1 name=tour_1 status:0 [2] en=0 spot_num=0 id=2 name=tour_2 status:0 [3] en=0 spot_num=0 id=3 name=tour_3 status:0 [4] en=0 spot_num=0 id=4 name=tour_4 status:0 [5] en=0 spot_num=0 id=5 name=tour_5 status:0 [6] en=0 spot_num=0 id=6 name=tour_6 status:0 [7] en=0 spot_num=0 id=7 name=tour_7 status:0 [8] en=0 spot_num=0 id=8 name=tour_8 status:0 ------------------end dump----------------------- timer handle excute times 74, interval 1 timer handle excute times 2, interval 1 device name or hw_ver in factory info is null,use device name in isp timer handle excute times 24, interval 1 [2025-07-25 15:02:33] [ERROR] ds_handle_method_do():1608 - [DS]not support action get_rtsp_info [2025-07-25 15:02:33] [ERROR] ds_handle():2504 - [DS]Signal handle failed. plug -->DWC_ETH_QOS_setsettings <--DWC_ETH_QOS_setsettings [2025-07-25 15:02:38] [ERROR] system_if_del_gateway_changing MTU from 1500 to 1480 route():267 - [NIFC]Ioctl SIOCDELRT error, ret code is -1, dst =DWC_ETH_QOS_yinit: apb_clk 120000000 Hz 00000000, gateway = 0100a8c0, error info:No such process. Queue0 Tx fifo size 2048, Rx fifo size 2048 Disabled JUMBO pkt Enabled Rx watchdog timer Enabled TSO Disabled Rx Split header mode
最新发布
09-20
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值