Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Information About A BlockingQueue

Reply
Thread Tools

Information About A BlockingQueue

 
 
Jason Cavett
Guest
Posts: n/a
 
      04-25-2007
I am currently in the process of using a BlockingQueue
(LinkedBlockingQueue, to be exact) to help with a producer/consumer
aspect of an application I'm developing. The user can continuously
add items to the queue for processing (and this does work). However,
I'm a little confused about how a BlockingQueue works.

When I add an item to the BlockingQueue, is the items copied into the
queue, or is it just a reference to the actual object?


The reason I ask is because I notice that after adding 9 to 11 items
into the queue, the application slows considerably (despite the fact
that the "queue" stuff is running in a separate thread). After
watching the output from the garbage collector, it appears as though I
have a memory leak. I attempted to use hprof to profile my
application to see where the memory leak is taking place, but I'm not
fully understanding the output of hprof. When my application lags
like this, it somewaht defeats the purpose of the use of the
BlockingQueue since I want users to be able to queue up files to
process.

Can anybody clear up any possible issues or provide some insight with
the way BlockingQueue works and any possible memory issues I should be
keeping an eye out for (there isn't much information that I could find
from my own Google searches).

Thanks

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      04-25-2007
On 25.04.2007 15:47, Jason Cavett wrote:
> I am currently in the process of using a BlockingQueue
> (LinkedBlockingQueue, to be exact) to help with a producer/consumer
> aspect of an application I'm developing. The user can continuously
> add items to the queue for processing (and this does work). However,
> I'm a little confused about how a BlockingQueue works.
>
> When I add an item to the BlockingQueue, is the items copied into the
> queue, or is it just a reference to the actual object?


The blocking queue holds on to objects in the queue like any other
collection does.

> The reason I ask is because I notice that after adding 9 to 11 items
> into the queue, the application slows considerably (despite the fact
> that the "queue" stuff is running in a separate thread).


What is an "item"?

> After
> watching the output from the garbage collector, it appears as though I
> have a memory leak. I attempted to use hprof to profile my
> application to see where the memory leak is taking place, but I'm not


hprof is unlikely to help you with detecting memory leaks other than
finding excessive creation of instances. But to get a leak you must
also be holding on to those instances longer than intended which is
something you do not get from hprof IIRC. You might want to look at one
of the various profiler / memory analyzer tools around (JProbe,
OptimizeIt, Eclipse TPTP).

> fully understanding the output of hprof. When my application lags
> like this, it somewaht defeats the purpose of the use of the
> BlockingQueue since I want users to be able to queue up files to
> process.
>
> Can anybody clear up any possible issues or provide some insight with
> the way BlockingQueue works and any possible memory issues I should be
> keeping an eye out for (there isn't much information that I could find
> from my own Google searches).


Here are some potential reasons for the slowdown:

- your objects are large and you are tight on JVM memory so GC has to
kick in more often or your JVM starts swapping to disk

- your processing is the slow bit (too much concurrency for example,
or it uses too much mem per processing instance)

There are probably more but without more detail we can't really tell.

Regards

robert
 
Reply With Quote
 
 
 
 
Jason Cavett
Guest
Posts: n/a
 
      04-26-2007
On Apr 25, 9:57 am, Robert Klemme <shortcut...@googlemail.com> wrote:
> On 25.04.2007 15:47, Jason Cavett wrote:
>
> > I am currently in the process of using a BlockingQueue
> > (LinkedBlockingQueue, to be exact) to help with a producer/consumer
> > aspect of an application I'm developing. The user can continuously
> > add items to the queue for processing (and this does work). However,
> > I'm a little confused about how a BlockingQueue works.

>
> > When I add an item to the BlockingQueue, is the items copied into the
> > queue, or is it just a reference to the actual object?

>
> The blocking queue holds on to objects in the queue like any other
> collection does.
>
> > The reason I ask is because I notice that after adding 9 to 11 items
> > into the queue, the application slows considerably (despite the fact
> > that the "queue" stuff is running in a separate thread).

>
> What is an "item"?
>
> > After
> > watching the output from the garbage collector, it appears as though I
> > have a memory leak. I attempted to use hprof to profile my
> > application to see where the memory leak is taking place, but I'm not

>
> hprof is unlikely to help you with detecting memory leaks other than
> finding excessive creation of instances. But to get a leak you must
> also be holding on to those instances longer than intended which is
> something you do not get from hprof IIRC. You might want to look at one
> of the various profiler / memory analyzer tools around (JProbe,
> OptimizeIt, Eclipse TPTP).
>
> > fully understanding the output of hprof. When my application lags
> > like this, it somewaht defeats the purpose of the use of the
> > BlockingQueue since I want users to be able to queue up files to
> > process.

