# Readwritesplit This document provides a short overview of the **readwritesplit** router module and its intended use case scenarios. It also displays all router configuration parameters with their descriptions. A list of current limitations of the module is included and use examples are provided. ## Overview The **readwritesplit** router is designed to increase the read-only processing capability of a cluster while maintaining consistency. This is achieved by splitting the query load into read and write queries. Read queries, which do not modify data, are spread across multiple nodes while all write queries will be sent to a single node. The router is designed to be used with a traditional Master-Slave replication cluster. It automatically detects changes in the master server and will use the current master server of the cluster. With a Galera cluster, one can achieve a resilient setup and easy master failover by using one of the Galera nodes as a Write-Master node, where all write queries are routed, and spreading the read load over all the nodes. ## Configuration Readwritesplit router-specific settings are specified in the configuration file of MariaDB MaxScale in its specific section. The section can be freely named but the name is used later as a reference in a listener section. For more details about the standard service parameters, refer to the [Configuration Guide](../Getting-Started/Configuration-Guide.md). ## Optional parameters ### `max_slave_connections` **`max_slave_connections`** sets the maximum number of slaves a router session uses at any moment. The default is to use all available slaves. max_slave_connections= ### `max_slave_replication_lag` **`max_slave_replication_lag`** specifies how many seconds a slave is allowed to be behind the master. If the lag is bigger than the configured value a slave can't be used for routing. This feature is disabled by default. max_slave_replication_lag= This applies to Master/Slave replication with MySQL monitor and `detect_replication_lag=1` options set. max_slave_replication_lag must be greater than the monitor interval. This option only affects Master-Slave clusters. Galera clusters do not have a concept of slave lag even if the application of write sets might have lag. ### `use_sql_variables_in` **`use_sql_variables_in`** specifies where should queries, which read session variable, be routed. The syntax for `use_sql_variable_in` is: use_sql_variables_in=[master|all] The default is to use SQL variables in all servers. When value `all` is used, queries reading session variables can be routed to any available slave (depending on selection criteria). Queries modifying session variables are routed to all backend servers by default, excluding write queries with embedded session variable modifications, such as: INSERT INTO test.t1 VALUES (@myid:=@myid+1) In above-mentioned case the user-defined variable would only be updated in the master where the query would be routed to due to the `INSERT` statement. **Note:** As of version 2.1 of MaxScale, all of the router options can also be defined as parameters. The values defined in _router_options_ will have priority over the parameters. ``` [Splitter Service] type=service router=readwritesplit servers=dbserv1, dbserv2, dbserv3 user=maxscale passwd=96F99AA1315BDC3604B006F427DD9484 disable_sescmd_history=true master_failure_mode=fail_on_write ``` ### `connection_keepalive` Send keepalive pings to backend servers. This feature was introduced in MaxScale 2.2.0 and is disabled by default. The parameter value is the interval in seconds between each keepalive ping. A keepalive ping will be sent to a backend server if the connection is idle and it has not been used within `n` seconds where `n` is greater than or equal to the value of _connection_keepalive_. The keepalive pings are only sent when the client executes a query. This functionality allows the readwritesplit module to keep all backend connections alive even if they are not used. This is a common problem if the backend servers have a low _wait_timeout_ value and the client connections live for a long time. ## Router options **`router_options`** may include multiple **readwritesplit**-specific options. All the options are parameter-value pairs. All parameters listed in this section must be configured as a value in `router_options`. Multiple options can be defined as a comma-separated list of parameter-value pairs. ``` router_options=