You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Benson Margulies <bi...@gmail.com> on 2012/01/20 17:45:30 UTC

Writing a whole lot of RDF to TDB versus Jena

We're trying to write rather an embarrassment of riches of RDF to TDB
by just making ordinary model API calls to the model from the default
graph. It bogs down. We're about to retry with a really big -Xmx, but
I wonder if we'd be better advised to fill up a memory model and tip
that into TDF instead?

Re: Writing a whole lot of RDF to TDB versus Jena

Posted by Andy Seaborne <an...@apache.org>.
On 22/01/12 20:43, Benson Margulies wrote:

>
> What I can share from the top of my head is the following. Perhaps I
> can do a better job than usual of explaining myself. More likely, in
> the process of explaining myself I'll solve the problem.
>
> So, based on an input, I construct a statement, which is sitting in
> stmt. By convention, if this statement exists, it is reified. All the
> time disappears into the listReifiedStatements call below.
>
> The problem for me is that the URI for an existing reified statement
> can't be derived from the data available at this point as this code is
> written. If I used my hashing idea to derive it instead of deriving it
> from ephemeral information, I wouldn't need to call
> listReifiedStatements! In other words, if I go on using 'real'
> reification, but use the hash trick to derive the URI, I think all
> will be swell. No need for partial reification or other abuses.
>
>               ReifiedStatement rstmt = null;
>              if (model.contains(stmt)) {
>                  RSIterator reit = model.listReifiedStatements(stmt);
>                  rstmt = reit.nextRS();
>              } else {
>                  model.add(stmt);
>                  String reUrl = RdfUtils.relationshipUri(docId, ordinal);
>                  rstmt = model.createReifiedStatement(reUrl, stmt);
>              }

Maybe model.listReifiedStatements is considering too general a case , or 
is just plain slow.

What about, assuming only complete reifications:

SELECT ?id { ?id rdf:subject SUBJ }

which can be an API call

model.listSubjectsWithProperty(rdf:subject, SUBJECT)

or

SELECT ?id {
   ?id rdf:subject SUBJ ;
       rdf:predicate PRED ;
       rdf:object OBJ
}

	Andy

Re: Writing a whole lot of RDF to TDB versus Jena

Posted by Benson Margulies <bi...@gmail.com>.
On Sun, Jan 22, 2012 at 3:21 PM, Andy Seaborne <an...@apache.org> wrote:
> On 21/01/12 18:21, Benson Margulies wrote:
>>
>> This isn't really a 'load' scenario. I've done more profiling since I
>> started that thread.
>>
>> A process is creating new RDF on the fly. It just makes 'add' calls to
>> the model obtained from the TDB default graph.
>>
>> There is, sadly, one case which I implemented with reification. When a
>> document wanders by which triggers thousands of these events, the code
>> bogs down. Not so much in adding the reifications, as in checking for
>> existing ones, which is what it has to do.
>
>
> Maybe theer is a better way - can you share the profiling?  It may be better
> not to check ... and let TDB suppress duplicates.

What I can share from the top of my head is the following. Perhaps I
can do a better job than usual of explaining myself. More likely, in
the process of explaining myself I'll solve the problem.

So, based on an input, I construct a statement, which is sitting in
stmt. By convention, if this statement exists, it is reified. All the
time disappears into the listReifiedStatements call below.

The problem for me is that the URI for an existing reified statement
can't be derived from the data available at this point as this code is
written. If I used my hashing idea to derive it instead of deriving it
from ephemeral information, I wouldn't need to call
listReifiedStatements! In other words, if I go on using 'real'
reification, but use the hash trick to derive the URI, I think all
will be swell. No need for partial reification or other abuses.

             ReifiedStatement rstmt = null;
            if (model.contains(stmt)) {
                RSIterator reit = model.listReifiedStatements(stmt);
                rstmt = reit.nextRS();
            } else {
                model.add(stmt);
                String reUrl = RdfUtils.relationshipUri(docId, ordinal);
                rstmt = model.createReifiedStatement(reUrl, stmt);
            }


>
> TDB reification support is special - it's pure code and implements the
> contract but being stateless the DB knows nothing of reification.  We have
> been thinking of making this the usual way because reification in RDF
> generally is nowadays for specialised use only.
>
>
>> I'm considering a scheme in which I feed the three URI's of the
>> statement into MD5, and 'reifiy' by adding statements like:
>>
>>   urn:<md5>      HAS_PROVENANCE WHATEVER
>>
>> instead of using the formal reification system.
>>
>> Of course, in an imaginary perfect world, TDB would somehow know about
>> reification.
>
>
> Been there, done that [not me personally] :-)
>
> Once upon-a-time, RDB (the old relational DB engine) did reification. While
> it gets good compactness, the complexity of managing partial reifications is
> huge and the payback is small.
>
> Named graphs can be used for keeping statements separated.
>
> All that said, I'd like to do property tables for TDB (string a set of
> properties per subject together) but that it's not a priority.
>
>        Andy
>
>
>

