Sysbench 性能测试

    在1000数据量的基础上分库分表,根据分为4个库,部署在同一台机器上,根据k分为1024个表,查询操作路由到单库单表; 作为对比,MySQL 运行在1000数据量的基础上,使用 INSERT+UPDATE+DELETE 和单路由查询语句。

    主从

    基本主从场景,设置一主库一从库,部署在两台不同的机器上,在10000数据量的基础上,观察读写性能; 作为对比,MySQL 运行在10000数据量的基础上,使用 INSERT+SELECT+DELETE 语句。

    主从+加密+分库分表

    全路由

    在1000数据量的基础上,分库分表,根据id分为4个库,部署在四台不同的机器上,根据k分为1个表,查询操作使用全路由。 作为对比,MySQL 运行在1000数据量的基础上,使用 INSERT+UPDATE+DELETE 和全路由查询语句。

    此处表结构参考 sysbench 的 sbtest 表

    测试场景配置

    单路由配置

    1. schemaName: sharding_db
    2. dataSources:
    3. ds_0:
    4. url: jdbc:mysql://***.***.***.***:****/ds?serverTimezone=UTC&useSSL=false
    5. username: test
    6. password:
    7. connectionTimeoutMilliseconds: 30000
    8. idleTimeoutMilliseconds: 60000
    9. maxLifetimeMilliseconds: 1800000
    10. maxPoolSize: 200
    11. ds_1:
    12. url: jdbc:mysql://***.***.***.***:****/ds?serverTimezone=UTC&useSSL=false
    13. username: test
    14. password:
    15. connectionTimeoutMilliseconds: 30000
    16. idleTimeoutMilliseconds: 60000
    17. maxLifetimeMilliseconds: 1800000
    18. maxPoolSize: 200
    19. ds_2:
    20. url: jdbc:mysql://***.***.***.***:****/ds?serverTimezone=UTC&useSSL=false
    21. username: test
    22. password:
    23. connectionTimeoutMilliseconds: 30000
    24. idleTimeoutMilliseconds: 60000
    25. maxLifetimeMilliseconds: 1800000
    26. maxPoolSize: 200
    27. ds_3:
    28. url: jdbc:mysql://***.***.***.***:****/ds?serverTimezone=UTC&useSSL=false
    29. username: test
    30. password:
    31. connectionTimeoutMilliseconds: 30000
    32. idleTimeoutMilliseconds: 60000
    33. maxLifetimeMilliseconds: 1800000
    34. maxPoolSize: 200
    35. - !SHARDING
    36. tables:
    37. tbl:
    38. actualDataNodes: ds_${0..3}.tbl${0..1023}
    39. tableStrategy:
    40. standard:
    41. shardingColumn: k
    42. shardingAlgorithmName: tbl_table_inline
    43. keyGenerateStrategy:
    44. column: id
    45. keyGeneratorName: snowflake
    46. defaultDatabaseStrategy:
    47. standard:
    48. shardingColumn: id
    49. shardingAlgorithmName: default_db_inline
    50. defaultTableStrategy:
    51. none:
    52. shardingAlgorithms:
    53. type: INLINE
    54. props:
    55. algorithm-expression: tbl${k % 1024}
    56. default_db_inline:
    57. type: INLINE
    58. props:
    59. algorithm-expression: ds_${id % 4}
    60. keyGenerators:
    61. snowflake:
    62. type: SNOWFLAKE
    63. props:
    64. worker-id: 123

    主从配置

    1. schemaName: sharding_db
    2. dataSources:
    3. primary_ds:
    4. url: jdbc:mysql://***.***.***.***:****/ds?serverTimezone=UTC&useSSL=false
    5. username: test
    6. password:
    7. connectionTimeoutMilliseconds: 30000
    8. idleTimeoutMilliseconds: 60000
    9. maxLifetimeMilliseconds: 1800000
    10. maxPoolSize: 200
    11. replica_ds_0:
    12. url: jdbc:mysql://***.***.***.***:****/ds?serverTimezone=UTC&useSSL=false
    13. username: test
    14. password:
    15. connectionTimeoutMilliseconds: 30000
    16. idleTimeoutMilliseconds: 60000
    17. maxLifetimeMilliseconds: 1800000
    18. maxPoolSize: 200
    19. rules:
    20. - !READWRITE_SPLITTING
    21. dataSources:
    22. pr_ds:
    23. writeDataSourceName: primary_ds
    24. readDataSourceNames:
    25. - replica_ds_0

    主从+加密+分库分表配置

    全路由

    1. schemaName: sharding_db
    2. dataSources:
    3. ds_0:
    4. url: jdbc:mysql://***.***.***.***:****/ds?serverTimezone=UTC&useSSL=false
    5. username: test
    6. password:
    7. connectionTimeoutMilliseconds: 30000
    8. idleTimeoutMilliseconds: 60000
    9. maxLifetimeMilliseconds: 1800000
    10. maxPoolSize: 200
    11. ds_1:
    12. url: jdbc:mysql://***.***.***.***:****/ds?serverTimezone=UTC&useSSL=false
    13. username: test
    14. connectionTimeoutMilliseconds: 30000
    15. idleTimeoutMilliseconds: 60000
    16. maxLifetimeMilliseconds: 1800000
    17. maxPoolSize: 200
    18. ds_2:
    19. url: jdbc:mysql://***.***.***.***:****/ds?serverTimezone=UTC&useSSL=false
    20. username: test
    21. password:
    22. idleTimeoutMilliseconds: 60000
    23. maxLifetimeMilliseconds: 1800000
    24. maxPoolSize: 200
    25. ds_3:
    26. url: jdbc:mysql://***.***.***.***:****/ds?serverTimezone=UTC&useSSL=false
    27. username: test
    28. password:
    29. connectionTimeoutMilliseconds: 30000
    30. idleTimeoutMilliseconds: 60000
    31. maxLifetimeMilliseconds: 1800000
    32. maxPoolSize: 200
    33. rules:
    34. - !SHARDING
    35. tables:
    36. tbl:
    37. actualDataNodes: ds_${0..3}.tbl1
    38. tableStrategy:
    39. standard:
    40. shardingColumn: k
    41. shardingAlgorithmName: tbl_table_inline
    42. keyGenerateStrategy:
    43. column: id
    44. keyGeneratorName: snowflake
    45. defaultDatabaseStrategy:
    46. standard:
    47. shardingColumn: id
    48. shardingAlgorithmName: default_database_inline
    49. defaultTableStrategy:
    50. none:
    51. shardingAlgorithms:
    52. default_database_inline:
    53. type: INLINE
    54. props:
    55. algorithm-expression: ds_${id % 4}
    56. tbl_table_inline:
    57. type: INLINE
    58. props:
    59. algorithm-expression: tbl1
    60. keyGenerators:
    61. snowflake:
    62. type: SNOWFLAKE
    63. props:
    64. worker-id: 123

    压测语句

    1. INSERT+UPDATE+DELETE语句:
    2. INSERT INTO tbl(k, c, pad) VALUES(1, '###-###-###', '###-###');
    3. UPDATE tbl SET c='####-####-####', pad='####-####' WHERE id=?;
    4. DELETE FROM tbl WHERE id=?
    5. 全路由查询语句:
    6. SELECT max(id) FROM tbl WHERE id%4=1
    7. 单路由查询语句:
    8. SELECT id, k FROM tbl ignore index(`PRIMARY`) WHERE id=1 AND k=1
    9. INSERT+SELECT+DELETE语句:
    10. INSERT INTO tbl1(k, c, pad) VALUES(1, '###-###-###', '###-###');
    11. SELECT count(id) FROM tbl1;
    12. SELECT max(id) FROM tbl1 ignore index(`PRIMARY`);
    13. DELETE FROM tbl1 WHERE id=?

    压测类

    参考shardingsphere-benchmark实现,注意阅读其中的注释

    压测执行

    1. cp target/shardingsphere-benchmark-1.0-SNAPSHOT-jar-with-dependencies.jar apache-jmeter-4.0/lib/ext
    2. jmeter n t test_plan/test.jmx

    压测结果处理

    注意修改为上一步生成的result.jtl的位置。

      历史压测数据展示