You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Jukka Zitting <ju...@gmail.com> on 2007/11/12 00:31:20 UTC

NGP: Prototyping

Hi,

I have a few new ideas and even some prototype code related to the NGP
proposal (http://jackrabbit.apache.org/dev/ngp.html), so I've created
a new jackrabbit-ngp component in the Jackrabbit sandbox as a place to
put the code and related data. It's better to have the material in svn
than on my hard drive... Feel free to use the area for any related
ideas or code snippets you come up with.

I'll try to summarize developments here on the mailing list whenever I
add anything more substantial, but I don't know yet how much or how
often I'll be able to work on this.

BR,

Jukka Zitting

Re: NGP: Prototyping

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Nov 23, 2007 10:23 AM, Thomas Mueller <th...@gmail.com> wrote:
> In any case, I wouldn't architect Jackrabbit around memory mapped
> files.

I guess you're right, thanks for the background.

I was hoping to offload paging features (when to load a part of the
file to memory and when to discard it) to the operating system, but it
seems like we need to handle that explicitly.

> Your patch exposes java.nio.ByteBuffer: Record.getBuffer(); I'm
> not sure why this is required.

Instead of parsing node data structures into Java object graphs, I
would like to access them directly using the on-disk serialization
format. For example a Node.getNodes() call should return an iterator
that just keeps a pointer for traversing the underlying buffer. This
would be perfect with a memory mapped file, but I guess we need to
provide some other way to get random access to the underlying records.

> > > Journal:
> > > "A record is never modified or removed once it has been added to a
> > > journal.". I agree, if there is a mechanism to removing old journal
> > > files.
> >
> > The way I see it, during normal operation we only need to be able to
> > append data to the file, so this shouldn't be a problem. At some
> > points the journal file needs to be vacuumed to save space, but that
> > operation would typically produce a new file that's then used to
> > replace the old journal. I'm not yet sure how often and at which
> > points such vacuuming needs to take place.
>
> I'm a bit worried that for long running processes (and Jackrabbit
> usually runs on the server) this could be a problem.

If we don't need to worry about the problem of not being able to
delete mapped files, then there should be no problem compacting the
journal and removing old files while Jackrabbit is running.

> > Also, I have an experimental C version of the journal and tree code.
> > The idea behind that is possibly to implement a mod_dav module to
> > enable direct WebDAV access to the tree structure stored in the
> > journal.
>
> I don't understand why you would write a WebDAV server in C. What
> advantages does this have?

I'm doing it mostly as a proof of concept.

> I see there are systems where Java is not supported. However now that
> Java is the most common programming language, and that Java has become
> more open source, I don't understand why.

There are many cases where a full Java stack is not available (even if
installed on a system). For example a typical Apache+PHP server. It
would be nice to make general content repository features easily
available for such systems.

Also, it's much easier to integrate a C library with various other
programming languages and environments.

> JNI has a big overhead, both performance wise and development wise.
> [...]
> So I don't buy the 'performance' argument - unless you can show I'm
> wrong of course ;-)

I guess you're right.

BR,

Jukka Zitting

Re: NGP: Prototyping

Posted by Thomas Mueller <th...@gmail.com>.
Hi,

> > Just curious, did you run some tests, is it faster than using
> > RandomAccessFile.read?
>
> I'm planning to... It would be really nice to map the entire journal
> file (or the part that already exists when a repository is started)
> into memory for direct access. In theory this should reduce the amount
> of copying taking place, but it's still unclear whether that happens
> in practice.

I guess there will be problems with virtual memory. I don't have much
experience with memory mapped files in Java, but from what I have
heard there are some problems. For example HSQLDB doesn't use memory
mapped files for large databases because of such problems.

In any case, I wouldn't architect Jackrabbit around memory mapped
files. Your patch exposes java.nio.ByteBuffer: Record.getBuffer(); I'm
not sure why this is required.

> > Journal:
> > "A record is never modified or removed once it has been added to a
> > journal.". I agree, if there is a mechanism to removing old journal
> > files.
>
> The way I see it, during normal operation we only need to be able to
> append data to the file, so this shouldn't be a problem. At some
> points the journal file needs to be vacuumed to save space, but that
> operation would typically produce a new file that's then used to
> replace the old journal. I'm not yet sure how often and at which
> points such vacuuming needs to take place.

