You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by "P.Kremen" <P....@open.ac.uk> on 2011/05/18 11:33:51 UTC

Adding statements to Jena SDB model

Hi folks,

I have a SDB-backed web application. So far it worked as follows:
1) created a SDB backed model
2) performed model reads and writes (using various methods including model.add(Statement), Resource.addProperty, etc).
3) the SDB model is closed

This worked *most of the time*, but sometimes the results were lost during save which pointed me to SDB wiki that says, that whenever using 'model.add', the batch has to be demarked by
   Model.notifyEvent(GraphEvents.startRead);
   ... WRITE ...
   Model.notifyEvent(GraphEvents.finishRead);

I also came across another option for demarkation:
   store.getLoader().startBulkUpdate();
   ... WRITE ...
   store.getLoader().finishBulkUpdate();

Could you please help me make clear
1) Which Model/Resource add/addProperty/addLabel/etc. operations need batch demarkation and
2) Which of the demarkation mechanism is preferred.

Thanks !

Cheers,
Petr

-- 
The Open University is incorporated by Royal Charter (RC 000391), an exempt charity in England & Wales and a charity registered in Scotland (SC 038302).


Re: Adding statements to Jena SDB model

Posted by Damian Steer <d....@bristol.ac.uk>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 18/05/11 11:10, P.Kremen wrote:
> Hi Damian
> 
>> model.add _does not need_ batches to be indicated. By default each
>> add operation, that is each statement, list of statements or model
>> add, happens in a batch load. If your results were occasionally
>> lost something is definitely wrong and we ought to investigate.
>> Could you post your code?
> 
> Well, I said it wrong way.
> 
> It is the same project as the SDB/MySQL issue discussed with you last
> time. 

Doh, Captain Memory strikes again, failed to notice who was asking the
question.

> I just do not have much control over the client
> logic. So I want to make it as efficient as possible from the SDB
> backend point of view. Basically, the currenty (ugly) API is as
> follows (which was designed before, so the only degree of freedom for
> me is the content of these methods):
> 
> public OntModel getOntModel() { 1) create an SDB-backed OntModel 2)
> Model.startBatchUpdate 3) return the model to the user }
> 
> public void saveOntModel(OntModel) { 1) Model.finishBatchUpdate 1)
> Model.startBatchUpdate }
> 
> Thx
> 
> Petr
> 

That's a tough thing to do, but you clearly know this. In my opinion
it's not worth it: poor performance is better than data loss, and
typically easy to fix.

If I have any inspiration in the meantime I'll let you know.

Damian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3TzJYACgkQAyLCB+mTtyn2yQCcCtfk9shsxhi80ZBTtBKFcuQa
XNAAoMwVLMjXYMbfTRIHOql76I9VkAop
=hKUq
-----END PGP SIGNATURE-----

RE: Adding statements to Jena SDB model

Posted by "P.Kremen" <P....@open.ac.uk>.
Hi Damian

> model.add _does not need_ batches to be indicated. By default each add operation, that is each statement, list of statements or model add, happens in a batch load.
> If your results were occasionally lost something is definitely wrong and we ought to investigate. Could you post your code?

Well, I said it wrong way. 

It is the same project as the SDB/MySQL issue discussed with you last time. Thus - I just provide SDB-backed OntModel to the client business logic which in turn does whatever it wants with it - Model.add(Statement), Model.getGraph().addTriple, Resource.addProperty, etc. etc. It is difficult  for me to trace all the options that are used. In this sense, it is 'occasional' to me that an update is lost - not occasional w.r.t SDB. Thus, it appears that BL developers use some operations that result in bulk updates and some that do not - so I need to know which operations I should advise the BL developers to use as the best and unified practice w.r.t SDB

> each add operation is a separate batched add, and that's expensive. By wrapping this with notifications or bulk update call (they resolve to the same thing so you can use either) you'll experience a substantial performance increase -- though you 
need to be careful.

I know, I know ;-) I just do not have much control over the client logic. So I want to make it as efficient as possible from the SDB backend point of view. Basically, the currenty (ugly) API is as follows (which was designed before, so the only degree of freedom for me is the content of these methods):

public OntModel getOntModel() {
   1) create an SDB-backed OntModel 
   2) Model.startBatchUpdate
   3) return the model to the user
}

public void saveOntModel(OntModel) {
   1) Model.finishBatchUpdate
   1) Model.startBatchUpdate
}

Thx

Petr

-- 
The Open University is incorporated by Royal Charter (RC 000391), an exempt charity in England & Wales and a charity registered in Scotland (SC 038302).


Re: Adding statements to Jena SDB model

Posted by Damian Steer <d....@bristol.ac.uk>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 18/05/11 10:33, P.Kremen wrote:
> Hi folks,
> 
> I have a SDB-backed web application. So far it worked as follows: 1)
> created a SDB backed model 2) performed model reads and writes (using
> various methods including model.add(Statement), Resource.addProperty,
> etc). 3) the SDB model is closed
> 
> This worked *most of the time*, but sometimes the results were lost
> during save which pointed me to SDB wiki that says, that whenever
> using 'model.add', the batch has to be demarked by 
> Model.notifyEvent(GraphEvents.startRead); ... WRITE ... 
> Model.notifyEvent(GraphEvents.finishRead);
> 
> I also came across another option for demarkation: 
> store.getLoader().startBulkUpdate(); ... WRITE ... 
> store.getLoader().finishBulkUpdate();
> 
> Could you please help me make clear 1) Which Model/Resource
> add/addProperty/addLabel/etc. operations need batch demarkation and 
> 2) Which of the demarkation mechanism is preferred.
> 
> Thanks !
> 
> Cheers, Petr
> 

Hi Petr,

Hmm, just checked the wiki and agree it ought to be clearer.

model.add _does not need_ batches to be indicated. By default each add
operation, that is each statement, list of statements or model add,
happens in a batch load.

If your results were occasionally lost something is definitely wrong and
we ought to investigate. Could you post your code?

What's the deal with explicitly marking adds then?

If you are writing code like:

for (Statement s: collectionOfStatements) {
  if (matchesSomeCondition(s)) sdbModel.add(s);
}

each add operation is a separate batched add, and that's expensive. By
wrapping this with notifications or bulk update call (they resolve to
the same thing so you can use either) you'll experience a substantial
performance increase -- though you need to be careful.

It's typically much better to just write to an in-memory model or list
of statements then add the whole thing to the sdbModel. No nasty finally
{} business etc.

Damian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3TmFQACgkQAyLCB+mTtynIhACg8fL59zdiXWMiODsWy3S+xlvD
pd0An1veNscFsAwTjVIVh3qYdtOE9/rF
=JxSW
-----END PGP SIGNATURE-----