>
> > Can anybody clear up any possible issues or provide some insight with
> > the way BlockingQueue works and any possible memory issues I should be
> > keeping an eye out for (there isn't much information that I could find
> > from my own Google searches).

>
> Here are some potential reasons for the slowdown:
>
> - your objects are large and you are tight on JVM memory so GC has to
> kick in more often or your JVM starts swapping to disk
>
> - your processing is the slow bit (too much concurrency for example,
> or it uses too much mem per processing instance)
>
> There are probably more but without more detail we can't really tell.
>
> Regards
>
> robert


Thanks for the tips. I checked into the "objects are large...so GC
hast to kick in more often" Turns out this is the problem. I forgot
I had done it, but I was making deep copies of objects to put onto the
BlockingQueue so the user could continue to edit the file but the file
(at that point in time) could also be processed.

Of course, creating deep copies quickly fills up memory, so I quickly
ran out of memory. I can easily fix this by putting the (reference
to) the object on the queue directly instead of a copy of the object,
but, unfortunately that raises the problem where users can continue
editing objects and what they originally put in the queue will not be
what's processed if they have continued to make changes to the file
(the processing is done in a separate thread).

Any suggestions on how to handle this problem?

Anyway, even if there isn't (I've come up with a temporary solution
for now), thank you for your helpful suggestions on the memory problem.

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      04-26-2007
On 26.04.2007 14:57, Jason Cavett wrote:
> On Apr 25, 9:57 am, Robert Klemme <shortcut...@googlemail.com> wrote:
>> On 25.04.2007 15:47, Jason Cavett wrote:
>>
>>> I am currently in the process of using a BlockingQueue
>>> (LinkedBlockingQueue, to be exact) to help with a producer/consumer
>>> aspect of an application I'm developing. The user can continuously
>>> add items to the queue for processing (and this does work). However,
>>> I'm a little confused about how a BlockingQueue works.
>>> When I add an item to the BlockingQueue, is the items copied into the
>>> queue, or is it just a reference to the actual object?

>> The blocking queue holds on to objects in the queue like any other
>> collection does.
>>
>>> The reason I ask is because I notice that after adding 9 to 11 items
>>> into the queue, the application slows considerably (despite the fact
>>> that the "queue" stuff is running in a separate thread).

>> What is an "item"?
>>
>>> After
>>> watching the output from the garbage collector, it appears as though I
>>> have a memory leak. I attempted to use hprof to profile my
>>> application to see where the memory leak is taking place, but I'm not

>> hprof is unlikely to help you with detecting memory leaks other than
>> finding excessive creation of instances. But to get a leak you must
>> also be holding on to those instances longer than intended which is
>> something you do not get from hprof IIRC. You might want to look at one
>> of the various profiler / memory analyzer tools around (JProbe,
>> OptimizeIt, Eclipse TPTP).
>>
>>> fully understanding the output of hprof. When my application lags
>>> like this, it somewaht defeats the purpose of the use of the
>>> BlockingQueue since I want users to be able to queue up files to
>>> process.
>>> Can anybody clear up any possible issues or provide some insight with
>>> the way BlockingQueue works and any possible memory issues I should be
>>> keeping an eye out for (there isn't much information that I could find
>>> from my own Google searches).

>> Here are some potential reasons for the slowdown:
>>
>> - your objects are large and you are tight on JVM memory so GC has to
>> kick in more often or your JVM starts swapping to disk
>>
>> - your processing is the slow bit (too much concurrency for example,
>> or it uses too much mem per processing instance)
>>
>> There are probably more but without more detail we can't really tell.

>
> Thanks for the tips. I checked into the "objects are large...so GC
> hast to kick in more often" Turns out this is the problem. I forgot
> I had done it, but I was making deep copies of objects to put onto the
> BlockingQueue so the user could continue to edit the file but the file
> (at that point in time) could also be processed.
>
> Of course, creating deep copies quickly fills up memory, so I quickly
> ran out of memory. I can easily fix this by putting the (reference
> to) the object on the queue directly instead of a copy of the object,
> but, unfortunately that raises the problem where users can continue
> editing objects and what they originally put in the queue will not be
> what's processed if they have continued to make changes to the file
> (the processing is done in a separate thread).
>
> Any suggestions on how to handle this problem?


