Showing posts with label chain. Show all posts
Showing posts with label chain. Show all posts

Tuesday, January 13, 2009

Seven quiet facts

I didn't want to get involved, but Jan caught me in the tell-seven-things-about-you game. The rules:
  • Link your original tagger(s), and list these rules on your blog.
  • Share seven facts about yourself in the post - some random, some weird.
  • Tag seven people at the end of your post by leaving their names and the links to their blogs.
  • Let them know they’ve been tagged by leaving a comment on their blogs and/or Twitter.

seven
Here are the seven facts about me:
  1. Nobody among my parents and siblings speaks any foreign language. On the other hand, my wife speaks four languages, my sisters-in-law at least three each, and my father-in-law speaks seven languages fluently.
  2. English is my fourth language and I learned it at the age of 33. (Previous ones: Italian, Sardinian, French, and Spanish as my fifth one)
  3. I never had typing lessons. I type with only two (occasionally four) fingers.
  4. I learned SQL before English. I attended my first Oracle course five years before my first English lesson.
  5. I wrote a database query language in 1991. One of the application that I created with that interpreter is till running today.
  6. My first operating system was VMS, running on a Digital VAX 11-750. I still fondly remember that file system with integrated revision control.
  7. My favorite pastime is reading (mostly in English, but also in Italian and French). I have always a book with me, in case I get stuck in traffic, at the supermarket queue, or at the airport. During working days, I read one book per week. During weekends and vacation, one per day is quite common.

The seven invited ones:
  • Kaj Arnö, my boss, who offered me the job of my dreams in MySQL, writes in languages that he does not speak, and who will surely enjoy this new form of social networking.(done)
  • Barton George, one of the finest minds in the open source arena, who always enjoys a good challenge.(done)
  • Edona Nahi, my wife's third sister, who's attending a master in California.
  • Ivan Zoratti, my Italian colleague who enjoys his life abroad.
  • Monty Taylor, a fine open source enthusiast with an extensive culture that I would like to unveil.
  • Ronald Bradford, because he has a lot to say now, and I am curious to hear it.
  • Stefano Rodighiero, who shares my passion for Perl and has recently made me envious by writing a book that I would have liked to. (done)

Tuesday, May 27, 2008

Chaining Proxies

If you need to combine two scripts with MySQL Proxy you have three choices.
  • You can manually rewrite the two scripts (good luck!)
  • you can use the load-multi module to load scripts on demand;
  • or you can use the proxy chaining technique.

To chain two proxies, you need to start one Proxy with the first Lua script, pointing at the real backend, listening to a non-standard port. Then you start the second Proxy with the second Lua script, having the first proxy as a backend, and listening to the standard proxy port.
It's a difficult and error prone procedure. You would forget about it, unless there were an easy workaround. And indeed you can have such a workaround. Just use the chain_proxy script from MySQL Forge and use it with this simple syntax:
$ chain_proxy first_script.lua second_script.lua
When I made this script, I had the problem of handling the standard output for each proxy instance. The brute force solution is to start each instance in a separate terminal window, but that is less than optimal. It would be almost as much work as doing things manually.
Considering that usually I need the output of a Proxy session only for debugging and that I am a frequent user of GNU screen, I made this arrangement:
The script starts each proxy inside a separate screen. At the end, it gives the list of screens being used, and creates a customized script in /tmp/ to kill the chained proxies and remove the screens.
$ chain_proxy digits.lua loop.lua
proxy started on screen "second_proxy" using script "loop.lua" - pid_file : /tmp/proxy1.pid
proxy started on screen "first_proxy" using script "digits.lua" - pid_file : /tmp/proxy_chain1.pid
stop script is /tmp/proxy_chain_stop
There are screens on:
21257.first_proxy (Detached)
21258.second_proxy (Detached)
2 Sockets in /tmp/uscreens/S-gmax.
In this example, the two proxies are started in sequence, and the script gives information on what is going on. The output of "loop.lua" is in the "first_proxy" screen. To see it, I only need to do
$ screen -r first_proxy
When I am finished using the chained Proxy, I type
$ /tmp/proxy_chain_stop
There are screens on:
21257.first_proxy (Detached)
21258.second_proxy (Detached)
2 Sockets in /tmp/uscreens/S-gmax.

No Sockets found in /tmp/uscreens/S-gmax.
This script can also be implemented by redirecting the output of each proxy to a different file. YMMV. I like the screen solution better.

I will be speaking about this feature (and more) during my MySQL University session on advanced Lua scripting.