You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by MMax <Ma...@gmail.com> on 2009/11/23 15:24:12 UTC

LazyItemIterator

Hello, 

I'm trying to get properties for all child nodes of the root node in
repository. But when I'm iterating through javax.jcr.Node.getProperties() it
seems to request each property value from repository because of
LazyItemIterator interface type which this PropertyIterator implements. Is
there any way to get all property values to be loaded during one request for
each node?

I'm using rmi way of connection through jcr-rmi lib and
JackRabbitClientAdapterFactory.

Regards,
Maxim Musin.
-- 
View this message in context: http://n4.nabble.com/LazyItemIterator-tp786078p786078.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: LazyItemIterator

Posted by MMax <Ma...@gmail.com>.
Alex, thanks a lot for this advice. Jcr2Spi with Spi2Davex works really
faster than jcr-rmi connection. :)


Alexander Klimetschek wrote:
> 
> On Tue, Nov 24, 2009 at 16:45, MMax <Ma...@gmail.com> wrote:
>> I've tried using spi2dav way but I saw great performance decreasing. RMI
>> working 10 times faster on the same repository operations.
> 
> I think the real improvement comes with spi2davex [1] which actually
> does a lot of batch operations. You can configure it on the client
> side which node depth to pre-fetch to minimize the following number of
> operations (see config example in [2] createService() with the
> BatchReadConfig). Most importantly, all write operations will happen
> in a single POST upon a save() call. I think with the spi2dav you
> still have many single POSTs for every single property, that's why it
> is still slow.
> 
> Also, to make your life simpler, you can use jcr2spi on top of
> spi2davex to use the standard jcr api. You create an
> o.a.j.jcr2spi.RepositoryImpl and pass it an
> o.a.j.jcr2spi.config.RepositoryConfig which will have to return the
> spi (in this case spi2davex) in its getRepositoryService() method.
> Also, you can configure caching/polling behaviour here for the work
> between jcr api and spi.
> 
> [1]
> http://svn.apache.org/repos/asf/jackrabbit/tags/1.6.0/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/
> [2]
> http://svn.apache.org/repos/asf/jackrabbit/tags/1.6.0/jackrabbit-spi2dav/src/test/java/org/apache/jackrabbit/spi2davex/RepositoryStubImpl.java
> [3]
> http://svn.apache.org/repos/asf/jackrabbit/tags/1.6.0/jackrabbit-jcr2spi/
> [4]
> http://svn.apache.org/repos/asf/jackrabbit/tags/1.6.0/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/RepositoryImpl.java
> [5]
> http://svn.apache.org/repos/asf/jackrabbit/tags/1.6.0/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/config/RepositoryConfig.java
> 
> Note: all the above links are for the latest stable release in 1.6.0.
> Jackrabbit 2.0 will have a simpler way of getting a repository using
> the JSR-283 standardized RepositoryFactory, which has a generic helper
> implementation in the new jcr-client lib [6]. See the test cases for
> more sample usage [7]
> 
> [6]
> http://svn.apache.org/repos/asf/jackrabbit/trunk/jackrabbit-jcr-client/
> [7]
> http://svn.apache.org/repos/asf/jackrabbit/trunk/jackrabbit-jcr-client/src/test/java/org/apache/jackrabbit/client/RepositoryFactoryImplTest.java
> 
> I need to put this on the website or wiki...
> 
> Regards,
> Alex
> 
> -- 
> Alexander Klimetschek
> alexander.klimetschek@day.com
> 
> 

-- 
View this message in context: http://n4.nabble.com/LazyItemIterator-tp786078p787605.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: LazyItemIterator

Posted by Alexander Klimetschek <ak...@day.com>.
On Tue, Nov 24, 2009 at 16:45, MMax <Ma...@gmail.com> wrote:
> I've tried using spi2dav way but I saw great performance decreasing. RMI
> working 10 times faster on the same repository operations.

I think the real improvement comes with spi2davex [1] which actually
does a lot of batch operations. You can configure it on the client
side which node depth to pre-fetch to minimize the following number of
operations (see config example in [2] createService() with the
BatchReadConfig). Most importantly, all write operations will happen
in a single POST upon a save() call. I think with the spi2dav you
still have many single POSTs for every single property, that's why it
is still slow.

Also, to make your life simpler, you can use jcr2spi on top of
spi2davex to use the standard jcr api. You create an
o.a.j.jcr2spi.RepositoryImpl and pass it an
o.a.j.jcr2spi.config.RepositoryConfig which will have to return the
spi (in this case spi2davex) in its getRepositoryService() method.
Also, you can configure caching/polling behaviour here for the work
between jcr api and spi.

