Project: ShardingSphere (App Definition and Development / Database)
File: benchmarksql-proxy-sharding-test.en.md

+++ title = "BenchmarkSQL ShardingSphere-Proxy Sharding Performance Test" weight = 2 +++ BenchmarkSQL tool is used to test the sharding performance of ShardingSphere-Proxy. ShardingSphere-Proxy supports the TPC-C test through . In addition to the content described in this document, BenchmarkSQL is operated according to the original document `HOW-TO-RUN.txt`. Unlike stand-alone database stress testing, distributed database solutions inevitably face trade-offs in functions. It is recommended to make the following adjustments when using BenchmarkSQL to carry out stress testing on ShardingSphere-Proxy. Modify `run/runDatabaseBuild.sh` in the BenchmarkSQL directory at line 17. Before modification: ```bash AFTER_LOAD="indexCreates foreignKeys extraHistID buildFinish" ``` After modification: ```bash AFTER_LOAD="indexCreates buildFinish" ``` Note: None of the parameters mentioned in this section are absolute values and need to be adjusted based on actual test results. ShardingSphere can be compiled using Java 8. When using Java 17, maximize the ShardingSphere performance by default. The data sharding of BenchmarkSQL can use the warehouse id in each table as the sharding key. One of the tables `bmsql_item` has no warehouse id and has a fixed data volume of 100,000 rows: You can take `i_id` as a sharding key. However, the same Proxy connection may hold connections to multiple different data sources at the same time. Or you can give up sharding and store it in a single data source. But a data source may be under great pressure. Or you may choose range-based sharding for `i_id`, such as 1-50000 for data source 0 and 50001-100000 for data source 1. BenchmarkSQL has the following SQL involving multiple tables: ```sql SELECT cdiscount, clast, ccredit, wtax FROM bmsql_customer JOIN bmsqlwarehouse ON (wid = cwid) WHERE cwid = ? AND cdid = ? AND c_id = ? ``` ```sql SELECT oid, oentryd, ocarrier_id FROM bmsql_oorder WHERE owid = ? AND odid = ? AND ocid = ? AND o_id = ( SELECT max(o_id) FROM bmsql_oorder WHERE owid = ? AND odid = ? AND ocid = ? ) ``` If the warehouse id is used as the sharding key, the tables involved in the above SQL can be configured as bindingTable: ```yaml rules: !SHARDING bindingTables: bmsqlwarehouse, bmsqlcustomer bmsqlstock, bmsqldistrict, bmsqlorderline ``` For the data sharding configuration with warehouse id as the sharding key, refer to the appendix of this document. Adjust the JDBC URL in the configuration file used by BenchmarkSQL, that is, the value of the parameter name `conn`: Adding the parameter `defaultRowFetchSize=50` may reduce the number of fetch for multi-row result sets. You need to increase or decrease the number according to actual test results. Adding the parameter `reWriteBatchedInserts=true` may reduce the time spent on bulk inserts, such as preparing data or bulk inserts for the New Order business. Whether to enable the operation depends on actual test results. props.pg file excerpt. It is suggested to change the parameter value of `conn` in line

