Performance Test with Sysbench

Target

The performance of ShardingSphere-JDBC, ShardingSphere-Proxy and MySQL would be compared here. INSERT & UPDATE & DELETE which regarded as a set of associated operation and SELECT which focus on sharding optimization are used to evaluate performance for the basic scenarios (single route, readwrite-splitting & encrypt & sharding, full route). While another set of associated operation, INSERT & SELECT & DELETE, is used to evaluate performance for readwrite-splitting. To achieve the result better, these tests are performed with jmeter which based on a certain amount of data with 20 concurrent threads for 30 minutes, and one MySQL has been deployed on one machine, while the scenario of MySQL used for comparison is deployed on one machine with one instance.

Test Scenarios

Single Route

On the basis of one thousand data volume, four databases that are deployed on the same machine and each contains 1024 tables with id used for database sharding and k used for table sharding are designed for this scenario, single route select sql statement is chosen here. While as a comparison, MySQL runs with INSERT & UPDATE & DELETE statement and single route select sql statement on the basis of one thousand data volume.

Readwrite-splitting

One primary database and one replica database, which are deployed on different machines, are designed for this scenario based on ten thousand data volume. While as a comparison, MySQL runs with INSERT & SELECT & DELETE sql statement on the basis of ten thousand data volume.

Readwrite-splitting & Encrypt & Sharding

On the basis of one thousand data volume, four databases that are deployed on different machines and each contains 1024 tables with id used for database sharding, k used for table sharding, c encrypted with aes and pad encrypted with md5 are designed for this scenario, single route select sql statement is chosen here. While as a comparison, MySQL runs with INSERT & UPDATE & DELETE statement and single route select sql statement on the basis of one thousand data volume.

Full Route

On the basis of one thousand data volume, four databases that are deployed on different machines and each contains one table are designed for this scenario, field id is used for database sharding and k is used for table sharding, full route select sql statement is chosen here. While as a comparison, MySQL runs with INSERT & UPDATE & DELETE statement and full route select sql statement on the basis of one thousand data volume.

Testing Environment

Table Structure of Database

The structure of table here refer to sbtest in sysbench

  1. CREATE TABLE `tbl` (
  2. `id` bigint(20) NOT NULL AUTO_INCREMENT,
  3. `k` int(11) NOT NULL DEFAULT 0,
  4. `c` char(120) NOT NULL DEFAULT '',
  5. `pad` char(60) NOT NULL DEFAULT '',
  6. PRIMARY KEY (`id`)
  7. );

Test Scenarios Configuration

The same configurations are used for ShardingSphere-JDBC and ShardingSphere-Proxy, while MySQL with one database connected is designed for comparision. The details for these scenarios are shown as follows.

Single Route Configuration

  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. rules:
  36. - !SHARDING
  37. tables:
  38. tbl:
  39. actualDataNodes: ds_${0..3}.tbl${0..1023}
  40. tableStrategy:
  41. standard:
  42. shardingColumn: k
  43. shardingAlgorithmName: tbl_table_inline
  44. keyGenerateStrategy:
  45. column: id
  46. keyGeneratorName: snowflake
  47. defaultDatabaseStrategy:
  48. inline:
  49. shardingColumn: id
  50. shardingAlgorithmName: default_db_inline
  51. defaultTableStrategy:
  52. none:
  53. shardingAlgorithms:
  54. tbl_table_inline:
  55. type: INLINE
  56. props:
  57. algorithm-expression: tbl${k % 1024}
  58. default_db_inline:
  59. type: INLINE
  60. props:
  61. algorithm-expression: ds_${id % 4}
  62. keyGenerators:
  63. snowflake:
  64. type: SNOWFLAKE
  65. props:
  66. worker-id: 123

Readwrite-splitting Configuration

  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

