[MDEV-31609] Send initial values of system variables in first OK packet Created: 2023-07-03 Updated: 2024-01-15 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Protocol |
| Fix Version/s: | 11.5 |
| Type: | New Feature | Priority: | Critical |
| Reporter: | markus makela | Assignee: | Yuchen Pei |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||
| Description |
|
Currently, all drivers that need to know the values of some system variables must obtain this information by doing a separate SELECT. This adds latency to the connection creation. The OK packet that's sent in response to successful authentication could contain initial values of the system variables that are tracked by session_track_system_variables. With this, drivers that support system variable tracking could read these values on startup and avoid the cost of the extra query. An extension to this would be to provide some information about the status of the server to the drivers. One example of this would be the Threads_connected status variable that could help drivers that have connection pools to spread the load better if one of the servers in a cluster ends up with more connections than the others. |
| Comments |
| Comment by Sergei Golubchik [ 2023-07-07 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
it would mean a lot of information in the first OK packet that most clients don't need. is it ok? will it be noticeable? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by markus makela [ 2023-07-07 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
One suggestion was to add a matching connection attribute that the client would first send (e.g. _send_system_variables=<list of variable names>) that the server would understand and only send the ones that are requested. This would also allow the feature to be decoupled from session_track_system_variables. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by markus makela [ 2023-07-07 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
If we assume that the information tracked with session_track_system_variables is important enough to track while a connection is alive, it should also be of use when the connection is first created. With this assumption, we can look at how many bytes it takes to express this information. Currently most connectors would perform a separate SELECT to retrieve the values. This is what it would optimally look like:
If I counted it correctly, that's 688 bytes in total. By sending the values in the first OK packet, the amount of data sent is reduced to 274 bytes. In addition to the reduction in data volume, it also avoids one extra roundtrip that would have to be done.
The worst-case performance drop that would come with this change is for connections that are open for a very short time. This overhead can be avoided completely by dropping the CLIENT_SESSION_TRACK capability bit from the initial handshake response. I assume that the tracking of system variables is irrelevant for these types of connections as the likelihood of a system variable change happening in the middle of one is unlikely. |