```properties db=postgres driver=org.postgresql.Driver conn=jdbc:postgresql://localhost:5432/postgres?defaultRowFetchSize=50&reWriteBatchedInserts=true user=benchmarksql password=PWbmsql ``` The default value of `proxy-backend-query-fetch-size` is -1. Changing it to about `50` can minimize the number of fetch for multi-row result sets. The default value of `proxy-frontend-executor-size` is CPU 2 and can be reduced to about CPU 0.5 based on actual test results. If NUMA is involved, set this parameter to the number of physical cores per CPU based on actual test results. `global.yaml` file excerpt: ```yaml props: proxy-backend-query-fetch-size: 50 ``` Adjust pool size according to the actual stress testing process. ```yaml databaseName: bmsql_sharding dataSources: ds_0: url: jdbc:postgresql://db0.ip:5432/bmsql username: postgres password: postgres connectionTimeoutMilliseconds: 3000 idleTimeoutMilliseconds: 60000 maxLifetimeMilliseconds: 1800000 maxPoolSize: 1000 minPoolSize: 1000 ds_1: url: jdbc:postgresql://db1.ip:5432/bmsql username: postgres password: postgres connectionTimeoutMilliseconds: 3000 idleTimeoutMilliseconds: 60000 maxLifetimeMilliseconds: 1800000 maxPoolSize: 1000 minPoolSize: 1000 ds_2: url: jdbc:postgresql://db2.ip:5432/bmsql username: postgres password: postgres connectionTimeoutMilliseconds: 3000 idleTimeoutMilliseconds: 60000 maxLifetimeMilliseconds: 1800000 maxPoolSize: 1000 minPoolSize: 1000 ds_3: url: jdbc:postgresql://db3.ip:5432/bmsql username: postgres password: postgres connectionTimeoutMilliseconds: 3000 idleTimeoutMilliseconds: 60000 maxLifetimeMilliseconds: 1800000 maxPoolSize: 1000 minPoolSize: 1000 rules: !SHARDING bindingTables: bmsqlwarehouse, bmsqlcustomer bmsqlstock, bmsqldistrict, bmsqlorderline defaultDatabaseStrategy: none: defaultTableStrategy: none: keyGenerators: snowflake: type: SNOWFLAKE tables: bmsql_config: actualDataNodes: ds0.bmsqlconfig bmsql_warehouse: actualDataNodes: ds${0..3}.bmsqlwarehouse databaseStrategy: standard: shardingColumn: w_id shardingAlgorithmName: mod_4 bmsql_district: actualDataNodes: ds${0..3}.bmsqldistrict databaseStrategy: standard: shardingColumn: dwid shardingAlgorithmName: mod_4 bmsql_customer: actualDataNodes: ds${0..3}.bmsqlcustomer databaseStrategy: standard: shardingColumn: cwid shardingAlgorithmName: mod_4 bmsql_item: actualDataNodes: ds${0..3}.bmsqlitem databaseStrategy: standard: shardingColumn: i_id shardingAlgorithmName: mod_4 bmsql_history: actualDataNodes: ds${0..3}.bmsqlhistory databaseStrategy: standard: shardingColumn: hwid shardingAlgorithmName: mod_4 bmsql_oorder: actualDataNodes: ds${0..3}.bmsqloorder databaseStrategy: standard: shardingColumn: owid shardingAlgorithmName: mod_4 bmsql_stock: actualDataNodes: ds${0..3}.bmsqlstock databaseStrategy: standard: shardingColumn: swid shardingAlgorithmName: mod_4 bmsqlneworder: actualDataNodes: ds${0..3}.bmsqlnew_order databaseStrategy: standard: shardingColumn: nowid shardingAlgorithmName: mod_4 bmsqlorderline: actualDataNodes:

databaseStrategy: standard: shardingColumn: olwid shardingAlgorithmName: mod_4 shardingAlgorithms: mod_4: type: MOD props: sharding-count: 4 ``` ```sql create table bmsql_config ( cfg_name varchar(30) primary key, cfg_value varchar(50) ); create table bmsql_warehouse ( w_id integer not null, w_ytd decimal(12,2), w_tax decimal(4,4), w_name varchar(10), wstreet1 varchar(20), wstreet2 varchar(20), w_city varchar(20), w_state char(2), w_zip char(9) ); create table bmsql_district ( dwid integer not null, d_id integer not null, d_ytd decimal(12,2), d_tax decimal(4,4), dnexto_id integer, d_name varchar(10), dstreet1 varchar(20), dstreet2 varchar(20), d_city varchar(20), d_state char(2), d_zip char(9) ); create table bmsql_customer ( cwid integer not null, cdid integer not null, c_id integer not null, c_discount decimal(4,4), c_credit char(2), c_last varchar(16), c_first varchar(16), ccreditlim decimal(12,2), c_balance decimal(12,2), cytdpayment decimal(12,2), cpaymentcnt integer, cdeliverycnt integer, cstreet1 varchar(20), cstreet2 varchar(20), c_city varchar(20), c_state char(2), c_zip char(9), c_phone char(16), c_since timestamp, c_middle char(2), c_data varchar(500) ); create sequence bmsqlhistid_seq; create table bmsql_history ( hist_id integer, hcid integer, hcd_id integer, hcw_id integer, hdid integer, hwid integer, h_date timestamp, h_amount decimal(6,2), h_data varchar(24) ); create table bmsqlneworder ( nowid integer not null, nodid integer not null, nooid integer not null ); create table bmsql_oorder ( owid integer not null, odid integer not null, o_id integer not null, ocid integer, ocarrierid integer, oolcnt integer, oalllocal integer, oentryd timestamp ); create table bmsqlorderline ( olwid integer not null, oldid integer not null, oloid integer not null, ol_number integer not null, oliid integer not null, oldeliveryd timestamp, ol_amount decimal(6,2), olsupplyw_id integer, ol_quantity integer, oldistinfo char(24) ); create table bmsql_item ( i_id integer not null, i_name varchar(24), i_price decimal(5,2), i_data varchar(50), iimid integer ); create table bmsql_stock ( swid integer not null, siid integer not null, s_quantity integer, s_ytd integer, sordercnt integer, sremotecnt integer, s_data varchar(50), sdist01 char(24), sdist02 char(24), sdist03 char(24), sdist04 char(24), sdist05 char(24), sdist06 char(24), sdist07 char(24), sdist08 char(24), sdist09 char(24), sdist10 char(24) ); ``` ```sql alter table bmsqlwarehouse add constraint bmsqlwarehouse_pkey primary key (w_id); alter table bmsqldistrict add constraint bmsqldistrict_pkey primary key (dwid, d_id); alter table bmsqlcustomer add constraint bmsqlcustomer_pkey primary key (cwid, cdid, c_id); create index bmsqlcustomeridx1 on bmsqlcustomer (cwid, cdid, clast, c_first); alter table bmsqloorder add constraint bmsqloorder_pkey primary key (owid, odid, o_id); create unique index bmsqloorderidx1 on bmsqloorder (owid, odid, ocarrierid, oid); alter table bmsqlneworder add constraint bmsqlneworder_pkey primary key (nowid, nodid, nooid); alter table bmsqlorderline add constraint bmsqlorderline_pkey primary key (olwid, oldid, oloid, ol_number); alter table bmsqlstock add constraint bmsqlstock_pkey primary key (swid, siid); alter table bmsqlitem add constraint bmsqlitem_pkey primary key (i_id); ``` stmtNewOrderSelectWhseCust ```sql UPDATE bmsql_district SET dnextoid = dnextoid + 1 WHERE dwid = ? AND d_id = ? ``` stmtNewOrderSelectDist ```sql SELECT dtax, dnextoid FROM bmsql_district WHERE dwid = ? AND d_id = ? FOR UPDATE ``` stmtNewOrderUpdateDist ```sql UPDATE bmsql_district SET dnextoid = dnextoid + 1 WHERE dwid = ? AND d_id = ? ``` stmtNewOrderInsertOrder ```sql INSERT INTO bmsql_oorder ( oid, odid, owid, ocid, oentry_d, oolcnt, oalllocal) VALUES (?, ?, ?, ?, ?, ?, ?) ``` stmtNewOrderInsertNewOrder ```sql INSERT INTO bmsqlneworder ( nooid, nodid, nowid) VALUES (?, ?, ?) ``` stmtNewOrderSelectStock ```sql SELECT squantity, sdata, sdist01, sdist02, sdist03, sdist04, sdist05, sdist06, sdist07, sdist08, sdist09, sdist10 FROM bmsql_stock WHERE swid = ? AND siid = ? FOR UPDATE ``` stmtNewOrderSelectItem ```sql SELECT iprice, iname, i_data FROM bmsql_item WHERE i_id = ? ``` stmtNewOrderUpdateStock ```sql UPDATE bmsql_stock SET squantity = ?, sytd = s_ytd + ?, sordercnt = sordercnt + 1, sremotecnt = sremotecnt + ? WHERE swid = ? AND siid = ? ``` stmtNewOrderInsertOrderLine ```sql INSERT INTO bmsqlorderline ( oloid, oldid, olwid, ol_number, oliid, olsupplywid, olquantity, olamount, oldist_info) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ``` stmtPaymentSelectWarehouse ```sql SELECT wname,