[MXS-4769] Deferred session command execution Created: 2023-09-21 Updated: 2023-09-24 Resolved: 2023-09-24 |
|
| Status: | Closed |
| Project: | MariaDB MaxScale |
| Component/s: | readwritesplit |
| Affects Version/s: | None |
| Fix Version/s: | N/A |
| Type: | New Feature | Priority: | Major |
| Reporter: | markus makela | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 1 |
| Labels: | None | ||
| Description |
|
When lazy_connect or master_reconnection is enabled and a session command is executed with no open connection, the command will always prefer the current master node as the sescmd replier. This is not always ideal as it forces an open connection to the current master node even if it will never get used. Compared to master_failure_mode=fail_on_write, the session command will prefer the first available server for session commands. This behavior is much better for read-only workloads compared to how lazy_connect currently behaves. As there's no way to know whether the intended workload will be read-write or read-only, the choice of the sescmd replier type is not known in advance. The ideal solution for this would be to defer the execution of the session commands, if possible, until the server actually ends up being used. For things like SET NAMES and other guaranteed-to-work commands, this would be perfectly fine. For things like COM_STMT_PREPARE the answer must come from the real server. A short-term solution the problem of lazy_connect always preferring a master server is to detect whether it is enabled, whether a transaction is open and if master_failure_mode would allow the query to be executed. The behavior of server selection for this case is also somewhat inconsistent as with master_failure_mode=fail_on_write the commands can still end up being executed in a way where the master's response would be "wrong". I split this off into The long term solution is described in MXS-4390 that implements deferred execution of session commands. From the lazy_connect perspective, this would be relatively simple to implement by just injecting a fake OK packet whenever situation is detected where there are no open connections and a new connection would be needed. This would effectively result in optimistic deferred execution of session commands that would then delay their execution until an answer from the actual server is needed. |
| Comments |
| Comment by Simon [ 2023-09-22 ] |
|
This poses a significant bottleneck for applications that primarily read from local slaves but occasionally need to write to a remote master. In many PHP applications, the `SET NAMES` command is automatically issued to switch to the required character encoding. This query is then routed to all servers, including the master. When the master is located remotely, this introduces unnecessary latency, making MaxScale nearly unusable in a read-mostly scenario with a 'slow' master server. |
| Comment by markus makela [ 2023-09-24 ] |
|
Now that the problematic behavior of lazy_connect is split off into |