Hi,
I've written the code below to create 10M nodes, without any relations. But,
it has memory exception that couldn't solve. would you please help me.

Also I want to show this graph visually. I used Gremlin and Jung to view the
graph, but it either did not work even for 1M nodes! Any Idea About this
one?

Thank you :)

Code of BatchInserter:


public void batchInsertor(String graphPath)
{
BatchInserter inserter = null;
BatchInserterIndexProvider indexProvider = null;
BatchInserterIndex index = null;
try{
inserter = new BatchInserterImpl(graphPath);
indexProvider = new LuceneBatchInserterIndexProvider( inserter );
index = indexProvider.nodeIndex( "index", MapUtil.stringMap( "type", "exact"
) );
 for(int i=0; i<10000000; i++)
{
index.setCacheCapacity("name", 100000 );
Map<String, Object> properties = MapUtil.map( "name", String.valueOf(i));
long node = inserter.createNode(properties);
index.add( node, properties );
if(i%1000000 == 0)
{
System.out.println("Check Point: " + i);
}
}
 indexProvider.shutdown();
inserter.shutdown();
}
finally{
indexProvider.shutdown();
inserter.shutdown();
}
}


Error:

Exception in thread "main" java.lang.IllegalStateException: this writer hit
an OutOfMemoryError; cannot flush
at
org.apache.lucene.index.IndexWriter.doFlushInternal(IndexWriter.java:3521)
at org.apache.lucene.index.IndexWriter.doFlush(IndexWriter.java:3509)
at org.apache.lucene.index.IndexWriter.flush(IndexWriter.java:3500)
at org.apache.lucene.index.IndexWriter.optimize(IndexWriter.java:2271)
at org.apache.lucene.index.IndexWriter.optimize(IndexWriter.java:2249)
at
org.neo4j.index.impl.lucene.LuceneBatchInserterIndex.closeWriter(LuceneBatchInserterIndex.java:275)
at
org.neo4j.index.impl.lucene.LuceneBatchInserterIndex.shutdown(LuceneBatchInserterIndex.java:350)
at
org.neo4j.index.impl.lucene.LuceneBatchInserterIndexProvider.shutdown(LuceneBatchInserterIndexProvider.java:144)



Code of Visualization:

public JPanel showBatchInserted(String graphPath)
{
neo = new Neo4jGraph(graphPath);
JPanel graphPanel=new JPanel();
GraphJung g = new GraphJung(neo);
Layout<Vertex, Edge> layout = new CircleLayout<Vertex,Edge>(g);
layout.setSize(new Dimension(1500,1000));
viz = new VisualizationViewer<Vertex, Edge>(layout);
viz.setBackground(Color.WHITE);
viz.setAutoscrolls(true);
viz.setName("visualizationViewer");
viz.setSize(new Dimension(1500,1000));
AnnotatingGraphMousePlugin<Vertex, Edge> an=new
AnnotatingGraphMousePlugin<Vertex, Edge>(viz.getRenderContext());
AnnotatingModalGraphMouse<Vertex,Edge> gm =  new
AnnotatingModalGraphMouse<Vertex,Edge>(viz.getRenderContext(),
an);

gm.setMode(ModalGraphMouse.Mode.PICKING);
viz.setGraphMouse(gm);
JMenuBar menuBar = new JMenuBar();
JMenu modeMenu = gm.getModeMenu();
modeMenu.setText("Mouse Mode");
modeMenu.setIcon(null);
modeMenu.setPreferredSize(new Dimension(80,20));
menuBar.add(modeMenu,BorderLayout.NORTH);

GraphZoomScrollPane graphScroll=new GraphZoomScrollPane(viz);
graphScroll.add(menuBar,BorderLayout.NORTH);
graphScroll.add(viz,BorderLayout.CENTER);
graphScroll.setName("graphScroll");
graphPanel.add(graphScroll,BorderLayout.CENTER);


Transformer<Vertex,Paint> vertexPaint = new Transformer<Vertex,Paint>() {
public Paint transform(Vertex i) {
return Color.RED;
}
};
Transformer<Vertex,Icon> vertexIcon = new Transformer<Vertex,Icon>() {
public Icon transform(Vertex i) {
ImageIcon icon=new ImageIcon("icon/icon.png");
return icon;
}
};
float dash[] = {0.1f};
final Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_MITER, 10.0f, dash, 5.0f);
Transformer<Edge, Stroke> edgeStrokeTransformer =
new Transformer<Edge, Stroke>() {
public Stroke transform(Edge s) {
return edgeStroke;
}
};

Transformer<Edge,Paint> edgePaint = new Transformer<Edge,Paint>() {

public Paint transform(Edge arg0) {
// TODO Auto-generated method stub
return Color.BLUE;
}
};
Transformer<Edge, Paint> arrowColor=new Transformer<Edge, Paint>() {

@Override
public Paint transform(Edge arg0) {
// TODO Auto-generated method stub
return Color.BLUE;
}
};;;
Transformer<Edge, Paint> arrowDraw=new Transformer<Edge, Paint>() {

@Override
public Paint transform(Edge arg0) {
// TODO Auto-generated method stub
return Color.BLUE;
}
};;;
Transformer<Edge, Font> fontEdge=new Transformer<Edge, Font>() {

@Override
public Font transform(Edge arg0) {
Font temp=new Font(Font.MONOSPACED,Font.ITALIC, 12);
return temp;
}
};;;
Transformer<Vertex, Font> font=new Transformer<Vertex, Font>() {

@Override
public Font transform(Vertex arg0) {
// TODO Auto-generated method stub
Font temp=new Font(Font.MONOSPACED,Font.ITALIC, 12);

return temp;
}
};;;
Transformer<Vertex, String> vertexLabelTransformer = new Transformer<Vertex,
String>() {
public String transform(Vertex vertex) {
return (String) vertex.getProperty(PROPERTY_NODE_NAME);
}
};
Transformer<Edge, String> edgeLabelTransformer = new Transformer<Edge,
String>() {
public String transform(Edge edge) {
return
edge.getProperty(PROPERTY_EDGE_TYPE)+",cost="+String.valueOf(edge.getProperty(PROPERTY_EDGE_COST))+",time="+String.valueOf(edge.getProperty(PROPERTY_EDGE_TIME));//edge.getLabel()
;
}
};
viz.getRenderContext().setEdgeLabelTransformer(edgeLabelTransformer);
viz.getRenderContext().setVertexLabelTransformer(vertexLabelTransformer);
viz.getRenderContext().setEdgeDrawPaintTransformer(edgePaint);
viz.getRenderContext().setVertexIconTransformer(vertexIcon);
viz.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
viz.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
viz.getRenderer().getVertexLabelRenderer().setPosition(Position.N);
viz.getRenderContext().setArrowFillPaintTransformer(arrowColor);
viz.getRenderContext().setArrowDrawPaintTransformer(arrowDraw);
viz.getRenderContext().setVertexFontTransformer(font);
viz.getRenderContext().setEdgeFontTransformer(fontEdge);
 return graphPanel;
}
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to