[MXS-4635] Provide load balancing metadata to connectors Created: 2023-06-09  Updated: 2023-11-11  Resolved: 2023-07-13

Status: Closed
Project: MariaDB MaxScale
Component/s: Protocol
Affects Version/s: None
Fix Version/s: 23.08.0

Type: New Feature Priority: Major
Reporter: markus makela Assignee: markus makela
Resolution: Fixed Votes: 1
Labels: None

Attachments: File session-variable-tracking.diff    
Issue Links:
Relates
relates to MDEV-31609 Send initial values of system variabl... Open
relates to CONJ-1084 loadbalance distribution ensuring rep... Closed
relates to MDEV-15935 Connection Redirection Mechanism in M... Closed
relates to MXS-4153 Graceful Restart Open
Sprint: MXS-SPRINT-186

 Description   

By adding load related metadata to the login requests, the connectors can make more educated guesses as to where to connect next. This would work well with the MariaDB connectors that support multiple endpoints and would allow a more even load distribution.



 Comments   
Comment by Diego Dupin [ 2023-06-09 ]

A solution would be to have some new "Session change type" SESSION_CONNECTION_COUNTER : When establishing a connection to maxscale, maxscale can send to connectors current number of connection in connection creation ending OK_Packet.

When using loadbalancing, connector could by default use a round-robin pattern and when having those informations, will connect to the less use maxscale by default. The advantage is when a failover occurs, and that maxscale is up again, connectors will then priorize new connections creation to this maxscale until number of connections reach other's.

Comment by markus makela [ 2023-06-09 ]

Another option is to do what is planned for MDEV-15935 and just reserve a variable name for this purpose. This would be backwards compatible and would allow this to be emulated by applications as long as the connector supports session variable tracking.

Comment by Diego Dupin [ 2023-06-09 ]

Exactly, I was wondering how far this should be carried by connectors or maxscale. in fact the second solution seems more appropriate

Comment by markus makela [ 2023-06-14 ]

This should be straightforward to implement:

  • Extend mxs_mysql_create_ok() to support session state information.
  • Add the current number of connections as the value of a custom session variable name (similar to last_gtid). The number of connections can be read from m_session->service->stats().n_current_conns().

A preliminary name for the variable could be _connections. This could also be used by the MariaDB server to indicate how many connections there are. This would give the connectors more information that they could base their load balancing decisions on.

Once this is implemented, implementing an initial version of the redirection mechanism described in MDEV-15935 would be easy: just add a new configuration variable that sets the redirection URL. This would not perform redirection while the sessions are open but in the general case where connections have a finite lifetime, this would be a interruption-free way of moving connections from once instance to another.

Comment by markus makela [ 2023-06-22 ]

Attached a proof-of-concept patch for fake status changes for threads_connected (a status variable in MariaDB) which contains the number of current connections. I also added a version of the redirection URL into it since it was trivial to implement once the session state change tracker was done.

Comment by Sergei Golubchik [ 2023-06-28 ]

I'd rather do it on the server. It could set redirect_url when the number of connections grow above certain limit

Comment by markus makela [ 2023-07-06 ]

MaxScale will now by default send the same values that are set as the default values of session_track_system_variables in the first OK packet: character_set_client, character_set_connection, character_set_results, time_zone. Additionally, the system_time_zone, max_allowed_packet and tx_isolation values are sent as well. The current connection count is also added as threads_connected along with the 64-bit connection ID as connection_id. The autocommit value is not sent since it's redundant as one of the server status bits is reserved for it.

Generated at Thu Feb 08 04:30:03 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.