Repository navigation
Closed
Labels
Milestone
Description
Currently if you want to work with 100,000 records it is extremely slow:
$ python foo.py
count is 164717
int query took 4086ms
4 seconds to query 164,000 rows! I dug into this a little bit using the python library yappi and the tool kcachegrind to see where it was spending the time. Here is the python code I used:
import rethinkdb as r
import random
import pytz
import time
import yappi
from datetime import datetime
UTC = pytz.utc
YAPPI = False
DO_CREATE = False
DO_INSERTS = False
conn = r.connect()
if DO_CREATE:
r.table_create('test').run(conn)
START_BIGINT = 100000000000000000
END_BIGINT = 999999999999999999
def utc_now():
now = datetime.utcnow()
tz_now = now.replace(tzinfo=UTC)
return tz_now
def get_rint(start=1000000, end=9999999):
"""
Generate a very large integer
:return:
"""
return random.randint(start, end)
def get_bigint():
"""
Generate a random BIGINT
:return:
"""
return get_rint(start=START_BIGINT, end=END_BIGINT)
if DO_INSERTS:
for i in range(0, 300000):
r.table('test').insert({
'respondent_id': get_bigint(),
'row_id': get_bigint(),
'column_id': get_bigint(),
'value_id': get_bigint(),
'rid1': get_bigint(),
'rid2': get_bigint(),
'rid3': get_rint(),
'now': utc_now()
}).run(conn)
start = time.time()
if YAPPI:
yappi.set_clock_type('cpu')
yappi.start(builtins=True)
result = r.table('test').run(conn)
data = []
for row in result:
data.append(row)
count = len(data)
end = time.time()
if YAPPI:
stats = yappi.get_func_stats()
stats.save('callgrind.out', type='callgrind')
print('checkout callgrind.out')
print("count is %s" % count)
duration = int(1000 * (end - start))
print("int query took %sms" % duration)and this showed that most of the time is spent in recursively_convert_pseudo_types, here is a screenshot of the kcachegrind:

Activity
danielmewes commentedon Jul 23, 2015
Thank you for the script and data @sontek !
We'll look into it and see if we can optimize that function.
deontologician commentedon Jul 23, 2015
One avenue might be to write a custom JSONDecoder that does pseudotype conversion at parse time. If we did that it would open the door to #3506
sontek commentedon Jul 23, 2015
Yeah, I think having a JSONDecoder will be a great approach (I've monkeypatched it to use simplejson to get 5% perf boost) but until we convert that function to use a while loop instead of recursion then JSON actually isn't the slow part yet
deontologician commentedon Jul 23, 2015
I was thinking in lieu of having the recursive function at all. So it would do the work of that recursive function during the initial parse. Right now it does everything in two passes, the second one being slow because of function call overhead in the recursive pseudotype conversion
sontek commentedon Jul 23, 2015
So I changed the query to be:
so skip the slow function and it shaved off 50% of my time but was still pretty slow so there are some other gains to be had in other areas:
coffeemug commentedon Aug 24, 2015
For anyone watching this thread, we're doing an on-the-wire performance test (without the Python driver) to figure out baseline server performance for this workload. Once we get this information, it will be relatively easy to figure out what we need to do to fix this.
danielmewes commentedon Aug 25, 2015
The raw server performance for a single client reading the data, measured without any parsing on the client-side, is approximately 0.8 seconds per 100,000 documents.
This is using the documents generated by the script above, just slightly modified to store a more compact unix timestamp rather than a ReQL date/time object in the
nowfield.In this test, all data gets transferred to the client, but the client doesn't parse the response (except for a small header).
@sontek would that be fast enough or do you need higher single-client throughput?
I imagine that we might be able to do some more tuning on the server side for this workload.
sontek commentedon Aug 25, 2015
@danielmewes Does that scale out linearly? Whats it at for 50,000 and 500,000? I think 0.8 seconds would be acceptable as long as the python driver overhead wasn't adding much on top of that. Another thing we could look at is building out an async query model like:
So if we know the queries scale linearly we can asynchronously spawn the queries off to get the desired query speed. So if there are 200k results set, in that example I would still expect to wait no more than 0.8 seconds to get the data.
13 remaining items
danielmewes commentedon Sep 14, 2015
For the
between, we tested with splitting the queries up by primary index rather than by using a secondary index. Not sure if that explains the difference.coffeemug commentedon Sep 14, 2015
Also note that this use case (returning a large resultset) isn't yet well parallelizable across shards. We're working on this now, and it will go into 2.2 (due out in about a month). So right now you won't see the benefit of sharding on this use case, but you will see a large benefit after 2.2 is out.
sontek commentedon Sep 18, 2015
After talking with @danielmewes a bit yesterday I tried to do a few benchmarks:
This is my results:
You can see it pretty much always slows down from 1 to 4 nodes, here is the actual data:
This is the code:
I have a secondary index on
survey_id.Here is a google drive excel document with the numbers in it:
https://docs.google.com/spreadsheets/d/1kfyt9DjYrZwXowCVx4eSA7kLUrgK6oYvgbmtoOnXsTE/edit?usp=sharing
sontek commentedon Sep 18, 2015
I'm not able to reproduce that 500ms per 100k resultsets you were able to get. The fastest I'm able to get is with the threaded worker which gets be down to 11seconds for 1million records
danielmewes commentedon Sep 18, 2015
The difference in performance could be because of hardware differences. We'll re-test this with a configuration closer to yours.
danielmewes commentedon Nov 17, 2015
I'm marking this closed. The prominent inefficiencies in the Python driver have been addressed in the past few releases.
@sontek I'll contact you directly in the next days regarding any additional testing and/or bottlenecks.