Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

MagLev Alpha Released: A New, Scalable Ruby Implementation

By Peter Cooper / November 21, 2009

maglev.pngMagLev is a new(ish) Ruby implementation built by Gemstone Systems that focuses on providing an integrated object persistence layer and a distributed shared cache - a truly scalable Ruby implementation. Maglev has, however, had an air of vaporware about it, having been hyped up in early 2008 and only available to a small group of alpha testers till now. That changes today with the first public, alpha release!

Back in early 2008, MagLev program manager Bob Walker did an interview with InfoQ about the project where he said that 8 people were working on MagLev, so this is a pretty big deal for them. Developer Avi Bryant then did a short presentation at RailsConf 2008 where he gave a comprehensive overview of what MagLev is along with some live demonstrations.

Why Should You Care?

In short, MagLev is cool for a few reasons. Two key ones being that 1) MagLev runs on the SmallTalk virtual machine which, it is claimed, should yield significant performance increases for a language like Ruby, and 2) a MagLev environment allows multiple Ruby processes over multiple machines (if you wish) to use the same objects simultaneously for easy scalability. Avi's video is great if you want to get a grasp on it:

MagLev presentation at RailsConf 2008 from Monty Williams on Vimeo.

Developer Monty Williams is keen to stress that this is an alpha, not a beta, so you can't expect it to run Rails or any gems that require C extensions. That said, it does run Sinatra, Rack, and RubyGems, plus a significant effort has been put into passing the RubySpec, so it's not as if it's a crippled implementation as such.

If you want to learn more, consider following the MagLev team on Twitter @MagLev and checking out the official mailing list "maglev-discussion."

Installation (i.e. getting to an irb prompt that works)

Bear in mind that MagLev will only work on 64 bit versions of OS X, Linux, and Solaris, so if you're in the 32 bit club, there's no point in going any further (yet).

If you download the MagLev Installer script (small ZIP file), you can run the installMaglev.sh script and install the latest version like so:

./installMaglev.sh 22578

The announcement post doesn't make it clear you need to provide a version number of what version number to provide. 22578 was mentioned earlier in the day though, and it seems to work.

Once installed, MagLev provides some info about environment variables you need to add to your .bashrc or .bash_profile. Follow these, then open a new terminal and here's how you get to an irb session:

$ maglev start
startnetldi[Info]: Starting GemStone network server "gs64ldi".
startnetldi[Error]:  could not start server
startstone[Info]: Starting Stone repository monitor "maglev".
startstone[Info]: GemStone server 'maglev' has been started.

$ maglev-irb
irb(main):001:0> 20 + 20
=> 40
irb(main):002:0> exit
error , SystemExit Error,  nil,
          during /Users/peter/Downloads/MagLev-installer/MagLev-22578.MacOSX/bin/maglev-irb
SystemExit Error,  nil

Alternatively: GitHub installation

MagLev is also available from GitHub to clone. To install MagLev from GitHub:

git clone git://github.com/MagLev/maglev.git
cd maglev
./install.sh

.. then follow the note about adding the path to your .bashrc or .bash_profile and running Rake in a new prompt (though still under the maglev project directory).

If you get any further with doing something interesting like, say, getting an IRB prompt up successfully on this, do post a comment ;-)

caliper-logo.png[ad] Find duplication, code smells, complex code and more in your Ruby code with Caliper! The metrics are free and setup takes just one click. Get started!

