JiekerTime opened a new issue #11341: URL: https://github.com/apache/shardingsphere/issues/11341
### Which version of ShardingSphere did you use? 5.0.0-RC1-SNAPSHOT ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy? ShardingSphere-JDBC ### Expected behavior Number of database related connections is 20: MySQL:  PG:  ### Actual behavior Number of database related connections is 30:  PG:  ### Reason analyze (If you can) There is a problem with the processing of the number of connections in SS. ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc. **Use HikariConfig as the connection pool and set MaximumPoolSize to 2.** Execute the following code review: PG: public DataSource getDataSource(String db, Integer id) { HikariConfig config = new HikariConfig(); config.setUsername("root"); config.setPassword("root"); config.setDriverClassName("org.postgresql.Driver"); config.setJdbcUrl("jdbc:postgresql://127.0.0.1:5432/" + db + "?ApplicationName=hikari-" + id); config.setMaximumPoolSize(2); config.setTransactionIsolation("TRANSACTION_READ_COMMITTED"); return new HikariDataSource(config); } public Runnable getThread(int i) { return () -> { DataSource dataSource = getDataSource("db_" + i, i); for (int j = 0; j < 100; j++) { try (Connection connection = dataSource.getConnection()) { System.out.println(connection.getClientInfo()); Thread.sleep(100); } catch (SQLException | InterruptedException ignored) { } } }; } public Runnable getThread(DataSource dataSource) { return () -> { for (int j = 0; j < 100; j++) { try (Connection connection = dataSource.getConnection()) { System.out.println(connection.getClientInfo()); Thread.sleep(100); } catch (SQLException | InterruptedException ignored) { } } }; } public Runnable getThread(DataSource dataSource, String name) { return () -> { try (Connection connection = dataSource.getConnection()) { System.out.println(connection.createStatement().execute("SELECT 1")); Thread.sleep(100); } catch (SQLException | InterruptedException ignored) { } }; } @Test public void commonConnectionTest() throws InterruptedException { for (int i = 0; i < 10; i++) { new Thread(getThread(i)).start(); } Thread.sleep(100000); } @Test public void natureConnectionTest() throws InterruptedException, SQLException { Map<String, DataSource> dataSourceMap = new HashMap<String, DataSource>() { { put("db_0", getDataSource("db_0", 0)); put("db_1", getDataSource("db_1", 1)); put("db_2", getDataSource("db_2", 2)); put("db_3", getDataSource("db_3", 3)); put("db_4", getDataSource("db_4", 4)); put("db_5", getDataSource("db_5", 5)); put("db_6", getDataSource("db_6", 6)); put("db_7", getDataSource("db_7", 7)); put("db_8", getDataSource("db_8", 8)); put("db_9", getDataSource("db_9", 9)); } }; for (String key : dataSourceMap.keySet()) { new Thread(getThread(dataSourceMap.get(key))).start(); } Thread.sleep(100000); } @Test public void ssConnectionTest() throws InterruptedException, IOException, SQLException { Map<String, DataSource> dataSourceMap = new HashMap<String, DataSource>() { { put("db_0", getDataSource("db_0", 0)); put("db_1", getDataSource("db_1", 1)); put("db_2", getDataSource("db_2", 2)); put("db_3", getDataSource("db_3", 3)); put("db_4", getDataSource("db_4", 4)); put("db_5", getDataSource("db_5", 5)); put("db_6", getDataSource("db_6", 6)); put("db_7", getDataSource("db_7", 7)); put("db_8", getDataSource("db_8", 8)); put("db_9", getDataSource("db_9", 9)); } }; DataSource dataSource = YamlShardingSphereDataSourceFactory.createDataSource(dataSourceMap, new File("E:\\ideaproject\\procject_for_test\\shardingsphere\\src\\test\\resources\\sharding-databases.yaml")); for (int i = 0; i < 100; i++) { new Thread(getThread(dataSource, "thread-1"), "thread-1").start(); } System.out.println("finished!---------------"); Thread.sleep(100000); } MySQL: public DataSource getDataSource(String db, Integer id) { HikariConfig config = new HikariConfig(); config.setUsername("root"); config.setPassword("123456"); config.setDriverClassName("com.mysql.jdbc.Driver"); config.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/" + db + "?useServerPrepStmts=true&serverTimezone=UTC&useSSL=false&useLocalSessionState=true&characterEncoding=utf-8"); config.setMaximumPoolSize(2); config.setTransactionIsolation("TRANSACTION_READ_COMMITTED"); return new HikariDataSource(config); } public Runnable getThread(int i) { return () -> { DataSource dataSource = getDataSource("db_" + i, i); for (int j = 0; j < 100; j++) { try (Connection connection = dataSource.getConnection()) { System.out.println(connection.getClientInfo()); Thread.sleep(100); } catch (SQLException | InterruptedException ignored) { } } }; } public Runnable getThread(DataSource dataSource) { return () -> { for (int j = 0; j < 100; j++) { try (Connection connection = dataSource.getConnection()) { System.out.println(connection.getClientInfo()); Thread.sleep(100); } catch (SQLException | InterruptedException ignored) { } } }; } public Runnable getThread(DataSource dataSource, String name) { return () -> { try (Connection connection = dataSource.getConnection()) { System.out.println(connection.createStatement().execute("SELECT 1")); Thread.sleep(100); } catch (SQLException | InterruptedException ignored) { ignored.printStackTrace(); } }; } @Test public void commonConnectionTest() throws InterruptedException { for (int i = 0; i < 10; i++) { new Thread(getThread(i)).start(); } Thread.sleep(100000); } @Test public void ssSplitConnectionTest() throws InterruptedException, IOException, SQLException { Map<String, DataSource> dataSourceMap = new HashMap<String, DataSource>() { { put("db_0", getDataSource("db_0", 0)); put("db_1", getDataSource("db_1", 1)); put("db_2", getDataSource("db_2", 2)); put("db_3", getDataSource("db_3", 3)); put("db_4", getDataSource("db_4", 4)); put("db_5", getDataSource("db_5", 5)); put("db_6", getDataSource("db_6", 6)); put("db_7", getDataSource("db_7", 7)); put("db_8", getDataSource("db_8", 8)); put("db_9", getDataSource("db_9", 9)); } }; for (String key : dataSourceMap.keySet()) { new Thread(getThread(dataSourceMap.get(key))).start(); } Thread.sleep(100000); } @Test public void ssConnectionTest() throws InterruptedException, IOException, SQLException { Map<String, DataSource> dataSourceMap = new HashMap<String, DataSource>() { { put("db_0", getDataSource("db_0", 0)); put("db_1", getDataSource("db_1", 1)); put("db_2", getDataSource("db_2", 2)); put("db_3", getDataSource("db_3", 3)); put("db_4", getDataSource("db_4", 4)); put("db_5", getDataSource("db_5", 5)); put("db_6", getDataSource("db_6", 6)); put("db_7", getDataSource("db_7", 7)); put("db_8", getDataSource("db_8", 8)); put("db_9", getDataSource("db_9", 9)); } }; DataSource dataSource = YamlShardingSphereDataSourceFactory.createDataSource(dataSourceMap, new File("E:\\ideaproject\\procject_for_test\\shardingsphere\\src\\test\\resources\\sharding-databases.yaml")); for (int i = 0; i < 100; i++) { new Thread(getThread(dataSource, "thread-1"), "thread-1").start(); } System.out.println("finished!---------------"); Thread.sleep(100000); } -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
