Dry goods! MySql DAL middleware summary


image


1 Introduction

MySQL is a database used by Internet companies. If performance problems occur during use, mysql's horizontal expansion will be used, and master-slave replication will be used to improve read performance. If writing problems are solved, database and table splitting is required. This article will not introduce the high availability of mysql. If you need to understand the high availability architecture of imageMySQL , please talk about the high availability architecture of MySQL cluster . This article mainly introduces some implementation schemes of mysql access middleware (DAL).


2.Atlas

Official website: https://github.com/Qihoo360/Atlas/blob/master/README_ZH.md

2.1. Introduction to atlas

Atlas is a data middle-tier project based on MySQL protocol developed and maintained by the infrastructure team of Qihoo 360's Web Platform Department. Based on the MySQL-Proxy 0.8.2 version officially launched by MySQL, it has revised a lot of bugs and added many features. At present, the project has been widely used within 360 companies. Many MySQL services have been connected to the Atlas platform, and the number of read and write requests carried every day reaches several billion. At the same time, more than 50 companies have deployed Atlas in the production environment, more than 800 people have joined our developer exchange group, and these numbers are still increasing.

2.2. atlas architecture

Atlas is a middleware between the application and MySQL. From the perspective of the back-end DB, Atlas is equivalent to the client connecting to it, and from the perspective of the front-end application, Atlas is equivalent to a DB. Atlas communicates with the application as a server. It implements the MySQL client and server protocols, and at the same time communicates with MySQL as a client. It shields the details of the DB from the application. At the same time, in order to reduce the burden on MySQL, it also maintains a connection pool.

image

2.3. Main functions

1. Read and write separation

2. Load balancing from the library

3.IP filtering

4. Automatic sub-table

5.DBA can smoothly go online and offline DB

6. Automatically remove the down DB

The advantages of Atlas over the official MySQL-Proxy

1. Rewrite all Lua codes in the main process with C, Lua is only used for management interfaces

2. Rewrite the network model and thread model

3. Realize the connection pool in the true sense

4. Optimized the locking mechanism, and the performance has been improved dozens of times

3.Mysql router

Official website: http://dev.mysql.com/doc/mysql-router/en/

3.1. Introduction to mysql router

MySQL Router is a database middleware officially released by mysql. It is a lightweight agent program between the application client and dbserver. It can detect, analyze and forward queries to the back-end database instance, and return the results to the client. It is an alternative to mysql-proxy. Its architecture diagram and functions are as follows.

3.2. mysql router architecture

image

  • 1. Router realizes the separation of reading and writing, the program is not directly connected to the database IP, but fixedly connected to the mysql router. MySQL Router is transparent to front-end applications. The application treats MySQL Router as a normal mysql instance, and sends queries to MySQL Router, and MySQL Router returns the query results to the front-end application.

  • 2. From the database server failure, the business can run normally. Unavailable servers are automatically logged off by MySQL Router. The program configuration does not require any modification.

  • 3. If the main database fails, MySQL Router decides to automatically switch between the master and the slave, and the business can be accessed normally. The program configuration does not require any modification.

MySQL Router read-write separation principle:

After MySQL Router accepts the front-end application request, it distinguishes read and write according to different ports, sends all queries connected to the read-write port to the main library, and sends select queries connected to the read-only port to multiple slave libraries in a polling manner. So as to achieve the purpose of separation of reading and writing. The result of reading and writing will be handed to MySQL Router, which will be returned to the client application by MySQL Router.

3.3. Main functions of mysql router

The main purpose of MySQL Router is separation of read and write, automatic switchover of main and main failures, load balancing, connection pooling, etc.



4.Mycat

Official website: http://www.mycat.org.cn/

4.1. Introduction to mycat

Mycat is based on the evolution of the open source cobar. It completely refactors the code of cobar, uses NIO to reconstruct the network module, and optimizes the Buffer kernel, enhances the basic features such as aggregation and Join, and is compatible with most databases. General database middleware. After version 1.4, it has completely departed from the basic cobar kernel, combined with Mycat cluster management, automatic expansion, and intelligent optimization to become a high-performance middleware.

  • A completely open source large database cluster for enterprise application development
  • Support transactions, ACID, and an enhanced database that can replace MySQL
  • An enterprise-level database that can be regarded as a MySQL cluster to replace the expensive Oracle cluster
  • A new SQL Server integrating memory caching technology, NoSQL technology, and HDFS big data
  • A new generation of enterprise-level database products that combine traditional databases and new distributed data warehouses
  • A novel database middleware product

4.2. mycat architecture

image

4.3. Main functions of mycat

  • Support SQL92 standard

  • Comply with Mysql native protocol, cross-language, cross-platform, and cross-database general middleware agent.

  • Automatic failover based on heartbeat, support read-write separation, support MySQL master-slave, and galera cluster cluster.

  • Support Galera for MySQL cluster, Percona Cluster or MariaDB cluster

  • Based on Nio implementation, effective thread management, high concurrency issues.

  • Supports multi-slice automatic routing and aggregation of data, and supports commonly used aggregation functions such as sum, count, and max.

  • Supports arbitrary joins within a single database, supports cross-database 2-table joins, and even caltlet-based multi-table joins.

  • Supports the sharding strategy of global tables and ER relations to achieve efficient multi-table join queries.

  • Support multi-tenant solutions.

  • Support for distributed transactions (weak xa).

  • Support global serial number, solve the problem of primary key generation under distributed.

  • Rich sharding rules, plug-in development, easy to expand.

  • Powerful web, command line monitoring.

  • 支持前端作为mysq通用代理,后端JDBC方式支持Oracle、DB2、SQL Server 、 mongodb 、巨杉。

  • 支持密码加密

  • 支持服务降级

  • 支持IP白名单

  • 支持SQL黑名单、sql注入***拦截

  • 支持分表(1.6)

  • 集群基于ZooKeeper管理,在线升级,扩容,智能优化,大数据处理(2.0开发版)。

Mysql+mycat架构实战请戳imageMysql+Mycat实现数据库主从同步与读写分离


5.Cobar

官网:https://github.com/alibaba/cobar/wiki

5.1.cobar简介

Cobar是提供关系型数据库(MySQL)分布式服务的中间件,它可以让传统的数据库得到良好的线性扩展,并看上去还是一个数据库,对应用保持透明。产品在阿里巴巴稳定运行3年以上。接管了3000+个MySQL数据库的schema。集群日处理在线SQL请求50亿次以上。集群日处理在线数据流量TB级别以上。

5.2.cobar架构

image5.3.cobar现状

2013年阿里的Cobar在社区使用过程中发现存在一些比较严重的问题,及其使用限制,后来在cobar的基础上改良诞生mycat,也就是目前cobar的代替版,而且2013年之后就没有版本更新了。


6.Amoeba

官网:http://docs.hexnova.com/amoeba/

6.1.amoeba简介

Amoeba(变形虫)项目,该开源框架于2008年 开始发布一款 Amoeba for Mysql软件。这个软件致力于MySQL的分布式数据库前端代理层,它主要在应用层访问MySQL的 时候充当SQL路由功能,专注于分布式数据库代理层(Database Proxy)开发。座落与 Client、DB Server(s)之间,对客户端透明。具有负载均衡、高可用性、SQL 过滤、读写分离、可路由相关的到目标数据库、可并发请求多台数据库合并结果。通过Amoeba你能够完成多数据源的高可用、负载均衡、数据切片的功能

6.2.amoeba架构

image

6.3.amoeba现状

目前作者已经停止维护。


7.Mysql proxy

7.1.mysql proxy简介

MySQL Proxy是一个处于你的client端和MySQL server端之间的简单程序,它可以监测、分析或改变它们的通信。它使用灵活,没有限制,常见的用途包括:负载均衡,故障、查询分析,查询过滤和修改等等。MySQL Proxy就是这么一个中间层代理,简单的说,MySQL Proxy就是一个连接池,负责将前台应用的连接请求转发给后台的数据库,并且通过使用lua脚本,可以实现复杂的连接控制和过滤,从而实现读写分离和负载平衡。对于应用来说,MySQL Proxy是完全透明的,应用则只需要连接到MySQL Proxy的监听端口即可。当然,这样proxy机器可能成为单点失效,但完全可以使用多个proxy机器做为冗余,在应用服务器的连接池配置中配置到多个proxy的连接参数即可。MySQL Proxy更强大的一项功能是实现“读写分离”,基本原理是让主数据库处理事务性查询,让从库处理SELECT查询。数据库复制被用来把事务性查询导致的变更同步到集群中的从库。

7.2.mysql proxy现状

自从mysql官网出现mysql router之后,mysql proxy就已经停止维护了。

mysql proxy架构实战ProxySQL+Mysql实现数据库读写分离实战


8.客户端分片

8.1.客户端分片简介

The program client performs sub-database sub-table. That is to split the database and the table directly in the program, such as the user table. According to the user's UID, such as 13678789, according to the last digit, it can be divided into 10 databases from 0-9. The ones with the ending number 0 are stored in the db_user_0 database, and the ones ending with 1 are stored in the db_user_1 database, and also when selecting same. Then, according to the penultimate digit, it can be divided into 10 tables from 0-9, and written into the corresponding table according to the last number of the penultimate. For example, the UID information of 13678789 is written into the table_user_8 of the db_user_9 database.

8.2. Advantages

(1) No need to use middleware, no impact on performance (2) Code control, strong definability

9. Postscript

For the above mysql middleware, I personally recommend using atlas and mycat in production, and client sharding can be used if the development strength is strong or there is a DBA. Mysql router feels that it is not very mature yet. As for other middleware authors, they don't update it anymore. As long as there are no historical problems, don't use it.

Author Original article submission, author: Simon flying ice, after a 90 it man, has been working in Beijing, love sports, love of adventure, love of travel.  



Guess you like

Origin blog.51cto.com/15127557/2665913