Skip to content

Test point insert/read/update performance (in Ruby, but also elsewhere) #1798

Closed

Description

@coffeemug

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.

See the code at https://github.com/ajselvig/RubyDatabaseBenchmarks

Activity

  1. mlucy commented on Dec 26, 2013

    @mlucy
    Member

    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.

  2. danielmewes commented on Dec 27, 2013

    @danielmewes
    Member

    (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)

  3. danielmewes commented on Dec 27, 2013

    @danielmewes
    Member

    @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?

  4. coffeemug commented on Dec 28, 2013

    @coffeemug
    ContributorAuthor

    It seems that the bottleneck is in the protobuffer decoding.

    We should also double check that the server/driver are using JSON for result values instead of protobufs.

  5. danielmewes commented on Dec 30, 2013

    @danielmewes
    Member

    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.

  6. danielmewes commented on Dec 30, 2013

    @danielmewes
    Member

    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.

  7. mlucy commented on Jan 2, 2014

    @mlucy
    Member

    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.

  8. ghost assigned on Jan 2, 2014
  9. coffeemug commented on Jan 3, 2014

    @coffeemug
    ContributorAuthor

    Note that this bottleneck should only appear when you're building queries in a loop rather than building one query and running it repeatedly.

    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).

  10. danielmewes commented on Jan 3, 2014

    @danielmewes
    Member

    @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.

  11. mlucy commented on Jan 3, 2014

    @mlucy
    Member

    Ah, I misunderstood what you were saying. Ignore my last post then.

  12. mlucy commented on Jan 3, 2014

    @mlucy
    Member

    Going to work on this right now.

  13. danielmewes commented on Jan 3, 2014

    @danielmewes
    Member

    Excellent. I will take care of writing similar benchmarks for the other client languages later.

  14. mlucy commented on Jan 3, 2014

    @mlucy
    Member

    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.)

  15. danielmewes commented on Jan 4, 2014

    @danielmewes
    Member

    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.

  16. 4 remaining items

  17. ghost assigned on Jan 4, 2014
  18. danielmewes commented on Jan 4, 2014

    @danielmewes
    Member

    @mlucy: Well it's pretty close to PHP without an optimized protocol buffer backend. Is there a native protocol buffer backend for Ruby?

  19. mlucy commented on Jan 4, 2014

    @mlucy
    Member
  20. mlucy commented on Jan 4, 2014

    @mlucy
    Member

    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:

    :: RethinkDB ::
    * rethinkdb 1.11.1-0ubuntu1~precise (GCC 4.6.3) (durability: soft)
    Total insert time: 3.96 seconds (504.9 inserts/second)
    Total read time: 3.6 seconds (556.0 reads/second)
    Total update time: 10.62 seconds (188.4 updates/second)
    
  21. mlucy commented on Jan 4, 2014

    @mlucy
    Member

    I added varint to our gemspec in review 1103 by @AtnNn .

  22. mlucy commented on Jan 4, 2014

    @mlucy
    Member

    I still want to look at this a little bit more, I bet we can get it higher.

  23. danielmewes commented on Jan 6, 2014

    @danielmewes
    Member

    @neumino just ported the benchmark to Node.js! It seems to be one of the most CPU efficient for these queries. Updated results:

    • JavaScript
    Insert: 873.743993010048 inserts/second
    Read: 1279.5905310300705 reads/second
    Update: 316.8065895770632 updates/second
    
    • Ruby (including @mlucy's optimization)
    Insert: 325.7 inserts/second
    Read: 428.9 reads/second
    Update: 164.3 updates/second
    
    • Python (without cpp protobuf backend, couldn't get it to run)
    Insert: 963.95674414 inserts/second
    Read: 1084.1272426 reads/second
    Update: 292.186557975 updates/second
    
    • and just for fun PHP-RQL
      • with cpp protobuf backend
    Insert: 803.58463969438 inserts/second
    Read: 1063.2924998441 reads/second
    Update: 289.70962652097 updates/second
    
    • without cpp protobuf backend
    Insert: 438.63670007221 inserts/second
    Read: 597.65483788184 reads/second
    Update: 211.33260237237 updates/second
    
  24. mlucy commented on Jan 8, 2014

    @mlucy
    Member

    The varint dependency is in next.

  25. coffeemug commented on Jan 8, 2014

    @coffeemug
    ContributorAuthor

    @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)

  26. mlucy commented on Jan 8, 2014

    @mlucy
    Member

    @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.

  27. coffeemug commented on Jan 10, 2014

    @coffeemug
    ContributorAuthor

    Moved.

  28. nviennot commented on Jan 10, 2014

    @nviennot
    Contributor

    Related: #1842

  29. mlucy commented on Jan 16, 2014

    @mlucy
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions