Skip to content

Instantly share code, notes, and snippets.

@fancyerii
Created August 19, 2014 06:23
Show Gist options
  • Save fancyerii/7420d86f9eff5f196f1c to your computer and use it in GitHub Desktop.
Save fancyerii/7420d86f9eff5f196f1c to your computer and use it in GitHub Desktop.
test insert
FileInputStream is = new FileInputStream("/Users/lili/Downloads/freebase-rdf-2014-08-03-00-00.gz");
GZIPInputStream gzis=new GZIPInputStream(is);
BufferedReader br=new BufferedReader(new InputStreamReader(gzis,"UTF8"));
int lineNum=0;
String line;
TitanGraph g=TitanFactory.open("/Users/lili/soft/titan-server-0.4.4/conf/titan-hbase-es.properties");
long total=0;
long start=System.currentTimeMillis();
int statSize=10_000;
while((line=br.readLine())!=null){
lineNum++;
if(lineNum % 1000000 ==0){
System.out.println("line: "+lineNum);
}
String[] arr=line.split("\t");
if(arr.length!=4){
continue;
}
String uri1=arr[0];
try{
Vertex v=g.addVertex(null);
v.setProperty("uri", uri1);
g.commit();
}catch(Exception e){
}
total++;
if(arr[2].startsWith("<") && arr[2].endsWith(">")){
try{
Vertex v2=g.addVertex(null);
v2.setProperty("uri", arr[2]);
g.commit();
}catch(Exception e){
}
total++;
}
if(total>=statSize){
System.out.println("insert speed: "+(1000.0*total/(System.currentTimeMillis()-start))+" vertices/sec.");
total=0;
start=System.currentTimeMillis();
}
}
br.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment