Discussion:
RecipientInformation.getContentStream causes the OutOfMemoryException
j.cinco
2014-07-23 08:27:38 UTC
Permalink
By the way I'm using version 1.49



--
View this message in context: http://bouncy-castle.1462172.n4.nabble.com/RecipientInformation-getContentStream-causes-the-OutOfMemoryException-tp4657241p4657242.html
Sent from the Bouncy Castle - Dev mailing list archive at Nabble.com.
David Hook
2014-07-23 08:45:16 UTC
Permalink
Try getting rid of the ByteArrayOutputStream in processDataStream.

Regards,

David
Post by j.cinco
By the way I'm using version 1.49
--
View this message in context: http://bouncy-castle.1462172.n4.nabble.com/RecipientInformation-getContentStream-causes-the-OutOfMemoryException-tp4657241p4657242.html
Sent from the Bouncy Castle - Dev mailing list archive at Nabble.com.
j.cinco
2014-07-23 10:00:39 UTC
Permalink
Hi David,

Thanks for the reply. I think that will not solve the OutOfMemory issue
since the memory leak is coming from RecipientInformation.getContentStream.
Just to prove that my thinking is right, I've tried to comment out the code
where I'm using RecipientInformation and based on the JProfiler result the
method which is RecipientInformation.getContentStream isn't already included
in the Hotspot list which is before it's in the number 1 spot. See screen
shot below.

*Before commenting the RecipientInformation*

<Loading Image...>

*After commenting the RecipientInformation*

<Loading Image...>
<Loading Image...>

Best,
Jose




--
View this message in context: http://bouncy-castle.1462172.n4.nabble.com/RecipientInformation-getContentStream-causes-the-OutOfMemoryException-tp4657241p4657244.html
Sent from the Bouncy Castle - Dev mailing list archive at Nabble.com.
Lothar Kimmeringer
2014-07-23 10:14:48 UTC
Permalink
Post by j.cinco
Thanks for the reply. I think that will not solve the OutOfMemory issue
since the memory leak is coming from RecipientInformation.getContentStream.
Just to prove that my thinking is right, I've tried to comment out the code
where I'm using RecipientInformation and based on the JProfiler result the
method which is RecipientInformation.getContentStream isn't already included
in the Hotspot list which is before it's in the number 1 spot. See screen
shot below.
all your screenshots show CPU-times and not memory-usage. I don't
use JProfiler but Yourkit but I assume that JProfiler is also able
to show what classes uses how much memory (memory allocation count).

Can you try to use CMSEnvelopedData instead of CMSEnvelopedParser.

If that doesn't help, either, please check where memory is lost
(JProfiler should be able to do that if it's worth its money).


Cheers, Lothar
j.cinco
2014-07-24 09:57:11 UTC
Permalink
Hi Lothar,

Please see the screen shot below for the memory allocated by
RecipientInformation and BouncyCastleProvider. Since I'm using version 1.49
I'll try to use the latest version which I think 1.50 and see if there's
already a fix. I set the maxPermSize of tomcat to -XX:MaxPermSize=1536m and
based on the total memory allocation for both classes it exceeds to the max
perm size and that's when the OutOfMemoryException occurs. This happens
after 4 hours of continuous execution of the web service method.

<Loading Image...>

<Loading Image...>

Cheers,
Jose



--
View this message in context: http://bouncy-castle.1462172.n4.nabble.com/RecipientInformation-getContentStream-causes-the-OutOfMemoryException-tp4657241p4657246.html
Sent from the Bouncy Castle - Dev mailing list archive at Nabble.com.
Lothar Kimmeringer
2014-07-24 10:41:53 UTC
Permalink
Post by j.cinco
Please see the screen shot below for the memory allocated by
RecipientInformation and BouncyCastleProvider.
Maybe it's my inability to see anything, but the only classes
in the list I can see are your own. There is no mention of
BC-classes.
Post by j.cinco
Since I'm using version 1.49
I'll try to use the latest version which I think 1.50 and see if there's
already a fix.
I don't think that the problem is within BC. What's the
implementation of your decrypt-method? Are you using global
members and is the instance reused?
Post by j.cinco
I set the maxPermSize of tomcat to -XX:MaxPermSize=1536m and
based on the total memory allocation for both classes it exceeds to the max
perm size and that's when the OutOfMemoryException occurs.
maxpermsize is something different and doesn't solve the problem.


Cheers, Lothar
j.cinco
2014-07-24 11:13:19 UTC
Permalink
If you check the first screen shot on my latest post you can see that
"org.bouncycastle.jce.provider.BouncyCastleProvier" memory allocation is
"1192 MB" and for the second screen shot
"org.bouncycastle.cms.RecipientInformation.getContentStream" memory
allocation is "581MB".

Cheers,
Jose



--
View this message in context: http://bouncy-castle.1462172.n4.nabble.com/RecipientInformation-getContentStream-causes-the-OutOfMemoryException-tp4657241p4657248.html
Sent from the Bouncy Castle - Dev mailing list archive at Nabble.com.
Lothar Kimmeringer
2014-07-24 12:28:16 UTC
Permalink
Post by j.cinco
If you check the first screen shot on my latest post you can see that
"org.bouncycastle.jce.provider.BouncyCastleProvier" memory allocation is
"1192 MB"
as I said, I'm not used to JProfiler. Why do you instantiate
BouncyCastleProvider millions of times? You only do that once
to add it to java.security.Security. Change that to let that
happen only once and try again.
Post by j.cinco
and for the second screen shot
"org.bouncycastle.cms.RecipientInformation.getContentStream" memory
allocation is "581MB".
Is JProfiler showing the class that allocates memory? If that's
the case, it still can be a bug in your own code (which is most
likely), since you might not clear resources in a proper way
leading to this effect. So my question remains valid: What is
the implementation of your decrypt-method?


Cheers, Lothar
Tim Whittington
2014-07-24 19:56:19 UTC
Permalink
Post by j.cinco
If you check the first screen shot on my latest post you can see that
"org.bouncycastle.jce.provider.BouncyCastleProvier" memory allocation is
"1192 MB" and for the second screen shot
"org.bouncycastle.cms.RecipientInformation.getContentStream" memory
allocation is "581MB”.
This is the JProfiler hotspot view, which is showing I believe _cumulative_ allocation, not retained objects.
In this case, 1192MB/22.6 million = ~53B per instance for the provider and 581MB/15.5 million = ~37B per instance for the getContentStream,

The latter is nothing out of the ordinary if you’re doing a lot of transactions (i.e. something proportionate to 15.5 million).
The former is highly unusual in that you should only need to instantiate the BC provider once (i.e. some kind of static registration like a servlet context listener/OSGi bundle activator/static block).

Neither of these though is evidence of a memory leak though - I’d suggest looking at the All Object/Recorded Objects view in JProfiler (I’m looking at version 7, it might have changed names in 8) or analysing a heap dump with http://www.eclipse.org/mat/.

cheers
tim
j.cinco
2014-07-25 06:21:38 UTC
Permalink
Hi Tim Whittington,

Thanks for your suggestion. Yesterday I tried to create only one instance
for BouncyCastleProvider class but didn't declare it as global static
variable it does improve but after 12 hours of continuous execution of the
web service method it crashed. Now somehow other developer has change it to
global static variable and now it shows a stable usage of memory heap. And
as I checked on the "Live Memory->Allocation Hot Spots" it's not included on
the list of hotspots also the RecipientInformation.getContentStream only
allocates small memory. I will let JProfiler run overnight and hope the
stability of the usage of memory heap will continue. I'll just post on this
forum if it really solve the issue. Anyways thanks in advance guys
especially to you Master Tim.

Cheers,
Jose



--
View this message in context: http://bouncy-castle.1462172.n4.nabble.com/RecipientInformation-getContentStream-causes-the-OutOfMemoryException-tp4657241p4657254.html
Sent from the Bouncy Castle - Dev mailing list archive at Nabble.com.
j.cinco
2014-07-28 06:06:09 UTC
Permalink
This was resolved.

Cheers,
Jose



--
View this message in context: http://bouncy-castle.1462172.n4.nabble.com/RecipientInformation-getContentStream-causes-the-OutOfMemoryException-tp4657241p4657258.html
Sent from the Bouncy Castle - Dev mailing list archive at Nabble.com.
Loading...