Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【需求】支持mariadb驱动选项的batchMultiSend=true #2542

Closed
funnyAnt opened this issue Jul 7, 2020 · 1 comment
Closed

【需求】支持mariadb驱动选项的batchMultiSend=true #2542

funnyAnt opened this issue Jul 7, 2020 · 1 comment

Comments

@funnyAnt
Copy link
Collaborator

funnyAnt commented Jul 7, 2020

需求来源

mariadb驱动batchMultiSend参数默认值为true,该参数官方解释是:

从1.5.0开始,“ useBatchMultiSend”选项允许按批发送查询。
如果禁用,查询将一一发送,等待结果再发送下一个。
如果启用,查询将按与useBatchMultiSendNumber选项的值(默认为100)相对应的批次发送。一段时间后将读取结果,避免了客户端和服务器不在同一主机上时的大量网络延迟。具体参考https://mariadb.com/kb/en/option-batchmultisend-description/

但是mycat不支持一次性处理多个sql报文,必现一个一个处理。

方案

为了支持该需求,设计如下:

  • 1)接收到一个报文后,去除网络IO 读事件。
  • 2)处理完报文后,恢复网络IO读事件,继续处理一个报文

缺陷

该方案仅仅是语法上面支持batchMultiSend=true,并没有达到因为使用batchMultiSend性能变快的效果。

@funnyAnt
Copy link
Collaborator Author

private static void testMariadbBatchUpdate() {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;

		try {
			Class.forName("org.mariadb.jdbc.Driver");
			conn = DriverManager.getConnection(
					"jdbc:mariadb://127.0.0.1:8066/TESTDB?rewriteBatchedStatements=false&useBatchMultiSend=true&user=root&password=123");

			pstmt = conn.prepareStatement("update customer set name=? where id=?");
			long time = System.currentTimeMillis();
			for (int i = 0; i < 50; i++) {
				pstmt.setString(1, String.valueOf(i));
				pstmt.setString(2, String.valueOf(i * 2));
				pstmt.addBatch();
			}
			pstmt.executeBatch();

			System.out.println("batch update end" + (System.currentTimeMillis() - time));

			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

测试代码如上。

性能对比测试:

因为目前采取的是伪支持方式,batchMultiSend为true 对比false时性能相当。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant