Performance Tuning in Version 6.0: Questions about JDBC Connection Parameters

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: v6.0版本性能调优之JDBC连接参数疑问

| username: TiDBer_yyy

In the Summary section, it is recommended to configure JDBC as follows:

  • TiDB is compatible with different MySQL protocol commands. The best performance comes from the application using the Prepared Statement interface and setting the following JDBC connection parameters:
useServerPrepStmts=true&cachePrepStmts=true&prepStmtCacheSize=1000&prepStmtCacheSqlLimit=20480&useConfigs=maxPerformance

Questions:

  1. Is the JDBC here specifically referring to Java code?
  2. Are the above parameters applicable to configurations developed in the Go language? If not, how should similar parameters be configured?
  3. Are there similar JDBC parameter recommendations for TiDB version 5.0 (excluding new features of version 6.0)?
| username: dbsid | Original post link

  1. Is the JDBC here specifically referring to Java code?

Specifically referring to Java code.

  1. Does the configuration developed in Golang apply to the above parameters? If not, how should similar parameters be configured?

Golang’s MySQL driver does not support automatic caching of prepared statement objects. The Go program code needs to implement this itself. Here is an example, which roughly requires the client to maintain a secondary map. The secondary keys are the connection id and query text, and the value is the already parsed prepared statement object.

func (s *bankState) refreshConn(ctx context.Context) error {
	conn, err := s.db.Conn(ctx)
	if err != nil {
		return err
	}
	s.conn = conn
	s.stmtCache = make(map[string]*sql.Stmt)
	return nil
}

func getBankState(ctx context.Context) *bankState {
	return ctx.Value(bankStateKey).(*bankState)
}

func (d *Driver) getAndCacheStmt(ctx context.Context, query string) (*sql.Stmt, error) {
	state := getBankState(ctx)

	if stmt, ok := state.stmtCache[query]; ok {
		return stmt, nil
	}
	stmt, err := state.conn.PrepareContext(ctx, query)
	if err != nil {
		return nil, err
	}
	state.stmtCache[query] = stmt
	return stmt, nil
}
  1. Are there similar JDBC parameter recommendations for TiDB version 5.0 (excluding the new features of version 6.0)?

JDBC parameters have been recommended for use since v5.4.0 when the prepared-plan-cache became GA.

| username: HACK | Original post link

:+1:

| username: TiDBer_yyy | Original post link

:+1::+1::+1:

| username: cs58_dba | Original post link

Java connections are generally more common.

| username: system | Original post link

This topic was automatically closed 1 minute after the last reply. No new replies are allowed.