Comments

  1. Monty Williams says:

    Hi Peter,

    Ruby 186p287 isn't required required for most users. We need it internally because we have to bootstrap the parser and other low level initialization tasks. But the parser is committed to the repository as part of the build, so no specific MRI version is needed. You do need Rake installed, but any implementation of Rake should suffice.

    What problem did you hit with the non-github installer? If anyone else hits a problem please post in the discussion group. Let us know what OS. Note: A 256 MB slice is too small unless you reduce some of the cache settings. That's been covered in the discussion group.

  2. Monty Williams says:

    P.S. MagLev runs on Snow Leopard just fine. If anyone has problems getting MagLev installed, please let us know.

  3. Peter Cooper says:

    When I ran the installer it said it needed a version number. So I added the version number mentioned in the example to the command and it tried to download but couldn't find it. I discovered valid version numbers elsewhere but didn't try with those before I went the Github route. Example of using the installer:

    [03:45:41 ~/Downloads/MagLev-installer]$ ./installMaglev.sh
    [Error] The upgradeToMaglev.sh command must have one argument
    i.e. upgradeToMaglev.sh [version_string]
    e.g. upgradeToMaglev.sh 22130

    If you can clear that up, I'll fix the post.

    After the install and running the rake task, I seem to have some MagLev stuff running. maglev stop only stops one portion of that. maglev start complains it requires Ruby 1.8.6p287. I can't figure out how to really get anywhere beyond that, but I haven't had time to go through the mailing list to figure it out yet.. got a baby to look after :-)

    If you can provide links or a basic step 1, step 2, step 3 for getting to an irb prompt, I'll get it up here and I'm sure readers would love it :-)

  4. Peter Cooper says:

    I've got installMaglev.sh working by putting version number 22578 on the end. The installer script doesn't make it clear that's what's necessary (and it's only a guess on my part based on a post earlier in the day that mentions that version #). I've updated the post anyway to cover this, as well as removing the part about Ruby 1.8.6p287.

    I'm going to see if this other install does better in terms of getting to irb :-)

  5. Peter Cooper says:

    Hurrah! Installing 22578 from the installMaglev.sh script has been a lot more successful. maglev start did its work (though had one minor error):

    startnetldi[Info]: Starting GemStone network server "gs64ldi".
    startnetldi[Error]:  could not start server
    startstone[Info]: Starting Stone repository monitor "maglev".
    startstone[Info]: GemStone server 'maglev' has been started.

    But after that, maglev-irb gets to an irb prompt :-)

  6. Peter Cooper says:

    Post updated with info on how to get to irb. Works for me now.

  7. Monty Williams says:

    No problem. I shoulda mentioned the current version number.

    There are some docs in the html directory or at
    http://maglev.gemstone.com/html/

    Here's the suggested install steps for the non-github version.

    mkdir MagLev
    cd MagLev

    ./installMaglev.sh 22578 # or later version number

    cd $MAGLEV_HOME
    rake maglev:start
    # you can also use "maglev start", which doesn't use the rakefile
    # and thus can be run from anywhere

    # To get an IRB prompt
    maglev-irb

    # to run a ruby program
    maglev-ruby fib.rb # assuming you have a fib.rb of course

    # to shut down the server
    rake maglev:stop
    # you can also use "maglev stop"

    # If you see a tweet about a new version, you can use
    ./upgradeMaglev.sh
    # instead of installMaglev.sh.

    Here are a couple of other simple nuggets to try while in $MAGLEV_HOME:
    spec/mspec/bin/mspec spec/rubyspec/language/and_spec.rb
    rake bench:file FILE=benchmark/benchmarks/micro-benchmarks/bm_app_fib.rb

    For more complex examples check the docs and READMEs

  8. Peter Cooper says:

    Awesome, the bit getting to irb matches up with what I've discovered - cool! Thanks for providing the extra info.

  9. grantmichaels says:

    monty -

    it's really exciting to see this out! i recall like it was yesterday when you first emailed me to "watch this space" ... it's a little bit insane to think that it's got to be fully a year and a half ago, or more ... oh, it's still gorgeous in florida =)

    congrats,
    grantmichaels

  10. Peter Cooper says:

    Perhaps I'm being dumb but I rigged up the same "hat" thing that Avi did but both of my IRB sessions have totally different $hat contents. I'm guessing there's no syncing happening, though am not sure how to resolve that. I'll go check out those docs you mentioned ;-)

  11. Peter Cooper says:

    Seems some things have changed. Noted in the docs:

    1. Unmodified MRI code, when run on MagLev, runs just like in MRI.
    2. Explicit action is necessary to take advantage of MagLev persistence

    So if anyone's trying to follow along with that video, don't. Check out the documentation and look at the examples :-)

  12. Peter Cooper says:

    Specifically this page on persistence will get you up to speed with having two IRBs and moving objects around. You have to make sure the class is persisted, but also do commit_transaction in each place to see the updates..

  13. Peter Cooper says:

    FWIW, some very patchy benchmarks using the "fannkuchen" benchmark I'm keen on lately:

    1.8.7 - 6.276s
    1.9.1 - 3.539s
    MagLev Alpha - 2.975s
    MacRuby 0.5b2 - 4.649s
    MacRuby 0.5b2 (compiled) - 2.901s
    JRuby 1.4.0 (basic) - 5.579s

    Always remember to take benchmarks with a pinch of salt. I only ran these for my own curiosity.

  14. Monty Williams says:

    The netldi isn't needed except for remote sessions. There are sometimes issues starting it if you're not a static network, or are on VPN, or change networks :-(

    You're right -- the persistence API has evolved since the Avi hat trick movie. There is a version of the hat trick in examples/hat_trick, and more complex persistence examples in examples/mdb & examples/persistence/kdtree

    You can run most benchmarks in the RBS suite using rake. See "rake -T bench" or the docs.

  15. Sho says:

    I also ran some initial benchmarks using Sinatra/webrick (no other web servers supported that I know of).

    Ruby 1.8.7: Requests per second: 131.38
    Ruby 1.9.1: Requests per second: 144.77
    Maglev: Requests per second: 97.78

    I basically think that any benchmarks that are not using actual real world applications that people are actually using are bunk.

  16. Peter Cooper says:

    Sho: Not always. I think they can be useful to get a general impression, though the accuracy is poor. It's useful to know, at least, that Maglev isn't 50 times slower than MRI or whatever though, and even basic benchmarks can give us an indication of very general levels of performance.

  17. Wayne E. Seguin says:

    Monty,

    Several users of my rvm tool (http://rvm.beginrescueend.com/) have requested that MagLev be added to it. Can you join #rvm on irc.freenode.net sometime and chat with me about it? (http://webchat.freenode.net/?channels=rvm)

    Another user is concerned that it would conflict with MagLev's license. So I at least have a few questions pertaining to that aspect.

    Thank you very much!

    ~Wayne

  18. TheRealQuestion says:

    The real question is how expensive MagLev will be. From what I understand, MagLev is free but the runtime required to run it (GemStone) is not. That may be a nonstarter for most folks.

  19. Monty Williams says:

    We have a number of people running commercial sites using Seaside (http://seaside.gemstone.com/) on a free version of GemStone. We haven't settled on the best strategy for MagLev, but I expect it'll be similar http://seaside.gemstone.com/

    Other possibilites include paying for service & support, hosting, etc. But there will be some way for you to use it at no charge.

  20. Monty Williams says:

    Oops. I pasted the wrong URL. The link to the GemStone Seaside pricing model should have been http://bit.ly/5qxOYb

Other Posts to Enjoy

Twitter Mentions