I'm a bit worried that for long running processes (and Jackrabbit
usually runs on the server) this could be a problem.

> Also, I have an experimental C version of the journal and tree code.
> The idea behind that is possibly to implement a mod_dav module to
> enable direct WebDAV access to the tree structure stored in the
> journal.

I don't understand why you would write a WebDAV server in C. What
advantages does this have?

I see there are systems where Java is not supported. However now that
Java is the most common programming language, and that Java has become
more open source, I don't understand why.

> The C implementation could also eventually become a highly
> optimized JNI backend for an NGP implementation,

JNI has a big overhead, both performance wise and development wise.
Native implementations have portability, security, and other problems
(for example memory leak). There are not many cases where I would JNI.
The standard libraries don't use JNI a lot for pure processing
(meaning, things that can't be done in Java). Where they use it, the
native implementation is not pure C, it is C with some assembler:

- Compression (Zip and GZIP)
- Checksum (Adler32, CRC32)
- Image decoding
- System.arraycopy

>From what I can see, the rest is in Java (for example BigInteger,
BigDecimal, character encoding / decoding, XML processing, Java
compiler, String). Not sure about encryption. I have heard many cases
where the Java implementation was faster than a C++ version, some
before JDK 1.5. There are pure Java compressions tools and MP3
decoders, and they are not much slower than native ones - but
development and maintenance is much easier.

So I don't buy the 'performance' argument - unless you can show I'm
wrong of course ;-)

> much more control over memory mapping

Sorry, what else do you need except unmapping files? To unmap a file,
there is actually a workaround described at
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4724038 (directly
call the cleaner object), however I couldn't make it work so far.

Regards,
Thomas

Re: NGP: Prototyping

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Nov 15, 2007 11:07 AM, Thomas Mueller <th...@gmail.com> wrote:
> A few remarks about the current NGP prototype:
>
> java.nio.ByteBuffer (FileJournal / MediumRecord)
> Just curious, did you run some tests, is it faster than using
> RandomAccessFile.read?

I'm planning to... It would be really nice to map the entire journal
file (or the part that already exists when a repository is started)
into memory for direct access. In theory this should reduce the amount
of copying taking place, but it's still unclear whether that happens
in practice.

> FileChannel.map
> My experience with memory mapped files is: it is fast, but
> problematic. The biggest problem (for me) is: there is no way to unmap
> a file. That means it is not possible to truncate, rename, or delete a
> file that was once mapped. See:
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4724038
>
> Journal:
> "A record is never modified or removed once it has been added to a
> journal.". I agree, if there is a mechanism to removing old journal
> files.

The way I see it, during normal operation we only need to be able to
append data to the file, so this shouldn't be a problem. At some
points the journal file needs to be vacuumed to save space, but that
operation would typically produce a new file that's then used to
replace the old journal. I'm not yet sure how often and at which
points such vacuuming needs to take place.

Also, I have an experimental C version of the journal and tree code.
The idea behind that is possibly to implement a mod_dav module to
enable direct WebDAV access to the tree structure stored in the
journal. The C implementation could also eventually become a highly
optimized JNI backend for an NGP implementation, in which case we'd
also have much more control over memory mapping (of course at the
expense of operating system dependencies).

BR,

Jukka Zitting

Re: NGP: Prototyping

Posted by Thomas Mueller <th...@gmail.com>.
Hi,

A few remarks about the current NGP prototype:

java.nio.ByteBuffer (FileJournal / MediumRecord)
Just curious, did you run some tests, is it faster than using
RandomAccessFile.read?

FileChannel.map
My experience with memory mapped files is: it is fast, but
problematic. The biggest problem (for me) is: there is no way to unmap
a file. That means it is not possible to truncate, rename, or delete a
file that was once mapped. See:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4724038

Journal:
"A record is never modified or removed once it has been added to a
journal.". I agree, if there is a mechanism to removing old journal
files.

Thomas