Readwrite-splitting & Encrypt & Sharding Configuration

  1. schemaName: sharding_db
  2. dataSources:
  3. primary_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. 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. primary_ds_1:
  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. replica_ds_1:
  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. primary_ds_2:
  36. url: jdbc:mysql://***.***.***.***:****/ds?serverTimezone=UTC&useSSL=false
  37. username: test
  38. password:
  39. connectionTimeoutMilliseconds: 30000
  40. idleTimeoutMilliseconds: 60000
  41. maxLifetimeMilliseconds: 1800000
  42. maxPoolSize: 200
  43. replica_ds_2:
  44. url: jdbc:mysql://***.***.***.***:****/ds?serverTimezone=UTC&useSSL=false
  45. username: test
  46. password:
  47. connectionTimeoutMilliseconds: 30000
  48. idleTimeoutMilliseconds: 60000
  49. maxLifetimeMilliseconds: 1800000
  50. maxPoolSize: 200
  51. primary_ds_3:
  52. url: jdbc:mysql://***.***.***.***:****/ds?serverTimezone=UTC&useSSL=false
  53. username: test
  54. password:
  55. connectionTimeoutMilliseconds: 30000
  56. idleTimeoutMilliseconds: 60000
  57. maxLifetimeMilliseconds: 1800000
  58. maxPoolSize: 200
  59. replica_ds_3:
  60. url: jdbc:mysql://***.***.***.***:****/ds?serverTimezone=UTC&useSSL=false
  61. username: test
  62. password:
  63. connectionTimeoutMilliseconds: 30000
  64. idleTimeoutMilliseconds: 60000
  65. maxLifetimeMilliseconds: 1800000
  66. maxPoolSize: 200
  67. rules:
  68. - !SHARDING
  69. tables:
  70. tbl:
  71. actualDataNodes: pr_ds_${0..3}.tbl${0..1023}
  72. databaseStrategy:
  73. standard:
  74. shardingColumn: id
  75. shardingAlgorithmName: tbl_database_inline
  76. tableStrategy:
  77. standard:
  78. shardingColumn: k
  79. shardingAlgorithmName: tbl_table_inline
  80. keyGenerateStrategy:
  81. column: id
  82. keyGeneratorName: snowflake
  83. bindingTables:
  84. - tbl
  85. defaultDataSourceName: primary_ds_1
  86. defaultTableStrategy:
  87. none:
  88. shardingAlgorithms:
  89. tbl_database_inline:
  90. type: INLINE
  91. props:
  92. algorithm-expression: pr_ds_${id % 4}
  93. tbl_table_inline:
  94. type: INLINE
  95. props:
  96. algorithm-expression: tbl${k % 1024}
  97. keyGenerators:
  98. snowflake:
  99. type: SNOWFLAKE
  100. props:
  101. worker-id: 123
  102. - !READWRITE_SPLITTING
  103. dataSources:
  104. pr_ds_0:
  105. writeDataSourceName: primary_ds_0
  106. readDataSourceNames:
  107. - replica_ds_0
  108. loadBalancerName: round_robin
  109. pr_ds_1:
  110. writeDataSourceName: primary_ds_1
  111. readDataSourceNames:
  112. - replica_ds_1
  113. loadBalancerName: round_robin
  114. pr_ds_2:
  115. writeDataSourceName: primary_ds_2
  116. readDataSourceNames:
  117. - replica_ds_2
  118. loadBalancerName: round_robin
  119. pr_ds_3:
  120. writeDataSourceName: primary_ds_3
  121. readDataSourceNames:
  122. - replica_ds_3
  123. loadBalancerName: round_robin
  124. loadBalancers:
  125. round_robin:
  126. type: ROUND_ROBIN
  127. - !ENCRYPT:
  128. encryptors:
  129. aes_encryptor:
  130. type: AES
  131. props:
  132. aes-key-value: 123456abc
  133. md5_encryptor:
  134. type: MD5
  135. tables:
  136. sbtest:
  137. columns:
  138. c:
  139. plainColumn: c_plain
  140. cipherColumn: c_cipher
  141. encryptorName: aes_encryptor
  142. pad:
  143. cipherColumn: pad_cipher
  144. encryptorName: md5_encryptor

Full Route Configuration

  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. rules:
  36. - !SHARDING
  37. tables:
  38. tbl:
  39. actualDataNodes: ds_${0..3}.tbl1
  40. tableStrategy:
  41. standard:
  42. shardingColumn: k
  43. shardingAlgorithmName: tbl_table_inline
  44. keyGenerateStrategy:
  45. column: id
  46. keyGeneratorName: snowflake
  47. defaultDatabaseStrategy:
  48. standard:
  49. shardingColumn: id
  50. shardingAlgorithmName: default_database_inline
  51. defaultTableStrategy:
  52. none:
  53. shardingAlgorithms:
  54. default_database_inline:
  55. type: INLINE
  56. props:
  57. algorithm-expression: ds_${id % 4}
  58. tbl_table_inline:
  59. type: INLINE
  60. props:
  61. algorithm-expression: tbl1
  62. keyGenerators:
  63. snowflake:
  64. type: SNOWFLAKE
  65. props:
  66. worker-id: 123

Test Result Verification

SQL Statement

  1. INSERT+UPDATE+DELETE sql statements:
  2. INSERT INTO tbl(k, c, pad) VALUES(1, '###-###-###', '###-###');
  3. UPDATE tbl SET c='####-####-####', pad='####-####' WHERE id=?;
  4. DELETE FROM tbl WHERE id=?
  5. SELECT sql statement for full route:
  6. SELECT max(id) FROM tbl WHERE id%4=1
  7. SELECT sql statement for single route:
  8. SELECT id, k FROM tbl ignore index(`PRIMARY`) WHERE id=1 AND k=1
  9. INSERT+SELECT+DELETE sql statements
  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=?

Jmeter Class

Consider the implementation of shardingsphere-benchmark Notes: the notes in shardingsphere-benchmark/README.md should be taken attention to

Compile & Build

  1. git clone https://github.com/apache/shardingsphere-benchmark.git
  2. cd shardingsphere-benchmark/shardingsphere-benchmark
  3. mvn clean install

Perform Test

  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
  3. test.jmx example:https://github.com/apache/shardingsphere-benchmark/tree/master/report/script/test_plan/test.jmx

Process Result Data

Make sure the location of result.jtl file is correct.

  1. sh shardingsphere-benchmark/report/script/gen_report.sh

Display of Historical Performance Test Data

In progress, please wait.