Traffic Dual Routing #
Background #
In complex business scenarios, architects usually use a hybrid deployment architecture to flexibly build application systems suitable for various scenarios by mixing DBPlusEngine-Driver and DBPlusEngine-Proxy, while using a unified registry to configure the sharding strategy.
DBPlusEngine-Driver adopts a decentralized architecture and shares resources with applications. It is suitable for High-Performance Lightweight OLTP applications developed by Java. However, because DBPlusEngine-Driver shares resources with applications, when executing SQL that consumes more resources, the stability and performance of applications will be affected. At the same time, DBPlusEngine-Driver consumes a large number of connections. When applications and databases are deployed in different network partitions, the impact of network latency on performance will be more obvious.
DBPlusEngine-Proxy provides a unified static entry and is independent of application deployment. It is suitable for OLAP applications and scenarios of managing and maintaining sharding databases. Users use DBPlusEngine-Proxy to execute SQL that consumes more resources, which can effectively avoid affecting applications.
In order to improve the query performance and stability of the application, we can consider forwarding the SQL that consumes more resources at the DBPlusEngine-Driver access end to the DBPlusEngine-Proxy access end located in the same network as the database. The DBPlusEngine-Proxy access end calculates the query results and returns them to the application uniformly.
Challenges #
Although the performance and stability of the application can be effectively improved by forwarding the SQL that consumes more resources at the access end of DBPlusEngine-Driver to DBPlusEngine-Proxy for execution, it also leads to more complex deployment architecture. Users need to determine which statements need to be forwarded to DBPlusEngine-Proxy, and develop relevant business logic at the DAO layer to control the forwarding of SQL.
In addition, in the scenario of starting a transaction, forwarding some SQL in the transaction to DBPlusEngine-Proxy for execution will affect the consistency and visibility of the transaction, thus affecting the use of the transaction by the business system.
Goal #
The main design goal of the DBPlusEngine Traffic module is to make the impact of SQL forwarding as transparent as possible, and let the user use the mixed deployment cluster of DBPlusEngine-Driver and DBPlusEngine-Proxy as much as possible.
Core Concept #
Tag #
The tag attribute configured for the DBPlusEngine-Proxy instance is used to distinguish instances. When the DBPlusEngine-Driver turns on the traffic function, the forwarding target is the DBPlusEngine-Proxy instance corresponding to the tag.
Forwarding Strategy #
For SQL at the access end of DBPlusEngine-Driver, use the strategy of forwarding, includes: target proxy instance label, forwarding algorithm and load balancing algorithm. According to different algorithms, the forwarding strategy can be divided into transaction forwarding strategy and ordinary forwarding strategy. When the algorithm in the strategy is configured as TransactionTrafficAlgorithm the forwarding strategy is transaction forwarding strategy, and when the algorithm in the strategy is configured as other algorithms, the forwarding strategy is ordinary forwarding strategy.
Forwarding Algorithm #
Algorithms used to determine whether the current SQL needs forwarding include HintTrafficAlgorithm, SegmentTrafficAlgorithm and TransactionTrafficAlgorithm.
- HintTrafficAlgorithm based on SQL Hint function to do SQL forwarding.
- SegmentTrafficAlgorithm forwards based on SQL statements, and internally provides forwarding algorithms based on SQL strings and SQL regular matching.
- TransactionTrafficAlgorithm is an algorithm specially used to handle how to forward SQL statements in a transaction when a transaction is started. At present, it supports FIRST_SQL, JDBC and Proxy three strategies. FIRST_SQL means the first forwarding result based on transaction statement, to forward SQL statement in the transaction. JDBC indicates that all SQL of transaction statements are forwarded to the JDBC access terminal for execution. Proxy means that all SQL of transaction statements are forwarded to the proxy access terminal for execution.
Load Balancing Algorithm #
The load balancing algorithm forwards SQL statements to different proxy instances corresponding to tags for execution. At present, it has two load balancing algorithms: RANDOM and ROUND_ROBIN.
Use Norms #
Supported #
- Support forwarding of all commonly used SQL.
Unsupported #
- SQL that is not supported by the kernel function configured by the user is still not supported after forwarding.
- It does not support forwarding SQL to different access terminals or proxy instances for execution after starting a transaction.