在使用OrientDB的多线程方式中出现了问题。
他们在数据库中总共有2万条记录,我想获得每个线程的前200条记录。
如果一次使用一个线程,我可以在0.5秒内得到结果,但是当一次使用10个线程时,我将在5秒内得到所有结果。
更多线程将花费更多时间,50个线程将花费50秒。 API回复时间太长。
如何提高使用OrientDB的性能?
我已经阅读了OrientDB的有关性能调整的文档。我曾尝试更新有关网络连接池的参数,但这没用。
OrientDB的版本为2.2.37(具有单个实例)。
有一些代码示例,只需阅读记录即可。
public class Test3 {
public static void main(String[] args) {
try {
OServerAdmin serverAdmin = new OServerAdmin("remote:localhost").connect("root", "root");
if (!serverAdmin.existsDatabase("metadata", "plocal")) {
serverAdmin.createDatabase("metadata", "graph", "plocal");
}
serverAdmin.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
OrientGraphFactory factory= new OrientGraphFactory("remote:localhost/metadata", "root", "root");
factory.setAutoStartTx(false);
factory.setProperty("minPool", 5);
factory.setProperty("maxPool", 50);
factory.setupPool(5, 50);;
int threadCount = 5;
for (int i = 0; i < threadCount; i++) {
new Thread(() -> {
long start = System.currentTimeMillis();
OrientGraph orientGraph = factory.getTx();
String sql = "select * from mytable skip 0 limit 100";
Iterable<Vertex> vertices = orientGraph.command(new OCommandSQL(sql.toString())).execute();
System.out.println(Thread.currentThread().getName() + "===" + "execute sql cost:" + (System.currentTimeMillis() - start));
}).start();;
}
}
}