Increase heap size. Or, since you are using a blocking queue anyway,
use a lower max size for the queue. Deal with your "files" (whatever
that means) more efficiently.

> Anyway, even if there isn't (I've come up with a temporary solution
> for now), thank you for your helpful suggestions on the memory problem.


I'm glad you figured out.

Kind regards

robert
 
Reply With Quote
 
Patricia Shanahan
Guest
Posts: n/a
 
      04-26-2007
Jason Cavett wrote:
> On Apr 25, 9:57 am, Robert Klemme <shortcut...@googlemail.com> wrote:
>> On 25.04.2007 15:47, Jason Cavett wrote:
>>
>>> I am currently in the process of using a BlockingQueue
>>> (LinkedBlockingQueue, to be exact) to help with a producer/consumer
>>> aspect of an application I'm developing. The user can continuously
>>> add items to the queue for processing (and this does work). However,
>>> I'm a little confused about how a BlockingQueue works.
>>> When I add an item to the BlockingQueue, is the items copied into the
>>> queue, or is it just a reference to the actual object?

>> The blocking queue holds on to objects in the queue like any other
>> collection does.
>>
>>> The reason I ask is because I notice that after adding 9 to 11 items
>>> into the queue, the application slows considerably (despite the fact
>>> that the "queue" stuff is running in a separate thread).

>> What is an "item"?
>>
>>> After
>>> watching the output from the garbage collector, it appears as though I
>>> have a memory leak. I attempted to use hprof to profile my
>>> application to see where the memory leak is taking place, but I'm not

>> hprof is unlikely to help you with detecting memory leaks other than
>> finding excessive creation of instances. But to get a leak you must
>> also be holding on to those instances longer than intended which is
>> something you do not get from hprof IIRC. You might want to look at one
>> of the various profiler / memory analyzer tools around (JProbe,
>> OptimizeIt, Eclipse TPTP).
>>
>>> fully understanding the output of hprof. When my application lags
>>> like this, it somewaht defeats the purpose of the use of the
>>> BlockingQueue since I want users to be able to queue up files to
>>> process.
>>> Can anybody clear up any possible issues or provide some insight with
>>> the way BlockingQueue works and any possible memory issues I should be
>>> keeping an eye out for (there isn't much information that I could find
>>> from my own Google searches).

>> Here are some potential reasons for the slowdown:
>>
>> - your objects are large and you are tight on JVM memory so GC has to
>> kick in more often or your JVM starts swapping to disk
>>
>> - your processing is the slow bit (too much concurrency for example,
>> or it uses too much mem per processing instance)
>>
>> There are probably more but without more detail we can't really tell.
>>
>> Regards
>>
>> robert

>
> Thanks for the tips. I checked into the "objects are large...so GC
> hast to kick in more often" Turns out this is the problem. I forgot
> I had done it, but I was making deep copies of objects to put onto the
> BlockingQueue so the user could continue to edit the file but the file
> (at that point in time) could also be processed.
>
> Of course, creating deep copies quickly fills up memory, so I quickly
> ran out of memory. I can easily fix this by putting the (reference
> to) the object on the queue directly instead of a copy of the object,
> but, unfortunately that raises the problem where users can continue
> editing objects and what they originally put in the queue will not be
> what's processed if they have continued to make changes to the file
> (the processing is done in a separate thread).
>
> Any suggestions on how to handle this problem?


Here are a couple of ideas, summary information and lazy copy.

You might be able to pick out a subset of the data represented by the
entire deep copy that covers everything that really needs to go through
the blocking queue. Construct a new object that represents just that
data, and put it on the queue.

In a lazy copy approach you make a note of the fact that there is a
virtual copy of the object, but just put the object reference on the
queue. If the virtual copy makes it to the head of the queue without the
original being modified, you just remove the note of its existence. You
actually do the deep clone if, and only if, the user does something that
changes the value of the original before you have finished with the
virtual copy.

Patricia
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Information technology is incomplete without information security alannis.albert@googlemail.com Computer Support 0 04-14-2008 06:42 AM
More Information than just IIS Log Information subrato ASP .Net 8 03-14-2006 09:59 PM
multiple, independent references to collections and blockingqueue iterators falcon Java 4 12-22-2005 04:42 AM
signer information does not match signer information of other classes in the same package clercmedia Java 2 12-09-2005 03:14 PM
strange information from asp.net trace / getting performance information using WebRequest and StreamReader z. f. ASP .Net 0 02-03-2005 11:23 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57