MySQL Proxy vs. HSCALE

Recently I added the first code to support multiple MySQL backends in HSCALE (see svn.hscale.org). As a “side note” I have to thank Giuseppe Maxia for MySQL Sandbox which made multi server testing a bliss!

While coding this I started to feel that writing HSCALE on top of MySQL Proxy is no more as easy and clean as it started out to be. And finally I reached the point where I have to say:

HSCALE (and maybe other advanced multi-server applications) and (current) MySQL Proxy don’t fit very well.

Before I go into details please let me make clear that this is mostly due to the specific nature of MySQL Proxy being a connection and protocol based proxy. MySQL Proxy is great and there are a lot of cool applications that fit perfectly with it.

Aside from some other minor glitches (like missing tokens in SQL tokenizer) the biggest show stopper is:

Handling of multiple backends

The biggest problem I had to face is the handling of backend connections in MySQL Proxy. What I would need for HSCALE are dedicated connections to every backend for every proxy connection. So if a client connects to the proxy, a connection to each backend is opened and attached to this particular client connection. This way I easily could maintain the state of the connection by sending commands like SET variable or USE database to all backends.
Dedicated connections are vital for XA or transactions in general, too.

The way the proxy handles backend connections right now is somewhat cumbersome (See an example.). The way you have to maintain your own connection pool is hard to understand and uses too much “magic” in my opinion. And the pool only grows with the number of connections made to the proxy. People are having problems with this approach (read the MySQL Proxy forum, for instance this thread).

The current experimental multi-server code in HSCALE uses this connection pooling technique since it is the only way to establish connections to other backend servers.

So what can we do now to implement multi-server support in HSCALE?

  1. Wait until MySQL Proxy supports dedicated backend connections This would be the easiest and most elegant solution. But it could be that Jan Kneschke and the other developers decide that this is not what they intended to do with the proxy. And this would be totally ok from their point of view! Even if they decide that this is a cool feature it could take a long while until it is implemented. (Hint: I would gladly help out here ;) ).
  2. Work around this using luasql While possible this solution would not be preferable since we are using two technologies for the same thing.
  3. Switch to another proxy There are quite a few. This would be no fun and I did not take a look at them all to see if it is even possible. It would be complete rewrite though.
  4. Fork MySQL Proxy or implement a plugin The new plugin technology could be used to implement the multi-backend connection stuff myself. As a last resort, I could fork the whole project (like Spock Proxy did, see below). This would still mean a lot of work though and loss of the MySQL efforts put into the proxy.
  5. Use other sharding technologies and eventually abandon HSCALE As an example Spock Proxy, a fork of MySQL Proxy does a great deal of what we intend to do with HSCALE.
  6. Re-implement HSCALE as a JDBC driver Since our applications are written in Java exclusively we could do that.

Of course I would love to continue HSCALE as a MySQL Proxy application! The main reasons are the efforts MySQL is putting into MySQL Proxy, the extensibility we gain combining multiple LUA scripts (there are more things we do with the proxy apart from HSCALE) and last but not least the community echo HSCALE already received.

As a next step I will take a deeper look into the proxy code and evaluate the efforts needed to add dedicated connections.

11 Responses to “MySQL Proxy vs. HSCALE”

  1. deepfryed Says:

    hiya, i’ve tried using hscale and the connections always seem to go the same backend. using the current development code in svn btw. is there something i’m missing out in the docs ?

    e.g.
    mysql-proxy –proxy-backend-addresses=10.0.0.1:3306 –proxy-backend-addresses=10.0.0.2:3306 –proxy-lua-script=/home/bharanee/sfw/hscale/hscale/src/optivo/hscale/main.lua

  2. pero Says:

    Hi deppfryed,

    as mentioned above the current multi-server code is EXPERIMENTAL. The problem you are experiencing is the reason I wrote this blog post ;) The other backends will only be used after you connected several times to proxy. It is the same problem as with the read-write-splitting: http://forums.mysql.com/read.php?146,197085,202796#msg-202796

    This is exactly what I am doing in the unit tests (see file test/proxyUnit/suite/optivo/hscale/t/setup.sql).

    Version 0.3 will have (correct) multi-server support and a dictionary based partition lookup.

    Regards

    Peter

  3. HScale and MySQL Proxy « François Schiettecatte’s Blog Says:

    […] HScale and MySQL Proxy Filed under: Scaling, Software Development — François Schiettecatte @ 5:58 pm I have written about HScale before and MySQL Proxy, raising a few questions about fault tolerance, but I did not anticipate the issues they ran into. […]

  4. Jan Kneschke Says:

    Multi-Backend handling will be the next big thing after we finally released 0.7.0.

  5. pero Says:

    Jan,

    this is great news! I’d love to hear some details of what you are planning and share some of my thoughts with you. I eventually going to meet Lenz and Giuseppe at the forthcoming developers conference in Riga. If you join the conference, too, we could have a talk then (if you like).

    Greetings

    Peter

  6. Jan Kneschke Says:

    Sure, I’ll be very happy to meet you in Riga and invite you to a beer or too.

  7. pero on anything » Blog Archive » More fun with LUA - Introducing Log4LUA Says:

    […] the dust about backend connection handling in MySQL Proxy had settled, I begun working on other parts of HSCALE again. (I’ll return to the backend […]

  8. pero on anything » Blog Archive » Version 0.3 of HSCALE is almost in the door Says:

    […] note: Due to the problems with backend connection handling version 0.3 will still focus on single server backends. Even though support for multiple backends […]

  9. pero on anything » Blog Archive » LuaSQL fetches results about 15% faster than MySQL Proxy Says:

    […] evaluating LuaSQL as backend connection replacement I came across this. I did a quick performance test using mysqlslap and it showed that just reading […]

  10. Robert Hodges Says:

    Hi Peter,

    Your articles on HSCALE have been very interesting. Since you are using Java, another option you might want to consider is looking at the Tungsten Connector (aka Myosotis), which is described at http://community.continuent.com/community/tungsten-connector as well as in a recent blog article (http://scale-out-blog.blogspot.com/2008/05/myosotis-connector-fast-sql-proxy-for.html). Currently the proxy is a simple native wire protocol to JDBC proxy, written in Java. However, we are adding logic to allow you to add plug-ins. We have a lot of experience with the proxying issues you mention as our sequoia project does something similar.

    Please have a look and contact me if you have further questions. Meanwhile, good luck with HSCALE.

    Cheers, Robert

  11. René Leonhardt Says:

    Intelligent connection pooling can boost performance quite a bit.
    I hope the folks from Drizzle will work together with MySQL Proxy to keep MySQL a valuable alternative to Oracle DRCP and FAN.
    http://www.slideshare.net/ZendCon/solving-the-c20k-problem-raising-the-bar-in-php-performance-and-scalability-presentation

Leave a Reply