TeslaCN commented on issue #24122:
URL: 
https://github.com/apache/shardingsphere/issues/24122#issuecomment-1429176268

   I have some idea about this issue.
   
   ## How to configure idle timeout in database
   
   The parameter corresponding to MySQL is `wait_timeout`
   
<https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_wait_timeout>
   
   The parameter corresponding to PostgreSQL is `idle_session_timeout`
   <https://www.postgresql.org/docs/current/runtime-config-client.html>
   
   But ShardingSphere-Proxy doesn't maintain global variables and session 
variables at present. So we may consider adding the idle timeout parameter in 
properties.
   
   ## API changes
   
   Add new prop:
   ```yaml
   props:
     proxy-frontend-connection-idle-timeout: 3600
   ```
   
   ### Idea about implementing idle timeout in ShardingSphere-Proxy
   
   Create a Handler for judging idle timeout and place it after 
`FrontendChannelInboundHandler`
   
   In terms of connection idle detection, Netty has provided relevant 
implementations:
   `io.netty.handler.timeout.IdleStateHandler` supports read/write idle timeout 
detection.
   We can create a new Handler which extends `IdleStateHandler` to handle idle 
timeout logic.
   
   
   ### How to distinguish real idle and I/O idle while executing long statement
   When executing `select sleep(20)` or other long statements, the I/O of the 
connection may be idle, but the connection is busy.
   
   Such as:
   ```sql
   set wait_timeout=10
   select sleep(20);
   ```
   
   At the ShardingSphere-Proxy level, consider judging whether 
`ConnectionSession.queryContext` is empty:
   - When `ConnectionSession.queryContext` is empty, it means that the 
connection has no executing statement;
   - When `ConnectionSession.queryContext` is not null, it means the connection 
is executing the statement.


-- 
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]

Reply via email to