From 1ea94501e41b3d30c460e122e04d8d25ca51a2a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 12 Jun 2018 22:16:45 +0300 Subject: [PATCH] Prefer servers that are not busy executing session commands Readwritesplit now prefers servers that are not busy executing session commands. This should give the best responsiveness for reads. --- .../routing/readwritesplit/rwsplit_route_stmt.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc index 123aee722..ffcfac699 100644 --- a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc +++ b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc @@ -63,6 +63,19 @@ static SRWBackend compare_backends(SRWBackend a, SRWBackend b, select_criteria_t return a; } + // Prefer servers that are not busy executing session commands + bool a_busy = a->has_session_commands(); + bool b_busy = b->has_session_commands(); + + if (a_busy && !b_busy) + { + return b; + } + else if (!a_busy && b_busy) + { + return a; + } + return p(a, b) <= 0 ? a : b; }