您可以尝试以下方法:
- 检查互联网下游,例如使用本地文件测试相同的代码。
- 检查上游互联网,例如使用内存回购
Repository repo = new SailRepository(new MemoryStore());
-Xmx
在 JAVA_OPTS中使用为您的 Java 应用程序提供足够的内存
- 不确定
conn.clear(context);
打算做什么。据我了解,它将删除上下文中的所有三元组?
在我的地方,将 10,000,000 个 2.7G rdf 转储的 10,000,000 Triples 从 wikidata 加载到内存中的 repo 大约需要 5 分钟(我使用 maven 测试运行export MAVEN_OPTS=-Xmx7000m
)。这使得每秒约 33333 三倍 - 如果我计算正确;-)。
@Test
public void variant3() throws MalformedURLException, IOException {
Repository repo = new SailRepository(new MemoryStore());
repo.initialize();
IRI context = repo.getValueFactory().createIRI("info/mycontext:context1");
RDFFormat format = RDFFormat.NTRIPLES;
System.out.println("Load zip file of format " + format);
try (InputStream in = new URL(
"https://tools.wmflabs.org/wikidata-exports/rdf/exports/20160801/wikidata-terms.nt.gz")
.openConnection().getInputStream();
NotifyingRepositoryConnectionWrapper con = new NotifyingRepositoryConnectionWrapper(repo,
repo.getConnection());) {
RepositoryConnectionListenerAdapter myListener = new RepositoryConnectionListenerAdapter() {
private long count = 0;
@Override
public void add(RepositoryConnection arg0, Resource arg1, IRI arg2, Value arg3, Resource... arg4) {
count++;
if (count % 100000 == 0)
System.out.println("Add statement number " + count + "\n" + arg1 + " " + arg2 + " " + arg3);
}
};
con.addRepositoryConnectionListener(myListener);
con.add(in, "", format,context);
} catch (Exception e) {
throw new RuntimeException(e);
}
}