Thursday, November 01, 2012

OrientDB: huge improvement in performance (+9,000%) in many use cases. Thanks RaspberryPi !



Hi all,
today I've a good story to tell you. A couple of days ago Fabrizio Fortino sent to me an email with some metrics and screenshots about the profiling of an in-production instance of OrientDB. Well, a lot of time was spent on open/close of database. 

That was the issue 1145 (http://code.google.com/p/orient/issues/detail?id=1145) but I assigned to it a low priority because it was an improvement, not a real bug...

Well today I'm hacking with a Raspberry PI cheap HW and OrientDB to see if it could be used in production for some limited use cases. Well on this kind of HW everything is much-much slower! "Yeah, it's normal: I have a $35 HW, Java is not so optimized yet on this ARM platform, etc.". This were my firsts thoughts about the initial results.

But after some profiling I was arrived at the same conclusion of Fabrizio, so I decided to spend 2 hours of my life to investigate in deep.

Well, I've just committed a small patch (r7134) that avoids to open a database every time a database is re-used from the pool. In facts this is a quite costly operation, specially if you do many small atomic operation where most of the cost is in open/close that in the operation itself!

This fix improved a lot these scenarios:
  • Usage via HTTP/Rest, because a new connection is acquired every time from the pool at every operation
  • Java Web Applications where at the server side you used the database pool
  • you wrote a Java App that every time creates a new instance of a database. if this is your case I strongly encourage using the database pool that at this time is much faster
  1. in case metadata changes (schema, security, functions) you would need to invoke a reload() to get the changes
The improvement will be minor in the cases:
All these are PROS, what about CONS?
This is a simple load of a tiny document against a database on my pc:

$ ab -n1000 -A admin:admin -k -c10 http://localhost:2480/document/demo/71:1
...
Requests per second:    52.56 [#/sec] (mean)

$ ab -n1000 -A admin:admin -k -c10 http://localhost:2480/document/demo/71:1
...
Requests per second:    4694.57 [#/sec] (mean)

This is 90x faster, namely 9,000%, namely a huge improvement!

Now it's funny that OrientDB on the Raspberry PI, with the new patch, runs at a speed quite close to my PC I used everyday to work before this patch!

12 comments:

Lu said...

Are you using the Raspberry via command line or with a GUI? If you use it via command line, maybe is possible to increase the hardware performance. In fact the Raspberry Pi has 256Mb (or 512Mb for later versions) of RAM; this RAM is however shared between the graphics and main system memory.

By default 64Mb is allocated to graphics. This is overkill if you don’t plan to run the graphical interface (or rarely) as in the case of a server. To reduce the amount of memory available for graphics to 32MB enter the following command.

sudo cp /boot/arm224_start.elf /boot/start.elf, or use sudo raspi-config to do this using the config menu

(you can restore the previous configuration sudo cp /boot/arm192_start.elf /boot/start.elf )

Luca Garulli said...

I've turned off any GUI, and dedicated only 32MB to the graphic card, then I've overclocked it to try if it's stable. Well, seems yes.

Can I overclock up to 950Mhz without increasing the power? It's not about warranty but for the life of my Rspberry.

Lu said...

Overclock a Raspberry has limited side-effects but if you do it then you need to increase the power and I suggest you to use a good power source like Kindle or iPhone official charger. Economic charger can create problems.

Luca Garulli said...

Yesterday I bought a 1A power adapter because my previous one was slightly less (Samsung). But usually for such kind of stuff the CPU is not so important like the I/O and do you know a way to have a better I/O? I already have a Sandisk SD class 10 20Mb/sec but seems not so better than a class 4 as throughput.

Lu said...

Mhhh... i was wondering to increment the I/O speed too because I agree with you that the real bottleneck is there. I still have to experiment this, anyway the Raspberry Pi (at least the model B) has two USB 2.0 wich goes at 60 MB/s approximately so we can boot from the USB using this istructions: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=9117&p=112959

You should go 3 time faster i think :)

Luca Garulli said...

60 MB/sec is not so bad. I always believed the SD was faster than USB 2, but I will give it a try.

Lu said...

You can find professional SD Cards with a better I/O speeds but they are expensive and not done to be used as hard drive. With a significant number of I/O (like the OS activity) in fact, the lifecycle of the card decrease significantly. There are some ways to increase an SD life but they puts you in a non-performing condition:

http://raspberrypi.stackexchange.com/questions/169/how-can-i-extend-the-life-of-my-sd-card

Luca Garulli said...

Thanks for your suggestions! With last benchmarks OrientDB on a RaspberryPi handles about 60 requests/sec! I will try with a USB HD if it's even better.

Lu said...

Let me know, i m curious! :D

Ellis said...

Luca,

I sell copper heat sinks for the Raspberry Pi. I call them PiSinks.

Unknown said...
This comment has been removed by a blog administrator.
Unknown said...
This comment has been removed by a blog administrator.