Re: Writing a whole lot of RDF to TDB versus Jena

Posted by Andy Seaborne <an...@apache.org>.
On 21/01/12 18:21, Benson Margulies wrote:
> This isn't really a 'load' scenario. I've done more profiling since I
> started that thread.
>
> A process is creating new RDF on the fly. It just makes 'add' calls to
> the model obtained from the TDB default graph.
>
> There is, sadly, one case which I implemented with reification. When a
> document wanders by which triggers thousands of these events, the code
> bogs down. Not so much in adding the reifications, as in checking for
> existing ones, which is what it has to do.

Maybe theer is a better way - can you share the profiling?  It may be 
better not to check ... and let TDB suppress duplicates.

TDB reification support is special - it's pure code and implements the 
contract but being stateless the DB knows nothing of reification.  We 
have been thinking of making this the usual way because reification in 
RDF generally is nowadays for specialised use only.

> I'm considering a scheme in which I feed the three URI's of the
> statement into MD5, and 'reifiy' by adding statements like:
>
>    urn:<md5>      HAS_PROVENANCE WHATEVER
>
> instead of using the formal reification system.
>
> Of course, in an imaginary perfect world, TDB would somehow know about
> reification.

Been there, done that [not me personally] :-)

Once upon-a-time, RDB (the old relational DB engine) did reification. 
While it gets good compactness, the complexity of managing partial 
reifications is huge and the payback is small.

Named graphs can be used for keeping statements separated.

All that said, I'd like to do property tables for TDB (string a set of 
properties per subject together) but that it's not a priority.

	Andy




Re: Writing a whole lot of RDF to TDB versus Jena

Posted by Benson Margulies <bi...@gmail.com>.
This isn't really a 'load' scenario. I've done more profiling since I
started that thread.

A process is creating new RDF on the fly. It just makes 'add' calls to
the model obtained from the TDB default graph.

There is, sadly, one case which I implemented with reification. When a
document wanders by which triggers thousands of these events, the code
bogs down. Not so much in adding the reifications, as in checking for
existing ones, which is what it has to do.

I'm considering a scheme in which I feed the three URI's of the
statement into MD5, and 'reifiy' by adding statements like:

  urn:<md5>     HAS_PROVENANCE WHATEVER

instead of using the formal reification system.

Of course, in an imaginary perfect world, TDB would somehow know about
reification.

Re: Writing a whole lot of RDF to TDB versus Jena

Posted by Paolo Castagna <ca...@googlemail.com>.
Andy Seaborne wrote:
> Paolo has been looking at this - both hash and incremental ids.  Paolo -
> is there any thing in your mapreduce suite to do bulk incremental loading?

No, tdbloader4's [1] use case is loading into an empty database.
With current ids I did not find an easy and scalable way to merge
two or more set of TDB indexes.

As you said, hash ids (instead of file offsets) would make merging two
or more TDB indexes possible (and easier) as well as enabling different
(and much simpler) approaches at parallel loading.

There is a (non working!) branch [2] where I was trying to see what
it would take to have hash ids in TDB. I had not time recently to put
any effort on it (but it is still something I'd love to accomplish).

Paolo

 [1] https://github.com/castagna/tdbloader4
 [2] https://svn.apache.org/repos/asf/incubator/jena/Jena2/TDB/branches/hash-ids/

Re: Writing a whole lot of RDF to TDB versus Jena

Posted by Andy Seaborne <an...@apache.org>.
On 20/01/12 16:45, Benson Margulies wrote:
> We're trying to write rather an embarrassment of riches of RDF to TDB
> by just making ordinary model API calls to the model from the default
> graph. It bogs down. We're about to retry with a really big -Xmx, but
> I wonder if we'd be better advised to fill up a memory model and tip
> that into TDF instead?

Benson,

Is this loading an empty DB or one with existing data?

There are two modes of loading: bulking from empty and incremental. 
Even if you point the bulk loader at a store with existing data, it 
will; use the incremental approach.  The bulk loader trickery assumes 
total rewrite of all the tables.  It would be possible to do a bit 
better when loading so much that recalculating indexes fro scratch is 
better than incremental adds.

Incremental means add each triple, with all the associated indexing, one 
by one.  It means that the storage access is jumping all over the place 
and all the indexes are active. B+Trees end up doing less than idea 
copy-spliting.

The bulk loader works on one index at a time: that means more of the RAM 
is devoted to caching is (better cache intensity).  It also rebuild 
B+trees to reduce tree trashing, an unfortunate feature of B+Trees.

Large -Xmx is bad on 64 bits machines.  The main caching is outside the 
heap so more heap means less for the OS to cache memory mapped files.

If TDB used hash-based ids, (it uses incremental ids), better parallel 
processing and better merge DB effects would be possible.

Paolo has been looking at this - both hash and incremental ids.  Paolo - 
is there any thing in your mapreduce suite to do bulk incremental loading?

	Andy