@@ -130,7 +130,7 @@ def wait_until_mysql_connection(self) -> None:
130
130
131
131
# Increment this PATCH version before using `charmcraft publish-lib` or reset
132
132
# to 0 if you are raising the major API version
133
- LIBPATCH = 59
133
+ LIBPATCH = 60
134
134
135
135
UNIT_TEARDOWN_LOCKNAME = "unit-teardown"
136
136
UNIT_ADD_LOCKNAME = "unit-add"
@@ -141,7 +141,8 @@ def wait_until_mysql_connection(self) -> None:
141
141
BYTES_1MiB = 1048576 # 1 mebibyte
142
142
RECOVERY_CHECK_TIME = 10 # seconds
143
143
GET_MEMBER_STATE_TIME = 10 # seconds
144
- MIN_MAX_CONNECTIONS = 100
144
+ MAX_CONNECTIONS_FLOOR = 10
145
+ MIM_MEM_BUFFERS = 200 * BYTES_1MiB
145
146
146
147
SECRET_INTERNAL_LABEL = "secret-id"
147
148
SECRET_DELETED_LABEL = "None"
@@ -868,36 +869,60 @@ def render_mysqld_configuration(
868
869
* ,
869
870
profile : str ,
870
871
memory_limit : Optional [int ] = None ,
872
+ experimental_max_connections : Optional [int ] = None ,
871
873
snap_common : str = "" ,
872
874
) -> tuple [str , dict ]:
873
875
"""Render mysqld ini configuration file.
874
876
875
877
Args:
876
878
profile: profile to use for the configuration (testing, production)
877
879
memory_limit: memory limit to use for the configuration in bytes
880
+ experimental_max_connections: explicit max connections to use for the configuration
878
881
snap_common: snap common directory (for log files locations in vm)
879
882
880
883
Returns: a tuple with mysqld ini file string content and a the config dict
881
884
"""
885
+ max_connections = None
882
886
performance_schema_instrument = ""
883
887
if profile == "testing" :
884
888
innodb_buffer_pool_size = 20 * BYTES_1MiB
885
889
innodb_buffer_pool_chunk_size = 1 * BYTES_1MiB
886
890
group_replication_message_cache_size = 128 * BYTES_1MiB
887
- max_connections = MIN_MAX_CONNECTIONS
891
+ max_connections = 100
888
892
performance_schema_instrument = "'memory/%=OFF'"
889
893
else :
890
894
available_memory = self .get_available_memory ()
891
895
if memory_limit :
892
896
# when memory limit is set, we need to use the minimum
893
897
# between the available memory and the limit
894
898
available_memory = min (available_memory , memory_limit )
899
+
900
+ if experimental_max_connections :
901
+ # when set, we use the experimental max connections
902
+ # and it takes precedence over buffers usage
903
+ max_connections = experimental_max_connections
904
+ # we reserve 200MiB for memory buffers
905
+ # even when there's some overcommittment
906
+ available_memory = max (
907
+ available_memory - max_connections * 12 * BYTES_1MiB , 200 * BYTES_1MiB
908
+ )
909
+
895
910
(
896
911
innodb_buffer_pool_size ,
897
912
innodb_buffer_pool_chunk_size ,
898
913
group_replication_message_cache_size ,
899
914
) = self .get_innodb_buffer_pool_parameters (available_memory )
900
- max_connections = max (self .get_max_connections (available_memory ), MIN_MAX_CONNECTIONS )
915
+
916
+ # constrain max_connections based on the available memory
917
+ # after innodb_buffer_pool_size calculation
918
+ available_memory -= innodb_buffer_pool_size + (
919
+ group_replication_message_cache_size or 0
920
+ )
921
+ if not max_connections :
922
+ max_connections = max (
923
+ self .get_max_connections (available_memory ), MAX_CONNECTIONS_FLOOR
924
+ )
925
+
901
926
if available_memory < 2 * BYTES_1GiB :
902
927
# disable memory instruments if we have less than 2GiB of RAM
903
928
performance_schema_instrument = "'memory/%=OFF'"
0 commit comments