1. Introduction of Amoeba
Amoeba is a proxy that uses MySQL as the underlying data storage and provides MySQL protocol interface for applications . It centrally responds to application requests, and sends SQL requests to a specific database for execution according to the rules set by the user in advance. Based on this, requirements such as load balancing, read-write separation, and high availability can be achieved. Compared with MySQL's official MySQL Proxy, the author emphasizes the convenience of amoeba configuration (XML-based configuration file, writing rules in SQLJEP syntax, simpler than MySQL Proxy based on lua script).
Amoeba is equivalent to a router for SQL requests, and its purpose is to provide mechanisms for load balancing, read-write separation, and high availability, rather than fully implementing them . Users need to use MySQL's Replication and other mechanisms to achieve functions such as replica synchronization. amoeba also adopts a pluggable mechanism for the underlying database connection management and routing implementation, and third parties can develop more advanced policy classes to replace the author's implementation. This program is generally more in line with the idea of the KISS principle.
It is estimated that many database technicians who use MySQL Proxy are already familiar with it. Not long ago, some domestic developers also released an Amoeba (Amoeba) project . This project focuses on the development of distributed database Proxy, which has attracted widespread attention from the database community.
Why is it called Amoeba? In fact, this idea came to my mind suddenly. Amoeba means "amoeba" in Chinese. Amoeba is conceived as a development framework for database agents, which can develop agent layers for any database that conforms to the Amoeba framework. Therefore, it is more like an "amoeba" that can become the agent layer software of the target database.
2. Advantages of Amoeba
Amoeba mainly solves the following problems:
a). Integration of complex data sources after data segmentation
b). Provide data segmentation rules and reduce the impact of data segmentation rules on the database
c). Reduce the connection between the database and the client
d). Read-write separation routing
3. Insufficient Amoeba
a), currently does not support transactions
b), temporarily does not support stored procedures (will be supported in the near future)
c) It is not suitable for the scenario of importing data from amoeba or the query for large data volume query (for example, when a request returns more than 10w or even more data)
d) Temporarily does not support sub-database and sub-table, amoeba currently only sub-database instance, each segmented node needs to maintain the same database table structure:
Amoeba for MySQL: Only the MySQL database is proxied, and the MySQL network protocol needs to be analyzed. Its cost is much lower than Aladdin, and its performance is also higher;
Amoeba for Aladdin: All databases that currently provide JDBC drivers can be proxied, and these databases can coexist in the backend of Amoeba for Aladdin.
Fourth, how to achieve mysql read and write separation
Generally speaking, there are two ways:
1. Application layer implementation
2. Middleware layer implementation
Application layer implementation
Application layer implementation refers to the realization of read-write separation within the application and in the connector.
E.g:
com.mysql.jdbc.replicationdriver
mysqlnd_ms
advantage:
Read-write separation is realized inside the program, and it can be used after installation.
Reduce deployment difficulty.
The access pressure is below a certain level, and the performance is very good.
shortcoming:
Once the architecture is adjusted, the code needs to be changed, which is not flexible enough.
Difficult to implement advanced applications, such as automatic sub-library, sub-table
It cannot be applied to larger application scenarios.
Transactions are not currently supported
Middleware layer implementation:
Middleware layer implementation refers to the separation of read and write by external middleware programs
mysql-proxy
amoeba
TDDL(TAObao)
CObar (alibaba)
Atlas (qihoo360)
advantage:
More flexible in architectural design,
Load balancing of read libraries
Some advanced control, failover, flow control can be implemented on the program
mysql performance improvement can be achieved by relying on some technologies, such as connection pooling
Less invasive to business code
shortcoming:
Need to have a certain development strength and the support of the operation and maintenance team