[1] http://svn.apache.org/repos/asf/jackrabbit/tags/1.6.0/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/
[2] http://svn.apache.org/repos/asf/jackrabbit/tags/1.6.0/jackrabbit-spi2dav/src/test/java/org/apache/jackrabbit/spi2davex/RepositoryStubImpl.java
[3] http://svn.apache.org/repos/asf/jackrabbit/tags/1.6.0/jackrabbit-jcr2spi/
[4] http://svn.apache.org/repos/asf/jackrabbit/tags/1.6.0/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/RepositoryImpl.java
[5] http://svn.apache.org/repos/asf/jackrabbit/tags/1.6.0/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/config/RepositoryConfig.java

Note: all the above links are for the latest stable release in 1.6.0.
Jackrabbit 2.0 will have a simpler way of getting a repository using
the JSR-283 standardized RepositoryFactory, which has a generic helper
implementation in the new jcr-client lib [6]. See the test cases for
more sample usage [7]

[6] http://svn.apache.org/repos/asf/jackrabbit/trunk/jackrabbit-jcr-client/
[7] http://svn.apache.org/repos/asf/jackrabbit/trunk/jackrabbit-jcr-client/src/test/java/org/apache/jackrabbit/client/RepositoryFactoryImplTest.java

I need to put this on the website or wiki...

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: LazyItemIterator

Posted by MMax <Ma...@gmail.com>.
Hi, Alex. Thanks for this tip. 

I've tried using spi2dav way but I saw great performance decreasing. RMI
working 10 times faster on the same repository operations.

Here are 2 snippets of code for each connection way (the code gets root
children and their properties). Can you look through them and tell me if I'm
doing something wrong in spi2dav way?

1. RMI connection : 

Session session = null;
InitialContext ctx = new InitialContext();
JackrabbitClientAdapterFactory adapter = new
JackrabbitClientAdapterFactory(); 
RemoteRepository rr = (RemoteRepository)
ctx.lookup("rmi://localhost:1099/jackrabbit.repository");
Repository repository = adapter.getRepository(rr); 
Credentials credJBoss = new SimpleCredentials("test", "test".toCharArray());

     session = repository.login(credJBoss);
     Node rootNode = session.getRootNode();
     NodeIterator nodeIter = rootNode.getNodes();
     while (nodeIter.hasNext())
     {
	PropertyIterator propIter = nodeIter.nextNode().getProperties();
	while (propIter.hasNext()) {
	      Property prop = propIter.nextProperty();
	      prop.getName();
	}
    }

2. Spi2Dav :

String url = "http://localhost:8081/jackrabbit-webapp-1.6.0/server";
final IdFactory idFactory = IdFactoryImpl.getInstance();
final NameFactory nFactory = NameFactoryImpl.getInstance();
final PathFactory pFactory = PathFactoryImpl.getInstance();
final QValueFactory vFactory = QValueFactoryImpl.getInstance();

final RepositoryServiceImpl webdavRepoService = 
     new RepositoryServiceImpl(url, idFactory, nFactory, pFactory,
vFactory);
SessionInfo sessionInfo = webdavRepoService.obtain(new
SimpleCredentials("user", password".toCharArray()), "default");

Iterator<PropertyId> propIter = null;
Iterator<ChildInfoImpl> iter = webdavRepoService.getChildInfos(sessionInfo,
new MyNodeId(null, null));  // MyNodeId - class implementing NodeId
interface
     while (iter.hasNext()) {
	ChildInfoImpl childInfo = iter.next();
	propIter = webdavRepoService.getNodeInfo(sessionInfo, new
MyNodeId(childInfo.getUniqueID(), null)).getPropertyIds();
	while (propIter.hasNext()) {
 	      propIter.next();
	}
      }

Best Regards,

Maxim Musin
-- 
View this message in context: http://n4.nabble.com/LazyItemIterator-tp786078p786917.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: LazyItemIterator

Posted by Alexander Klimetschek <ak...@day.com>.
On Mon, Nov 23, 2009 at 11:24, MMax <Ma...@gmail.com> wrote:
> I'm trying to get properties for all child nodes of the root node in
> repository. But when I'm iterating through javax.jcr.Node.getProperties() it
> seems to request each property value from repository because of
> LazyItemIterator interface type which this PropertyIterator implements. Is
> there any way to get all property values to be loaded during one request for
> each node?

If you use a bundle persistence manager (recommended by default), this
will be the case as nodes are stored as bundles together with their
properties. The only exception might be (larger) binaries that are
stored in separate blobs or in a datastore.

> I'm using rmi way of connection through jcr-rmi lib and
> JackRabbitClientAdapterFactory.

Well, in this case things are different, since they have to be fetched
across the wire. The RMI way of remoting is not very good with
performance. As another choice, there is the webdav / davex way to do
remoting using the jcr webdav server and jcr2spi and spi2dav(ex) on
the client side.

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com