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
large table slow and inconsistent insert performance #1385
Im inserting docs from a realtime stream that is about 2k docs/minute with each doc between 0.4k and 1k in size ... after growing to about 30M docs, performance tanks. it swings between ~40 docs/sec and ~800 docs/sec for about 5 minutes each. I've got 4 clients performing one insert at a time, each pulling off of a queue and pushing into rethinkdb. While the machine is typically constantly loaded it has no problem with other things, for instance we're also testing mongo on the same box under the same workload and it keeps up just fine.
i did have zone_recliam_mode set to 0 (it is a NUMA box). i've since turned that to 1 because of the way rethinkdb works - I thought running out of space in a zone could have been causing trouble. this didn't fix the problem.
mongo was able to maintain a steady rate of about 2k docs per sec under the same load while running on the same box. turning off the mongo testing didn't seem to help either (not resource contention).
there are no indexes on the table other than primary key (which is generated on insert) and my clients are python.
We're presently in the process of setting up long running performance tests to weed out issues such as this one. #1369 describes the first workload we're going to focus on which seems to be similar enough to this workload that it should uncover whatever problem it is you're hitting. This should get better withing the next few releases. One question I have is how long has the server actually been running? Judging from your numbers here (30M docs and 2K/minute) it seems like it's probably been up for about 10 days. Is that about right?
What's your cluster setup? How many nodes, how shards on the table, how many replicas, how many write acks?
Is there an obvious bottleneck on the machine running RethinkDB? Is CPU utilization at 100%, for instance, or is the disk throughput saturated?
Is there an obvious bottleneck on the machine running the clients? If you restart the clients, do you see the same performance numbers?
How are you doing the writes? Are you sending one document at a time, or are you doing batched writes? Are you doing one connection per write, or sending them all through the same connection? If the former, are you closing the old connections?
Sorry for the barrage of questions, but it will make nailing down the performance problem much easier on our end.
Scheduling for 1.9.x; this is pretty bad performance on a pretty simple workload, so it should be easy and profitable to fix it sooner rather than later.
@jdoliner -- that's not 100% obvious to me; if it's bouncing between 10 and 200 writes/sec, then it might be able to hold steady at 60. Or it might not.
Which questions were answered in the original post? Re-reading, I see @underrun said "one insert at a time", but I don't see answers to the others.
Not 2k/sec 2k docs/minute ('m tracking long term stats with minute resolution not second). Though when the table was clean I started with a backlog and was able to handle 1k writes/sec with no problem til the backlog cleared out.
the feeder queue rate actually varies between 2k docs/min and 5k docs/min ... looks like the average over the past week (I'm at 37M rows after almost 8 days) has been closer to 3.5k docs/min - just for the couple hours I was monitoring it yesterday it was about 2k docs/min ... so actually the 60 / sec case would definitely fit this workload. My docs are typically a bit smaller - most coming in under 1k and I have no secondary indexes. but that other ticket's workload description would probably cover this pretty well.
Some answers:
SSD
soft
1 node 1 shard 1 replica 1 ack (tried it after rebalancing to 16 shards but that didn't seem to help either)
server cpu utilization is fine. iostat tells me disk utilization is steady at about 94% with fine throughput and low wait
no client bottleneck. restarting them didn't help.
4, 5 or 6 clients each have one connection they hold open and write one doc at a time. more clients seem to increase maximum throughput slightly during the 5 minute window of not crap performance. But 6 clients doesn't do any better than 1 for the 5 minutes window where performance tanks.
@underrun -- there is one thing I didn't understand about the issue. At even 5k/minute peak, that's about ~83 docs per second. How could performance go up to 800 docs/sec if the clients are only inserting an order of magnitude fewer docs at peak?
Also a few more questions:
How are you measuring RethinkDB performance? If you're looking at the admin page graph, there is a known issue with the graph underreporting performance. The performance monitoring code currently has a lower priority than query code, so RethinkDB drops some performance statistics requests at high load due to timeouts. The web UI then underreports performance because it treats missing data as zero. I'm wondering if this could be the culprit -- what happens if you measure the number of requests on the clients themselves?
I'm using external performance measurement for my per minute counts - i'm actually monitoring the queue that is feeding rethinkdb. whether or not the admin web page is underreporting performance, rethinkdb is not keeping up with my queue ... which is about 3k/min average, but it does dip and spike and with my perf resolution at the minute level, the instantaneous spikes could be quite large. Since my recorded data is per minute and the per second data i reported was observed at some point during the event I don't have a good way to reconcile the two.
Literally the performance graph of the per minute data looks like a square wave. With a wavelength of 10 minutes and at best about a 50% duty cycle. To top that off, looking at the performance over time, the oscillation is unstable with a steady maximum and decreasing average insert rate. It took about 12h to degrade to the point I described in this issue from when the square wave behavior started emerging.
I've got enough memory to try it with with a larger cache, but it took about a week to get to this point and unless I missed something I would have to recreate the table to change the cache size?
@underrun -- ok, this makes sense. Here's a quick hack to change the cache size (after 1.10 you won't have to do any of this, so thanks for bearing with us for now). If you point your browser to RETHINKDB_HOST:RETHINKDB_WEB_PORT/ajax (e.g. localhost:8080/ajax) you'll see a json document that describes the cluster. If you search for cache_size in that document you'll find its value, in bytes, on each table. All you have to do to change it, is to send a curl POST request with the new value, and restart the cluster.
Here's an example curl request to set the cache size on a table to 2GB:
curl -X POST -d '2147483648' http://192.168.0.145:8080/ajax/semilattice/rdb_namespaces/59f7b2ac-d923-46cc-8cc7-b6adae8b1602/cache_size -H "Content-Type: application/json" -f
(Note that you have to replace 59f7b2ac-d923-46cc-8cc7-b6adae8b1602 with the ID of your table, and 2147483648 with the cache size in bytes you want). Also, make sure to restart the machine because the new cache size doesn't currently take effect until restart.
It's actually going to be pain to pick your table's id out of the metadata unless you have a json parsing plugin installed in your browser. If you don't I'd recommend doing the following:
curl host:8080/ajax/semilattice/rdb_namespaces | python -mjson.tool | less
I'm seeing a similar square-wavey thing after inserting ~30m 2k documents with soft durability, wavelength of about a minute and average throughput of about 2k docs/sec. (The throughput at the start was closer to 6-8k/sec.) I'm seeing the square wave in the data explorer, but I don't think it's due to a stats timeout because the peaks of the wave correspond with high CPU usage, and the troughs with almost no CPU usage.
I talked to Slava and he mentioned that it might be because of how we flush dirty blocks in the buffer cache, and that @srh might have a way to improve that once he's done making env_t reentrant.
@danielmewes -- here is one idea you might not have thought of (I discussed it with @srh at some point). We can get rid of the flush lock without huge changes to the cache. The only reason we need a flush lock is that on flushes the cache can't just take locks on dirty blocks since it has no notion of b-tree ordering and locking in random order can cause a deadlock. If we change the cache api to accept information about relationships between blocks, the cache could lock dirty blocks in order and we can completely get rid of the flush lock. This sounds like an ideal solution to me. (@jdoliner implemented some functionality to pass rough information to the cache about the node level, but right now we only use it for page replacement; I suspect this functionality isn't strict at all times, which is ok for page replacement but not ok for locking). This might be relatively simple to do and is probably worth looking into.
@coffeemug: Thanks for the suggestion. I had discussed that before with @jdoliner and we decided that splitting batches was the easier solution for the moment.
This judgement was not without flaw as it turned out.
In the end it took me longer to implement than expected, which however was mostly due to my unfamiliarity with the query processing code and some of the assumptions on how transactions behave. My initial test implementation violated those assumptions. The other thing I did not fully consider at that time is that splitting the batches does have an impact on single-client performance because it adds latency. Due to this we cannot make the "sub batches" too small, making the solution less effective with respect to reducing flush lock waits.
We should certainly change the cache sooner or later. Acquiring locks in b-tree order is one option to remove the flush lock. I have also discussed another one with @srh which would actually allow us to flush individual transactions even if data got subsequently modified by another later transaction. This can have advantages if some of the writes have hard durability while other long-running write transactions are active. The basic idea is to take a pro-active snapshot whenever a write transaction releases a block, or alternatively before it acquires a block.
Say we have two transactions t1 and t2, and t1 comes in first, followed by t2.
t1 modifies a block b, followed by t2 modifying the same block b.
Then t1 finishes, but t2 is not yet done and still holds locks in the tree (it might want to modify more blocks).
With both our current flush lock as well as with acquiring blocks in b-tree order during the writeback, we would now have to wait until t2 finishes before we can flush the changes made by t1. However if we have a snapshot of b just after t1 released it (or just before t2 acquired it, which is the same semantically), we can write exactly the state after t1's completion. t2 will be included in a later writeback once it is done, but it will not block flushing any earlier transactions.
I think it makes sense to plan, implement and test this very carefully. This unfortunately will take some time. Until then the batch-splitting work-around should do the job in many use cases.
Addition: After re-reading @underrun 's original problem description, I should point out that the original problem was with non-batched inserts, so the batch splitting will actually not have an impact on that scenario.
We still have to fix the stalls in @mlucy's insert workload and the splitting does improve that one.
This might be a good time to re-visit the throttling hypothesis. Some throttling improvements are already in next, and I will check how much difference they make now that we have gotten (most of) the flush lock stalls out of the way.
Moving this from point milestone to subsequent. @danielmewes made a bunch of changes around this, and will do more. Given what we know, this issue don't belong in the point release.
Status: This problem is still there to some degree. I will have to re-evaluate it again when the new cache is in, because that will change related things.
I'm seeing very consistent performance on RethinkDB 1.12.
@underrun Sorry this issue took so long to get completely resolved. If you are still having this problem, I recommend upgrading to RethinkDB 1.12 and retesting it.
Activity
underrun commentedon Aug 29, 2013
now its bouncing between 10 writes per sec and 200 writes per sec ...
jdoliner commentedon Aug 29, 2013
We're presently in the process of setting up long running performance tests to weed out issues such as this one. #1369 describes the first workload we're going to focus on which seems to be similar enough to this workload that it should uncover whatever problem it is you're hitting. This should get better withing the next few releases. One question I have is how long has the server actually been running? Judging from your numbers here (30M docs and 2K/minute) it seems like it's probably been up for about 10 days. Is that about right?
mlucy commentedon Aug 29, 2013
This seems different from that workload -- 2k writes/sec and 60 writes/sec aren't really in the same ballpark.
@underrun --
Sorry for the barrage of questions, but it will make nailing down the performance problem much easier on our end.
mlucy commentedon Aug 29, 2013
Scheduling for 1.9.x; this is pretty bad performance on a pretty simple workload, so it should be easy and profitable to fix it sooner rather than later.
jdoliner commentedon Aug 29, 2013
@mlucy we'd definitely notice with that workload if performance on a table fell to 10 writes per second after you got 30M docs in it.
jdoliner commentedon Aug 29, 2013
@mlucy a lot of questions you're asking are answered in the original post.
mlucy commentedon Aug 29, 2013
@jdoliner -- that's not 100% obvious to me; if it's bouncing between 10 and 200 writes/sec, then it might be able to hold steady at 60. Or it might not.
Which questions were answered in the original post? Re-reading, I see @underrun said "one insert at a time", but I don't see answers to the others.
mlucy commentedon Aug 29, 2013
Actually, moving to 1.10 just so that all the performance issues are in one milestone.
underrun commentedon Aug 30, 2013
Not 2k/sec 2k docs/minute ('m tracking long term stats with minute resolution not second). Though when the table was clean I started with a backlog and was able to handle 1k writes/sec with no problem til the backlog cleared out.
the feeder queue rate actually varies between 2k docs/min and 5k docs/min ... looks like the average over the past week (I'm at 37M rows after almost 8 days) has been closer to 3.5k docs/min - just for the couple hours I was monitoring it yesterday it was about 2k docs/min ... so actually the 60 / sec case would definitely fit this workload. My docs are typically a bit smaller - most coming in under 1k and I have no secondary indexes. but that other ticket's workload description would probably cover this pretty well.
Some answers:
coffeemug commentedon Aug 30, 2013
@underrun -- there is one thing I didn't understand about the issue. At even 5k/minute peak, that's about ~83 docs per second. How could performance go up to 800 docs/sec if the clients are only inserting an order of magnitude fewer docs at peak?
Also a few more questions:
underrun commentedon Sep 3, 2013
I'm using external performance measurement for my per minute counts - i'm actually monitoring the queue that is feeding rethinkdb. whether or not the admin web page is underreporting performance, rethinkdb is not keeping up with my queue ... which is about 3k/min average, but it does dip and spike and with my perf resolution at the minute level, the instantaneous spikes could be quite large. Since my recorded data is per minute and the per second data i reported was observed at some point during the event I don't have a good way to reconcile the two.
Literally the performance graph of the per minute data looks like a square wave. With a wavelength of 10 minutes and at best about a 50% duty cycle. To top that off, looking at the performance over time, the oscillation is unstable with a steady maximum and decreasing average insert rate. It took about 12h to degrade to the point I described in this issue from when the square wave behavior started emerging.
I've got enough memory to try it with with a larger cache, but it took about a week to get to this point and unless I missed something I would have to recreate the table to change the cache size?
coffeemug commentedon Sep 3, 2013
@underrun -- ok, this makes sense. Here's a quick hack to change the cache size (after 1.10 you won't have to do any of this, so thanks for bearing with us for now). If you point your browser to
RETHINKDB_HOST:RETHINKDB_WEB_PORT/ajax(e.g.localhost:8080/ajax) you'll see a json document that describes the cluster. If you search forcache_sizein that document you'll find its value, in bytes, on each table. All you have to do to change it, is to send a curl POST request with the new value, and restart the cluster.Here's an example curl request to set the cache size on a table to 2GB:
(Note that you have to replace
59f7b2ac-d923-46cc-8cc7-b6adae8b1602with the ID of your table, and2147483648with the cache size in bytes you want). Also, make sure to restart the machine because the new cache size doesn't currently take effect until restart.Sorry for the complex instructions.
jdoliner commentedon Sep 3, 2013
It's actually going to be pain to pick your table's id out of the metadata unless you have a json parsing plugin installed in your browser. If you don't I'd recommend doing the following:
and picking it out from the output.
mlucy commentedon Sep 6, 2013
I'm seeing a similar square-wavey thing after inserting ~30m 2k documents with soft durability, wavelength of about a minute and average throughput of about 2k docs/sec. (The throughput at the start was closer to 6-8k/sec.) I'm seeing the square wave in the data explorer, but I don't think it's due to a stats timeout because the peaks of the wave correspond with high CPU usage, and the troughs with almost no CPU usage.
I talked to Slava and he mentioned that it might be because of how we flush dirty blocks in the buffer cache, and that @srh might have a way to improve that once he's done making
env_treentrant.29 remaining items
coffeemug commentedon Oct 3, 2013
@danielmewes -- here is one idea you might not have thought of (I discussed it with @srh at some point). We can get rid of the flush lock without huge changes to the cache. The only reason we need a flush lock is that on flushes the cache can't just take locks on dirty blocks since it has no notion of b-tree ordering and locking in random order can cause a deadlock. If we change the cache api to accept information about relationships between blocks, the cache could lock dirty blocks in order and we can completely get rid of the flush lock. This sounds like an ideal solution to me. (@jdoliner implemented some functionality to pass rough information to the cache about the node level, but right now we only use it for page replacement; I suspect this functionality isn't strict at all times, which is ok for page replacement but not ok for locking). This might be relatively simple to do and is probably worth looking into.
danielmewes commentedon Oct 3, 2013
@coffeemug: Thanks for the suggestion. I had discussed that before with @jdoliner and we decided that splitting batches was the easier solution for the moment.
This judgement was not without flaw as it turned out.
In the end it took me longer to implement than expected, which however was mostly due to my unfamiliarity with the query processing code and some of the assumptions on how transactions behave. My initial test implementation violated those assumptions. The other thing I did not fully consider at that time is that splitting the batches does have an impact on single-client performance because it adds latency. Due to this we cannot make the "sub batches" too small, making the solution less effective with respect to reducing flush lock waits.
We should certainly change the cache sooner or later. Acquiring locks in b-tree order is one option to remove the flush lock. I have also discussed another one with @srh which would actually allow us to flush individual transactions even if data got subsequently modified by another later transaction. This can have advantages if some of the writes have hard durability while other long-running write transactions are active. The basic idea is to take a pro-active snapshot whenever a write transaction releases a block, or alternatively before it acquires a block.
Say we have two transactions t1 and t2, and t1 comes in first, followed by t2.
t1 modifies a block b, followed by t2 modifying the same block b.
Then t1 finishes, but t2 is not yet done and still holds locks in the tree (it might want to modify more blocks).
With both our current flush lock as well as with acquiring blocks in b-tree order during the writeback, we would now have to wait until t2 finishes before we can flush the changes made by t1. However if we have a snapshot of b just after t1 released it (or just before t2 acquired it, which is the same semantically), we can write exactly the state after t1's completion. t2 will be included in a later writeback once it is done, but it will not block flushing any earlier transactions.
I think it makes sense to plan, implement and test this very carefully. This unfortunately will take some time. Until then the batch-splitting work-around should do the job in many use cases.
danielmewes commentedon Oct 3, 2013
The batch splitting code is in review 970.
danielmewes commentedon Oct 3, 2013
Addition: After re-reading @underrun 's original problem description, I should point out that the original problem was with non-batched inserts, so the batch splitting will actually not have an impact on that scenario.
We still have to fix the stalls in @mlucy's insert workload and the splitting does improve that one.
This might be a good time to re-visit the throttling hypothesis. Some throttling improvements are already in next, and I will check how much difference they make now that we have gotten (most of) the flush lock stalls out of the way.
coffeemug commentedon Nov 30, 2013
Moving this from point milestone to subsequent. @danielmewes made a bunch of changes around this, and will do more. Given what we know, this issue don't belong in the point release.
danielmewes commentedon Jan 6, 2014
Status: This problem is still there to some degree. I will have to re-evaluate it again when the new cache is in, because that will change related things.
danielmewes commentedon Feb 22, 2014
Have to re-test to see if we can finally close it. Moving to 1.12-polish.
danielmewes commentedon Apr 4, 2014
I'm seeing very consistent performance on RethinkDB 1.12.
@underrun Sorry this issue took so long to get completely resolved. If you are still having this problem, I recommend upgrading to RethinkDB 1.12 and retesting it.