You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Test point insert/read/update performance (in Ruby, but also elsewhere) #1798
There are reports of really bad point op performance in Ruby (but possibly other clients) in 1.11. Most of the CPU time is spent on the client. I don't know if the cause is the benchmarking code, the client driver, or something else.
(side remark: the 'update' part of the mentioned benchmark fails with RethinkDB 1.11. The reason being that the document id is passed to get() as a single-element array. Adding a [0] makes it work)
@mlucy: I'v profiled the benchmark with ruby-prof (http://ruby-prof.rubyforge.org/).
The report is in /home/daniel/ruby-bench-ruby-prof.kcachegrind on newton. You can open it witch kcachegrind.
You can run the benchmark through ruby /home/daniel/RubyDatabaseBenchmarks/run.rb, and create a new profile through ruby /home/daniel/RubyDatabaseBenchmarks/profile.rb. Both scripts expect a RethinkDB server to be running on newton with port offset 23. They load the Ruby driver from my RethinkDB directory /home/daniel/rethinkdb/drivers/ruby/lib.
It seems that the bottleneck is in the protobuffer decoding. Should the Ruby driver be using a compiled/native Protocol Buffer implementation?
When I did the profiling I actually made a mistake and was apparently using an older version of the driver, that didn't use JSON for results.
A new profile, this time with JSON, is in /home/daniel/ruby-bench-ruby-prof-18.kcachegrind on newton. The client is still using ~85% of a core.
One thing in the Ruby driver that's apparently using quite some CPU is RPP.sanitize_context. Commenting the call to it in the function expr in shim.rb makes the benchmark run roughly 50% faster. @mlucy: Any thoughts on that?
PS: Also disabling it in rethinkdb.rb's RQL#initialize function adds another 25% or so of throughput.
It's almost certainly the call to caller that's slow rather than the call to sanitize_context. (Note that this bottleneck should only appear when you're building queries in a loop rather than building one query and running it repeatedly.)
I'll try switching it to use caller_locations on Monday and see if that's any faster. If it isn't, we should see if there's a way to capture context lazily (so we only do the expensive call when we need to print it). If that doesn't work, we should just stop capturing the context by default, which should make the problem go away.
@mlucy: I'm not sure what you mean by the call to caller. My understanding of Ruby is very limited as you know, but I don't see it getting called in sanitize_context, or is it? What I actually did in my change was to basically short-circuit sanitize_context to its else case. More specifically I replaced calls to sanitize_context by the arguments that were passed to it. E.g. I replaced sanitize_context(caller) by caller.
What definitely showed up in the profile was the .reject method which is used in sanitize_context, and a lot of regex matching things that originated from there.
Fixing sanitize_context is pretty easy (up in Review 1101). When I do so, I get about 320 inserts/second on Newton. When I switch to using noreply: true, I get about 935 inserts/second. So we're now spending about 2/3 of our time waiting for the server.
I can do some more optimization work on the Ruby driver if it turns out to still be slower than the others ( @danielmewes -- do you have a sense of how fast the others are? ), but I think at this point optimizing the server would be the best way to improve the iterated-point-insert workload.
(Also, @danielmewes , rethink_runner.rb in the directory you mentioned has you home directory hardcoded into the $LOAD_PATH. You might want to change that.)
Let me re-test this and the other clients, then we can decide which next steps we should take. I'm not sure out of my head how fast the other drivers are, but I feel like I've seen better numbers in the past for this kind of operation.
Also our performance still compares badly to Mongo's in this benchmark.
Oh! Actually, it looks like ruby-protocol-buffers doesn't use a native backend unless you also install the varint module, which we weren't. When I install that our performance goes to:
Alright, I think we've gnawed most of the meat off this bone. Closing in favor of #1842 and #1868; will re-open if Ruby performance is still lagging after doing both of those.
Activity
mlucy commentedon Dec 26, 2013
Bumping to 1.11.x; I'll take a look at this when I get back to check whether it's really easy to fix or not.
danielmewes commentedon Dec 27, 2013
(side remark: the 'update' part of the mentioned benchmark fails with RethinkDB 1.11. The reason being that the document id is passed to
get()as a single-element array. Adding a[0]makes it work)danielmewes commentedon Dec 27, 2013
@mlucy: I'v profiled the benchmark with ruby-prof (http://ruby-prof.rubyforge.org/).
The report is in /home/daniel/ruby-bench-ruby-prof.kcachegrind on newton. You can open it witch kcachegrind.
You can run the benchmark through
ruby /home/daniel/RubyDatabaseBenchmarks/run.rb, and create a new profile throughruby /home/daniel/RubyDatabaseBenchmarks/profile.rb. Both scripts expect a RethinkDB server to be running on newton with port offset 23. They load the Ruby driver from my RethinkDB directory /home/daniel/rethinkdb/drivers/ruby/lib.It seems that the bottleneck is in the protobuffer decoding. Should the Ruby driver be using a compiled/native Protocol Buffer implementation?
coffeemug commentedon Dec 28, 2013
We should also double check that the server/driver are using JSON for result values instead of protobufs.
danielmewes commentedon Dec 30, 2013
When I did the profiling I actually made a mistake and was apparently using an older version of the driver, that didn't use JSON for results.
A new profile, this time with JSON, is in /home/daniel/ruby-bench-ruby-prof-18.kcachegrind on newton. The client is still using ~85% of a core.
danielmewes commentedon Dec 30, 2013
One thing in the Ruby driver that's apparently using quite some CPU is
RPP.sanitize_context. Commenting the call to it in the functionexprin shim.rb makes the benchmark run roughly 50% faster. @mlucy: Any thoughts on that?PS: Also disabling it in rethinkdb.rb's RQL#initialize function adds another 25% or so of throughput.
mlucy commentedon Jan 2, 2014
It's almost certainly the call to
callerthat's slow rather than the call tosanitize_context. (Note that this bottleneck should only appear when you're building queries in a loop rather than building one query and running it repeatedly.)I'll try switching it to use
caller_locationson Monday and see if that's any faster. If it isn't, we should see if there's a way to capture context lazily (so we only do the expensive call when we need to print it). If that doesn't work, we should just stop capturing the context by default, which should make the problem go away.coffeemug commentedon Jan 3, 2014
Unfortunately this is what one would naively do if they were to sit down and write some code (it's nice that there is a temporary workaround, though).
danielmewes commentedon Jan 3, 2014
@mlucy: I'm not sure what you mean by the call to
caller. My understanding of Ruby is very limited as you know, but I don't see it getting called insanitize_context, or is it? What I actually did in my change was to basically short-circuitsanitize_contextto itselsecase. More specifically I replaced calls tosanitize_contextby the arguments that were passed to it. E.g. I replacedsanitize_context(caller)bycaller.What definitely showed up in the profile was the
.rejectmethod which is used in sanitize_context, and a lot of regex matching things that originated from there.mlucy commentedon Jan 3, 2014
Ah, I misunderstood what you were saying. Ignore my last post then.
mlucy commentedon Jan 3, 2014
Going to work on this right now.
danielmewes commentedon Jan 3, 2014
Excellent. I will take care of writing similar benchmarks for the other client languages later.
mlucy commentedon Jan 3, 2014
Fixing sanitize_context is pretty easy (up in Review 1101). When I do so, I get about 320 inserts/second on Newton. When I switch to using
noreply: true, I get about 935 inserts/second. So we're now spending about 2/3 of our time waiting for the server.I can do some more optimization work on the Ruby driver if it turns out to still be slower than the others ( @danielmewes -- do you have a sense of how fast the others are? ), but I think at this point optimizing the server would be the best way to improve the iterated-point-insert workload.
(Also, @danielmewes ,
rethink_runner.rbin the directory you mentioned has you home directory hardcoded into the$LOAD_PATH. You might want to change that.)danielmewes commentedon Jan 4, 2014
Let me re-test this and the other clients, then we can decide which next steps we should take. I'm not sure out of my head how fast the other drivers are, but I feel like I've seen better numbers in the past for this kind of operation.
Also our performance still compares badly to Mongo's in this benchmark.
4 remaining items
danielmewes commentedon Jan 4, 2014
@mlucy: Well it's pretty close to PHP without an optimized protocol buffer backend. Is there a native protocol buffer backend for Ruby?
mlucy commentedon Jan 4, 2014
@danielmewes I thought we were already using one? Our gemspec says we depend on https://github.com/codekitchen/ruby-protocol-buffers .
mlucy commentedon Jan 4, 2014
Oh! Actually, it looks like ruby-protocol-buffers doesn't use a native backend unless you also install the
varintmodule, which we weren't. When I install that our performance goes to:mlucy commentedon Jan 4, 2014
I added varint to our gemspec in review 1103 by @AtnNn .
mlucy commentedon Jan 4, 2014
I still want to look at this a little bit more, I bet we can get it higher.
danielmewes commentedon Jan 6, 2014
@neumino just ported the benchmark to Node.js! It seems to be one of the most CPU efficient for these queries. Updated results:
mlucy commentedon Jan 8, 2014
The varint dependency is in next.
coffeemug commentedon Jan 8, 2014
@mlucy -- how soon are you planning to do more on this issue? (I'm trying to figure out if it should remain in 1.11.x or if I should move it out)
mlucy commentedon Jan 8, 2014
@coffeemug -- I was saving this for a day where I'm sick of working on GMR. So maybe 1.12 would be more appropriate right now.
coffeemug commentedon Jan 10, 2014
Moved.
nviennot commentedon Jan 10, 2014
Related: #1842
mlucy commentedon Jan 16, 2014
Alright, I think we've gnawed most of the meat off this bone. Closing in favor of #1842 and #1868; will re-open if Ruby performance is still lagging after doing both of those.