xmlgraphics-fop-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thomas.dewe...@kodak.com
Subject Re: Images in FOP 0.92beta
Date Sat, 15 Jul 2006 12:19:45 GMT
Hi Jeremias,

Jeremias Maerki <dev@jeremias-maerki.ch> wrote on 07/14/2006 04:26:57 PM:

> At first, I'd have preferred to avoid an extra thread if possible so I
> just added a local ReferenceQueue and used poll() to do house-keeping
> whenever a user agent signs off. I assume you don't have a
> non-too-frequently called method you could do on-demand house-keeping 
> so the thread is probably ok. 

   Well I figure that the thread will just be blocked in queue.remove
most of the time unless it has something to do.  I don't think there
is much overhead for a thread in the types of systems we are targeting
(i.e. not small constrained devices).  Note that this is one thread
that is used for all CleanerThread sub objects (so it's not like you
are likely to spawn lots of threads).

   Some people put the cleaning in the management calls (so you
poll the queue when people add/remove elements from the hash).  I'm
not fond of that as it means you are borrowing a 'strangers' thread
to do your work (it just feels ugly).

> And given that we have Batik in memory
> anyway FOP could co-use that thread. But since I'd like to avoid
> dependencies on Batik directly if possible, can we move CleanerThread to
> XML Graphics Commons and rename it to ReferenceCleanerThread to give it
> a more speaking name? 

   I was under the impression that most of the stuff in
batik.util will find it's way into graphics commons.  As for renaming
I don't think it's a big deal.

> The SoftReferenceCache is indeed a little odd, especially the method
> names. I think I'll skip that one for now.

   It is meant to be subclassed to provide a strongly typed interface
(notice all the '*Impl' methods are protected.  So the subclass can 
provide public versions that take strongly typed parameters.

> Some other interesting things I observed while playing around for those
> interested (ATM, I'm still doing the house-keeping without the thread
> but I might rewrite):

   SoftReferences are a very powerful tool in Java, I don't think they
get enough attention in general.

> When using weak references (as the current code does but with the fixed
> behavior) FOP takes around 35 sec on my machine to produce that 182
> image PDF. Heap usage is usually around 12MB with peaks to 26MB. The
> house-keeping after the user agent retires removes around 178 
> Switching to soft references which is actually the recommended type for
> caches, the heap usage goes up to the 64MB maximum and pretty much stay
> there. The whole thing takes 29-30 sec average. The house-keeping after
> the user agent retires removes between 161 and 170 references. So this
> means the VM actually keeps more references around, only freeing as many
> as it needs not to run into memory problems. And it runs faster this 
> I learned a few things today. :-)

   I guess that makes it a good day ;)

> On 14.07.2006 14:35:06 thomas.deweese wrote:
> > Hi all,
> > 
> >     Just a small comment on HashMaps with weak values:
> > 
> > Jeremias Maerki <dev@jeremias-maerki.ch> wrote on 07/13/2006 04:43:07 
> > 
> > > Ok, so I changed the WeakHashMap to a HashMap and wrapped the values 
> > > WeakReferences. Tadaaa! A PDF with 182 JPEG images with a total size 
> > > 258 MB is suddenly produced without exceptions using the VM's 
> > > heap settings, never going beyond 26MB heap usage. *g*
> > 
> >    There is a potential problem with this approach that Batik ran 
> > Unless you go a little further those weak values accumulate in the 
> > In your case this probably isn't a big deal, but for Batik where there
> > are potentially of thousands (or tens of thousands, think mouse move 
> > events) 
> > of entries, these 'dead' entries start to add up.
> > 
> >    As a result Batik has batik.util.CleanerThread.  This class has
> > inner classes that subclass the various SoftReference classes with an 
> > additional method 'public void cleared()'.  This method is called by
> > the CleanerThread when the object the soft reference is point at is
> > cleared from memory (it uses the ReferenceQueue part of soft 
> > 
> >    This gives you the hook you need to then de-register the entry from
> > the has table.  This is actually an incredibly useful 'addition' to
> > the standard soft reference classes (for example I will often use
> > it to check if classes I think should go to GC really do go to GC).
> > 
> >    I should also mention that Batik has a class called 
> > 'SoftReferenceCache'
> > which is a thread safe implementation of exactly what you just 
> > implemented. 
> > The interface may seem a little odd but it is designed to ensure that
> > only one party ever has to decode a resource even if multiple threads
> > request it "at the same time".
> > 
> >    Anyway just thought I would add my 2 cents...
> Jeremias Maerki

View raw message