[owl-s] Thread safety of loading ontologies and performing queries?
Jim Andreou
jim.andreou at gmail.com
Tue Jun 16 11:21:09 EDT 2009
2009/6/16 Thorsten Möller <Thorsten.Moeller at unibas.ch>
>
> > It would be nice to be able to download URIs from the network
> > concurrently
> This can be achieved indirectly. Start with one KB per thread and load
> the ontologies per thread in its "own" KB. After all threads finished
> then you can merge KBs into one (large) one using
> OWLKnowledgeBase.load(...), of course, using just one thread. Note that
> you might want to skip the base ontology of every KB, cf.
> OWLKnowledgeBase.getBaseOntology(). The load operation should be fast
> since it basically adds references of models rather than copying
> statements. Give it a try.
>
> Cheers,
> Thorsten
>
> [1] http://jena.sourceforge.net/how-to/concurrency.html
> [2] http://clarkparsia.com/pellet/faq/jena-concurrency/
>
Done that, works out nicely (thanks :)). For 6 test (non-local) URIs,
serially took 22sec, parallely less than half. (I know the numbers are
meaningless as-is, but I merely say it's while-worthy).
If we had:
- Some simple utilities that turn a URI/URL/InputStream(/String, why not) to
an OWLOntology
- A callback that takes OWLOntology (but this really belongs in Java :(
instead of reinventing yet another Handler<T> callback interface)
Then this could be nicely abstracted out into a reusable utility.
Here is a sketch of my code:
static void loadServices(Handler<OWLOntology> handler, Collection<URI>
services, ExecutorService executor) throws IOException, InterruptedException
{
CompletionService<OWLOntology> completionService = new
ExecutorCompletionService<OWLOntology>(executor);
for (final URI service : services) {
completionService.submit(new Callable<OWLOntology>() {
public OWLOntology call() throws Exception {
return OwlsUtils.parseURI(service); //are there such
methods available? It creates a dummy OWLKnowledgeBase for each call.
}
});
}
try {
for (int i = 0; i < services.size(); i++) { //assuming
"services" is not modified under the hood
OWLOntology ontology = completionService.take().get();
handler.handle(ontology); //this loads the ontology in my kb
with a write lock
}
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof IOException) {
throw (IOException)cause;
}
throw new RuntimeException(cause); //a bit sloppy
}
}
//this overload probably is not a good idea
static void loadServices(Handler<OWLOntology> handler, Collection<URI>
services) throws IOException, InterruptedException {
ExecutorService executor = Executors.newCachedThreadPool();
loadServices(handler, services, executor);
executor.shutdown();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.mindswap.org/pipermail/owl-s/attachments/20090616/3b05b98e/attachment.html
More information about the OWL-S
mailing list