现在,在来看看MySQL Proxy:
使用LUA(Lua 是一个小巧的脚本语言,该语言的设计目的是为了嵌入应用程序中,从而为应用程序提供灵活的扩展和定制功能。它的主页是 www.lua.org,Lua 最著名的应用是在暴雪公司的网络游戏WOW中),MySQL Proxy能减轻我们应用的复杂性,比如,根据不同的sql类型,可以将不用的应用分配到不同的数据库服务器。通过MySQL Proxy 来解析阻塞,把应用导向适合的数据库服务器。这里应用没有改动,这个结构变化的最显著的是有了一个叫“sql”的双向箭头的线。至于我们说到的不同的 sql类型留给 MySQL Proxy去辨别。
MySQL Proxy也具有均衡各种 MySQL服务(具有mysql复制的子机)查询的任务。 http://kaj.arno.fi/ProxyCluster5.png
图5清晰的这里描述的复杂结构,但是它也代表了数据库服务最高的伸缩度。
上面提到的都是用的目前最新版本的MySQL Cluster 和 MySQL Server,MySQL Proxy。
MySQL Proxy: http://forge.mysql.com/wiki/MySQL_Proxy
MySQL Cluster: http://www.mysql.com/products/database/cluster/
MySQL Replication: http://dev.mysql.com/doc/refman/5.0/en/replication.html
原文:
A while ago, I had a discussion with Stewart Smith, Vinay Joosery, Monty Taylor and a number of other MySQLers who know much more about MySQL Cluster than I do. The result is a model for using MySQL Proxy to offload MySQL Cluster from doing Table Scans, without touching the application. http://kaj.arno.fi/ProxyCluster1.png
The discussion started from me asking Stewart about the largest road block for expanding the number of use cases for MySQL Cluster. “Oh, that would probably be doing JOINs and other SELECTs requiring the scanning of large parts of the database”, he replied. “There, other storage engines are faster, such as MyISAM and InnoDB.”
In a very simple view, the application talks SQL with MySQL Cluster, and gets responses. http://kaj.arno.fi/ProxyCluster2.png
Stewart’s insight can be refined into the first simplistic diagram by adding the recognition that “SQL” can consist of
UPDATE, INSERT, DELETE statements (very light, usually invidual rows affected) — unidirectional blue arrow in the diagram below
Simple SELECT statements (also very light, defined as SELECTs that use indices and return invidual rows) — bidirectional black arrow
Complex SELECT statements (could be as easy as “SELECT *”, but defined as those not easily using indices and usually returning multiple rows) — dashed arrows having two arrowheads to show that plenty of data is being returned
This second figure doesn’t depict any change in application architecture from the first figure; it just shows a more granular view.
Now, enter the insight that plain MySQL Server (with MyISAM or InnoDB) can deliver the complex SELECTs faster. http://kaj.arno.fi/ProxyCluster3.png
In the new architecture represented by the above picture, we scale the application by
introducing Replication (replicating MySQL Cluster to plain MySQL Server)
changing the application to direct the complex SELECTs to MySQL Server instead of MySQL Cluster
This complicates life. Not only do we need to set up replication. We also need to touch the application all over the place, to direct queries to the appropriate server.
Now, enter MySQL Proxy. http://kaj.arno.fi/ProxyCluster4.png Using LUA scripts, MySQL Proxy can relieve us of the second complication, i.e. having to change the application to point to different MySQL Servers depending on the type of the SQL. Let MySQL Proxy parse the traffic and direct it to the appropriate server! The application is left untouched, and the topmost part of the picture again has a simple bidirectional arrow saying “SQL”. The distinction of what type of SQL we’re talking about is left to MySQL Proxy. MySQL Proxy can also be assigned to load balancing the queries to a number of MySQL Replication Slaves. http://kaj.arno.fi/ProxyCluster5.png
This picture clearly is the most complex architecture depicted here, but also represents the highest level of scaling. All of the above can be done using current versions of MySQL Cluster and MySQL Server, and the MySQL Proxy.
Sources:
MySQL Proxy: http://forge.mysql.com/wiki/MySQL_Proxy
MySQL Cluster: http://www.mysql.com/products/database/cluster/
MySQL Replication: http://dev.mysql.com/doc/refman/5.0/en/replication.html