Multi thread performance test issues
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.

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.

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

@Dmitry-PlainID good catch, that code is pretty old, but it's called very often. Changed and pushed in 2.2.x.
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
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().
How many ops/sec can you do now? What kind of ops are you executing?
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.
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.