orientdb icon indicating copy to clipboard operation
orientdb copied to clipboard

Multi thread performance test issues

Open Dmitry-PlainID opened this issue 9 years ago • 11 comments

OrientDB Version: 2.2.14

Java Version: 8

OS: Centos 7

Description

We are facing issues with multi threaded performance test. Our system uses the embedded OrientDB. The test is only reading from the DB.

For each request in the test we are getting a connection from the pool and releasing it after the request is completed.

Running a test with 20-10 threads we don't see any issue and the test passed well. But, running the same test with 400 threads or more (which is what we'll need in a production environmnet). All of the threads get blocking 50ms to 100ms.

We ran the profiler to check this issue and saw that all them are stuck on functions from this class: com.orientechnologies.orient.server.distributed.ODistributedConfiguration

Expected behavior

Expected the system to work the same way it does with 1 thread

Actual behavior

stuck on functions from this class: com.orientechnologies.orient.server.distributed.ODistributedConfiguration

Steps to reproduce

Run requests against the DB with more then 400 threads. screen shot 2017-03-22 at 19 56 21

Dmitry-PlainID avatar Mar 23 '17 10:03 Dmitry-PlainID

In addition, after further investigation we noticed that this method: public static synchronized Iterator<OSQLFunctionFactory> getFunctionFactories() { and all the methods in the class: public class OSQLEngine { are static synchronized which means that all of them (threads) will be stuck. screen shot 2017-03-23 at 15 26 00

Dmitry-PlainID avatar Mar 23 '17 13:03 Dmitry-PlainID

Hi, the synchronized block is supposed to be super fast because, after the 1st time, it just returns a read-only iterator. About ODistributedConfiguration, in recent 2.2.x (after 2.2.15 if I remember correctly), ODistributedConfiguration is immutable, so we could remove the synchronized modifier of the method. Let me investigate it more in deep.

lvca avatar Mar 23 '17 17:03 lvca

We see that this behavior shouldn’t occur but still inside the profiler we see the block. It would be more efficient to write the method like this: if (OPERATOR_FACTORIES == null) { synchronized (INSTANCE) { if (OPERATOR_FACTORIES == null) { ……….. } } }

so the synchronized happens inside the method and not on it’s signature. Moreover, If the methods are immutable will it be possible to remove them in next version?

Dmitry-PlainID avatar Mar 23 '17 20:03 Dmitry-PlainID

@Dmitry-PlainID I don't think that would make any difference, but using the double checking singleton pattern is anyway better than current implementation, so +1.

About the ODistributedConfiguration I've removed the synchronized blocks in 2.2.x branch. If you can try this branch it would be nice having the new results before to release 2.2.18 officially.

lvca avatar Mar 23 '17 22:03 lvca

Thanks for you quick fix. I tried it - work 5 times quickly. Now next point : com.orientechnologies.common.concur.resource.OSharedContainerImpl - same problem.

You can change sharedResources to Synchronized Map (Map<String, Object> sharedResources = Collections.synchronizedMap(new HashMap<String, Object>());)

and after it use synchronized block inside function:

T value = (T) sharedResources.get(iName); if (value == null) { synchronized(sharedResources) { ..... } }

screen shot 2017-03-24 at 19 02 04

Dmitry-PlainID avatar Mar 24 '17 16:03 Dmitry-PlainID

@Dmitry-PlainID good catch, that code is pretty old, but it's called very often. Changed and pushed in 2.2.x.

lvca avatar Mar 25 '17 13:03 lvca

We ran another test after you last fix, It helped a lot, we went from 35ms~ to 22ms~. This is a very big thing for us, so thank you for the quick response.

Another thing we found was the get method in the OStatementCache class: We think it would be better to write it like this:

` public OStatement get(String statement) { OStatement result;

result = map.get(statement);
if (result == null) {
  result = parse(statement);
  synchronized (map) {
    map.put(statement, result);
  }
}
return result;

} `

We are waiting for 2.2.18, and 3.1! Thanks

Dmitry-PlainID avatar Mar 26 '17 10:03 Dmitry-PlainID

Since the LinkedHashMap is not synchronized, it could be dangerous executing a map.get() out of the synchronized block while you're doing a map.put().

lvca avatar Mar 26 '17 13:03 lvca

How many ops/sec can you do now? What kind of ops are you executing?

lvca avatar Mar 26 '17 13:03 lvca

Yes, you right. Use map.get() and map.put() in multithread without synchronized block is dangerous. Use a ReentrantReadWriteLock, to allow multiple concurrent readers, but exclusiveness to write operations.

Dmitry-PlainID avatar Mar 27 '17 12:03 Dmitry-PlainID

How many ops/sec can you do now? What kind of ops are you executing?

In our performance environment we are running around 850 ops/sec. Each operation does around 30 queries to the OrientDB. So that means that we need around 25500~ query/sec. We have around 500~ connections to the DB. (This is an embedded OrientDB)

Other details:

  • The current hardware is: 8 CPU, 8 RAM.
  • OrientDB has around 500 objects in it

We wish to be around 5000 ops/sec, that's why each ms is very crucial for us. Another thing, we are waiting for the in memory distributed DB to check the performance with it.

Dmitry-PlainID avatar Mar 27 '17 12:03 Dmitry-PlainID