orientechnologies / orientdb

OrientDB is the most versatile DBMS supporting Graph, Document, Reactive, Full-Text and Geospatial models in one Multi-Model product. OrientDB can run distributed (Multi-Master), supports SQL, ACID Transactions, Full-Text indexing and Reactive Queries.
https://orientdb.dev
Apache License 2.0
4.73k stars 869 forks source link

Expand(out("edgeName")) VS Expand(out("edgeName").@RID) Performance Difference #3384

Closed brandonburkett closed 9 years ago

brandonburkett commented 9 years ago

Hello,

We have run into an odd performance issue with 2.0-SNAPSHOT with expand(). It seems that if you expand on an edge and include dot RID, it is much faster than if you do not. Oddly, both return the same data (whereas expand(out("edgeName").realProperty) only returns the realProperty field).

I am unsure if this is normal behavior or not, but we are seeing approx. 300ms performance difference.

Also, we are seeing some sizes of negative 1 (see "in_hasConcept" column). Note that Attractions have multiple concepts.

orientdb {db=test}> select expand(out("hasConcept")) from Attraction where name = "Hotel ABC" limit 1000

----+-------+-------+-------------------+-------------------+-------------------------+-------+-------------+---------------
#   |@RID   |@CLASS |updatedAt          |createdAt          |name                     |archive|in_hasConcept|out_hasCategory
----+-------+-------+-------------------+-------------------+-------------------------+-------+-------------+---------------
0   |#22:234|Concept|2015-01-12 11:12:46|2015-01-12 11:10:17|air conditioning         |false  |[size=-1]    |[size=1]       
1   |#22:266|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|biking                   |false  |[size=-1]    |[size=1]       
2   |#22:235|Concept|2015-01-12 11:12:46|2015-01-12 11:10:17|business                 |false  |[size=-1]    |[size=1]       
3   |#22:236|Concept|2015-01-12 11:12:46|2015-01-12 11:10:17|city                     |false  |[size=-1]    |[size=1]       
4   |#22:245|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|eco-friendly             |false  |[size=-1]    |[size=1]       
5   |#22:255|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|fishing                  |false  |[size=-1]    |[size=1]       
6   |#22:237|Concept|2015-01-12 11:12:46|2015-01-12 11:10:17|fitness facilities       |false  |[size=-1]    |[size=1]       
7   |#22:247|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|food and wine            |false  |[size=-1]    |[size=1]       
8   |#22:256|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|handicap accessible rooms|false  |[size=-1]    |[size=1]       
9   |#22:238|Concept|2015-01-12 11:12:46|2015-01-12 11:10:17|high-speed internet      |false  |[size=-1]    |[size=1]       
10  |#22:270|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|hiking                   |false  |[size=-1]    |[size=1]       
11  |#22:249|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|lgbt-friendly            |false  |[size=-1]    |[size=1]       
12  |#22:250|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|mountain                 |false  |[size=-1]    |[size=1]       
13  |#22:239|Concept|2015-01-12 11:12:46|2015-01-12 11:10:17|non-smoking rooms        |false  |[size=-1]    |[size=1]       
14  |#22:240|Concept|2015-01-13 09:36:20|2015-01-12 11:10:17|parking                  |false  |[size=-1]    |[size=2]       
15  |#22:251|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|pet-friendly             |false  |[size=-1]    |[size=1]       
16  |#22:241|Concept|2015-01-12 11:12:46|2015-01-12 11:10:17|pool                     |false  |[size=-1]    |[size=1]       
17  |#22:242|Concept|2015-01-12 11:12:46|2015-01-12 11:10:17|spa                      |false  |[size=-1]    |[size=1]       
18  |#22:277|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|stately                  |false  |[size=-1]    |[size=1]       
19  |#22:253|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|weddings                 |false  |[size=-1]    |[size=1]       
----+-------+-------+-------------------+-------------------+-------------------------+-------+-------------+---------------

20 item(s) found. Query executed in 0.298 sec(s).

orientdb {db=test}> select expand(out("hasConcept").@rid) from Attraction where name = "Hotel ABC" limit 1000

----+-------+-------+-------------------+-------------------+-------------------------+-------+-------------+---------------
#   |@RID   |@CLASS |updatedAt          |createdAt          |name                     |archive|in_hasConcept|out_hasCategory
----+-------+-------+-------------------+-------------------+-------------------------+-------+-------------+---------------
0   |#22:234|Concept|2015-01-12 11:12:46|2015-01-12 11:10:17|air conditioning         |false  |[size=-1]    |[size=1]       
1   |#22:266|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|biking                   |false  |[size=-1]    |[size=1]       
2   |#22:235|Concept|2015-01-12 11:12:46|2015-01-12 11:10:17|business                 |false  |[size=-1]    |[size=1]       
3   |#22:236|Concept|2015-01-12 11:12:46|2015-01-12 11:10:17|city                     |false  |[size=-1]    |[size=1]       
4   |#22:245|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|eco-friendly             |false  |[size=-1]    |[size=1]       
5   |#22:255|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|fishing                  |false  |[size=-1]    |[size=1]       
6   |#22:237|Concept|2015-01-12 11:12:46|2015-01-12 11:10:17|fitness facilities       |false  |[size=-1]    |[size=1]       
7   |#22:247|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|food and wine            |false  |[size=-1]    |[size=1]       
8   |#22:256|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|handicap accessible rooms|false  |[size=-1]    |[size=1]       
9   |#22:238|Concept|2015-01-12 11:12:46|2015-01-12 11:10:17|high-speed internet      |false  |[size=-1]    |[size=1]       
10  |#22:270|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|hiking                   |false  |[size=-1]    |[size=1]       
11  |#22:249|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|lgbt-friendly            |false  |[size=-1]    |[size=1]       
12  |#22:250|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|mountain                 |false  |[size=-1]    |[size=1]       
13  |#22:239|Concept|2015-01-12 11:12:46|2015-01-12 11:10:17|non-smoking rooms        |false  |[size=-1]    |[size=1]       
14  |#22:240|Concept|2015-01-13 09:36:20|2015-01-12 11:10:17|parking                  |false  |[size=-1]    |[size=2]       
15  |#22:251|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|pet-friendly             |false  |[size=-1]    |[size=1]       
16  |#22:241|Concept|2015-01-12 11:12:46|2015-01-12 11:10:17|pool                     |false  |[size=-1]    |[size=1]       
17  |#22:242|Concept|2015-01-12 11:12:46|2015-01-12 11:10:17|spa                      |false  |[size=-1]    |[size=1]       
18  |#22:277|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|stately                  |false  |[size=-1]    |[size=1]       
19  |#22:253|Concept|2015-01-12 11:12:46|2015-01-12 11:10:18|weddings                 |false  |[size=-1]    |[size=1]       
----+-------+-------+-------------------+-------------------+-------------------------+-------+-------------+---------------

20 item(s) found. Query executed in 0.002 sec(s).

orientdb {db=test}> select expand(out("hasConcept").name) from Attraction where name = "Hotel ABC" limit 1000

----+------+-------------------------
#   |@CLASS|value                    
----+------+-------------------------
0   |null  |air conditioning         
1   |null  |biking                   
2   |null  |business                 
3   |null  |city                     
4   |null  |eco-friendly             
5   |null  |fishing                  
6   |null  |fitness facilities       
7   |null  |food and wine            
8   |null  |handicap accessible rooms
9   |null  |high-speed internet      
10  |null  |hiking                   
11  |null  |lgbt-friendly            
12  |null  |mountain                 
13  |null  |non-smoking rooms        
14  |null  |parking                  
15  |null  |pet-friendly             
16  |null  |pool                     
17  |null  |spa                      
18  |null  |stately                  
19  |null  |weddings                 
----+------+-------------------------

20 item(s) found. Query executed in 0.002 sec(s).
lvca commented 9 years ago

Seems your record have many edges, so unmarshalling the entire record could be very expensive. How many edges have the records? Let's say record #22:234, #22:266 and #22:235?

brandonburkett commented 9 years ago

You are correct, we have lots of edges and this will be growing.

22:234 has 532 edges

22:266 has 219 edges

22:235 has 348 edges

lvca commented 9 years ago

So I'm closing this issue. You discovered a best practice to keep memory lower ;-)

vitorenesduarte commented 9 years ago

This consumes less memory in all cases? Can't it be like this by default?

lvca commented 9 years ago

@devourment77 Could you share your db so I can do some tests to understand if @vitorenesduarte is right about changing default behavior?

vitorenesduarte commented 9 years ago

@lvca any progress here?

lvca commented 9 years ago

@vitorenesduarte I haven't received any response from @devourment77. I'd like to have a db where I can debug why there is so much difference

vitorenesduarte commented 9 years ago

I've created a dummy database with this but the times of both queries are very alike so far.

lvca commented 9 years ago

I found a bug thanks to your code: the fetchplan fetches more than it should by loading many unnecessary records.

vitorenesduarte commented 9 years ago

Do you mean with Java API? I have queries that in console with fetchplan *:-2 take less time than with Java API. I couldn't understand why. Hope that the problem was this one you found.

lvca commented 9 years ago

The problem seems exactly this: no error but slowness because all not necessary loads. Fixing this in 2.0.8 and 2.1-rc2

brandonburkett commented 9 years ago

Apologies for not getting back on this topic and thank you @vitorenesduarte and @lvca for looking into the issue further.

lvca commented 9 years ago

The problem was only in console: fetchplan :1 was used by default instead of :0.