繁体   English   中英

Orientdb-具有数百万个顶点的SQL查询导致Java OutOfMemory错误

[英]Orientdb - SQL query with millions of vertices causes Java OutOfMemory error

我需要在V1类的所有顶点和V2类的所有顶点之间创建边。 我的班级每个都有2-3百万个顶点。 带有SELECT * FROM V1和SELECT * FROM V2的double for循环会产生Java OutOfMemory(堆空间)错误(请参见下文)。 这是一个脱机过程,如果需要,将执行一次或两次(不是频繁操作),因为该图将不会由用户(只有我自己)定期更新。 如何分批处理(使用SELECT ... LIMIT或g.getvertices())来避免这种情况?

这是我的代码:

        OrientGraphNoTx G = MyOrientDBFactory.getNoTx();
        G.setUseLightweightEdges(false);
        G.declareIntent(new OIntentMassiveInsert());

        for (Vertex p1 : (Iterable<Vertex>) EG.command( new OCommandSQL("SELECT * FROM V1")).execute()) 
        {
            for (Vertex p2 : (Iterable<Vertex>) EG.command( new OCommandSQL("SELECT * FROM V2")).execute()) 
            {
                if (p1.getProperty("prop1")==p2.getProperty("prop1")
                {
                    //p1.addEdge("MyEdge", p2);
                    EG.command( new OCommandSQL("create edge MyEdge from" + p1.getId() +"to "+  p2.getId() + " retry 100") ).execute ();
                }
            }
        }
        G.shutdown();

具有Java / Graph API的OrientDB 2.1.5

带有VM选项-Xmx4096m和-Dstorage.diskCache.bufferSize = 7200的NetBeans 8.1


控制台中的错误消息:

2016-05-24 15:48:06:112信息{db = MyDB} [提示]查询'SELECT * FROM V1'返回的结果集包含10000多个记录。 检查是否确实需要所有这些记录,或者通过使用LIMIT来同时提高性能和使用的RAM来减少结果集[OProfilerStub] java.lang.OutOfMemoryError:Java堆空间将堆转储到java_pid7896.hprof ...

Netbeans输出中的错误消息

线程“主”中的异常com.orientechnologies.orient.enterprise.channel.binary.OResponseProcessingException:响应处理期间的异常。 在com.orientechnologies.orient.enterprise.channel.binary.OChannelBienaryAsynchClient.handleStatus(OChannelBinaryAsynchClient.handleStatus(OChannelBinaryAsynchClient.handleStatus(OChannelBinaryAsynchClient.handleStatus))处在com.orientechnologies.orient.enterprise.channel.binary。 .orient.enterprise.channel.binary.OChannelBinaryAsynchClient.beginResponse(OChannelBinaryAsynchClient.java:282)位于com.orientechnologies.orient.enterprise.channel.binary.OChannelBinaryAsynchClient.beginResponse(OChannelBinaryAsynchClient。 .remote.OStorageRemote.beginResponse(OStorageRemote.java:2166)位于com.orientechnologies.orient.client.remote.OStorageRemote.command(OStorageRemote.java:1189)位于com.orientechnologies.orient.client.remote.OStorageRemoteThread.command(OStorage .java:444),位于com.orientechnologies.orient.core.command.OCommandRequestTextAbstract.execute(OCommandRequestTextAbstract.java:63),位于com.tinkerpop.blueprint s.impls.orient.OrientGraphCommand.execute(OrientGraphCommand.java:49)位于xx.xxx.xxx.xx.MyEdge。(MyEdge.java:40)位于xx.xxx.xxx.xx.GMain.main(GMain.java :60)原因:java.lang.OutOfMemoryError:超出了GC开销限制

作为解决方法,您可以使用类似于以下代码

Iterable<Vertex> cv1= g.command( new OCommandSQL("SELECT count(*) FROM V1")).execute();
long counterv1=cv1.iterator().next().getProperty("count");

int[] ids=g.getRawGraph().getMetadata().getSchema().getClass("V1").getClusterIds();

long repeat=counterv1/10000;
long rest=counterv1-(repeat*10000);

List<Vertex> v1=new ArrayList<Vertex>();
int rid=0;
for(int i=0;i<repeat;i++){
    Iterable<Vertex> v= g.command( new OCommandSQL("SELECT * FROM V1 WHERE @rid >= " + ids[0] + ":" + rid  + " limit 10000")).execute();
    CollectionUtils.addAll(v1, v.iterator());
    rid=10000*(i+1);
}
if(rest>0){
    Iterable<Vertex> v=g.command( new OCommandSQL("SELECT * FROM V1 WHERE @rid >= " + ids[0] + ":" + rid + " limit "+ rest)).execute();
    CollectionUtils.addAll(v1, v.iterator());
}

希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM