What Is Database Proxy
Database Proxy is a network proxy service between GaussDB(for MySQL) and the application service. It is used to proxy all the requests for the application service to access GaussDB(for MySQL).
Read/write splitting means that read and write requests are automatically forwarded through database proxy addresses. After creating a GaussDB(for MySQL) instance, you can create a proxy instance. Write requests are automatically forwarded to the primary node and read requests are forwarded to each node based on the routing policy of the proxy instance.
Functions
Basic Concepts
- Proxy address
After buying a proxy instance, you can view the proxy address on the Database Proxy page. The proxy instance sends write requests to the primary node and read requests to read replicas through this address.
- Proxy mode
There are read/write and read-only proxy modes.
Read/Write: All write requests are routed only to the primary node, and all read requests are routed to the selected nodes based on the read weights or active connections.
Read-only: All read requests are routed to the selected read replicas based on the read weights or active connections. The read requests will not be routed to the primary node.
- Transaction splitting
With transaction splitting enabled for a proxy instance, the proxy instance can route read requests prior to write operations in a transaction to read replicas, reducing the load on the primary node.
For more information about transaction splitting, see Enabling Transaction Splitting for a Proxy Instance.
- Connection pool
Proxy instances provide session-level connection pools, which help reduce the database load caused by frequent establishment of short connections.
For more information about connection pools, see Enabling the Connection Pool for a Proxy Instance.
- Routing policy
Proxy instances support weighted and load balancing routing policies.
- Weighted: Read requests are assigned to nodes based on the weights you specify.
- Load balancing: Read requests are assigned to nodes with fewer active connections. In the load balancing policy, you do not need to configure the weights of nodes.
For more information about routing policies, see Modifying the Routing Policy of a Proxy Instance.
How Read/Write Splitting Works
You can create one or more proxy instances for your GaussDB(for MySQL) instance to enable read/write splitting.
- Single proxy instance
If your GaussDB(for MySQL) instance has only one proxy instance, applications connect to the proxy instance through the proxy address. Write requests are forwarded to the primary node and read requests to the primary node or read replicas based on the routing policy you specify.
Figure 1 Read/write splitting with only one proxy instance
- Multiple proxy instances
To isolate workloads from different applications, you can create up to four proxy instances for your GaussDB(for MySQL) instance. Different applications can connect to different proxy instances as required. The associated read replicas of the proxy instances process read requests from different applications for workload isolation.
Figure 2 Read/write splitting with multiple proxy instances
Application Scenarios
- The primary node is overloaded due to a large number of requests in a transaction.
- The primary node is overloaded due to excessive connections.
- Read/write splitting is required.
Read/Write Splitting Advantages
- Compared with manual read/write splitting in applications, the read/write splitting using proxy addresses features flexible scale-out and low maintenance costs.
- Read requests are distributed to your read replicas based on weights to balance your database traffic and improve resource utilization.
- A proxy instance routes read requests of an application only to its associated read replicas to isolate workloads.
- By default, proxy instances provide overload protection to prevent server OOM (out of memory) due to heavy pressure when you perform operations on large result sets. This function is enabled by default and does not need to be configured separately. The pressure caused by the slow kernel depends on flow control.
Request Routing Rules
- Write requests sent only to the primary node
- INSERT, UPDATE, and DELETE
- All DDL operations (such as table/database creation, table/database deletion, table structure change, and permission change)
- All requests in transactions (But if transaction splitting is enabled, some read requests in transactions may be sent to read replicas. For details, see Enabling Transaction Splitting for a Proxy Instance.)
- User-defined functions
- Stored procedures
- EXECUTE statements
- Multi-statement requests
- Requests that use temporary tables
- All changes to user variables
- KILL in SQL statements (not command KILL)
- Read requests sent only to the primary node
- If query statements are in transactions, the transaction requests are routed to the primary node. If SET AUTOCOMMIT=0 is added before a query statement, the transaction requests are routed to the primary node.
- If all read replicas are abnormal or the read weights allocated to the read replicas are 0, requests will be routed to the primary node. You can set read weights for the primary node and read replicas after read/write splitting is enabled.
- When running SQL statements:
- If multi-statements (for example, insert xxx;select xxx) are executed, all subsequent requests will be routed to the primary node. To restore read/write splitting, disconnect your application from your instance and then connect it back again.
- Read operations with locks (for example, SELECT for UPDATE) will be routed to the primary node.
- When /*FORCE_MASTER*/ is used, requests will be routed to the primary node.
- If the HANDLER statement is executed, all subsequent requests will be routed to the primary node. To restore read/write splitting, disconnect your application from your instance and then connect it back again.
- SELECT last_insert_id()
- All queries of user variables
- Requests sent either to the primary node or a read replica
- SELECT not in a transaction
- The COM_STMT_EXECUTE command
- Requests always sent to all nodes
- Changes to all system variables
- The USE command
Read/Write Attribute Processing Logic
There are read-only and read/write modes for proxy instances. The read/write attribute processing logic varies depending on the proxy mode.
Proxy Mode |
Routing Policy |
Weight of Primary Node |
Normal Case |
All Read Replicas Are Faulty |
---|---|---|---|---|
Read-only |
Weighted Load balancing |
Not configurable |
The primary node does not process read-only requests. Proxy address: readable but not writable |
The primary node does not process read-only requests. Proxy address: connection error |
Read/Write |
Load balancing |
Assigned by system |
Primary node: readable and writable Proxy address: readable and writable |
Primary node: readable and writable Proxy address: readable and writable |
Weighted |
> 0 |
Primary node: readable and writable Proxy address: readable and writable |
Primary node: readable and writable Proxy address: readable and writable |
|
= 0 |
Primary node: not readable but writable Proxy address: readable and writable |
Primary node: readable and writable Proxy address: readable and writable |
Billing
Proxy instances are free.
Precautions
Category |
Precaution |
---|---|
Version constraints |
|
Unsupported functions |
|
Usage constraints |
|
HTAP analysis |
|
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot