# Rails/JRuby WAR Heap Space Issue

**URL:** <https://www.ruby-forum.com/t/rails-jruby-war-heap-space-issue/180602>\
**Category:** Rails\
**Created:** [December 22, 2009, 6:01pm UTC](https://www.ruby-forum.com/t/rails-jruby-war-heap-space-issue/180602 "2009-12-22T18:01:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelF](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecc23a/32.png) [@MichaelF](https://www.ruby-forum.com/u/MichaelF)\
**Post date:** [December 22, 2009, 6:01pm UTC](https://www.ruby-forum.com/t/rails-jruby-war-heap-space-issue/180602/1 "2009-12-22T18:01:09Z")

</div>

I am using JRuby / Rails / Glassfish Gem to run an app on Tomcat.

When someone submits a large file as an uploaded file I see the  
following in the log:

Processing ScholarshipsController#create (for 174.120.167.34 at  
2009-12-21 10:03:13) [POST]  
Parameters:  
{“authenticity\_token”=\>“9c26734a0f31…bf3a9d644e9001abb931”,  
“scholarship”=\>{…data removed for privacy…}

Dec 21, 2009 10:03:15 AM org.apache.catalina.core.StandardWrapperValve  
invoke  
SEVERE: Servlet.service() for servlet default threw exception  
java.lang.OutOfMemoryError: Java heap space  
at org.jruby.util.Pack.unpack(Pack.java:924)  
at org.jruby.RubyString.unpack(RubyString.java:6806)  
at org.jruby.RubyString$i\_method\_1\_0$RUBYINVOKER$unpack.call  
(org/  
jruby/RubyString$i\_method\_1\_0$RUBYINVOKER$unpack.gen)  
at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall  
(CachingCallSite.java:310)  
at org.jruby.runtime.callsite.CachingCallSite.call  
(CachingCallSite.java:149)  
at  
ruby.jit.ruby.home.mfromin.jvm.apache\_minus\_tomcat\_minus\_6\_dot\_0\_dot\_14.domains.scholarships\_dot\_sam\_dot\_org.SamScholar.WEB\_minus\_INF.gems.gems.activerecord\_minus\_jdbc\_minus\_adapter\_minus\_0\_dot\_9\_dot\_2.lib.jdbc\_adapter.jdbc\_mysql.quote17997250\_17974850. **file**  
(jdbc\_mysql.rb:82)  
at  
ruby.jit.ruby.home.mfromin.jvm.apache\_minus\_tomcat\_minus\_6\_dot\_0\_dot\_14.domains.scholarships\_dot\_sam\_dot\_org.SamScholar.WEB\_minus\_INF.gems.gems.activerecord\_minus\_jdbc\_minus\_adapter\_minus\_0\_dot\_9\_dot\_2.lib.jdbc\_adapter.jdbc\_mysql.quote17997250\_17974850. **file**  
(jdbc\_mysql.rb)  
at org.jruby.ast.executable.AbstractScript. **file**  
(AbstractScript.java:51)  
at org.jruby.internal.runtime.methods.JittedMethod.call  
(JittedMethod.java:187)  
at org.jruby.runtime.callsite.CachingCallSite.call  
(CachingCallSite.java:187)  
at  
ruby.jit.ruby.home.mfromin.jvm.apache\_minus\_tomcat\_minus\_6\_dot\_0\_dot\_14.domains.scholarships\_dot\_sam\_dot\_org.SamScholar.WEB\_minus\_INF.gems.gems.activerecord\_minus\_2\_dot\_2\_dot\_2.lib.active\_record.base.attributes\_with\_quotes1213394\_2293223.block\_0$RUBY  
$ **block** (base.rb:2817)  
at  
ruby.jit.ruby.home.mfromin.jvm.apache\_minus\_tomcat\_minus\_6\_dot\_0\_dot\_14.domains.scholarships\_dot\_sam\_dot\_org.SamScholar.WEB\_minus\_INF.gems.gems.activerecord\_minus\_2\_dot\_2\_dot\_2.lib.active\_record.base.attributes\_with\_quotes1213394\_2293223BlockCallback  
$block\_0$RUBY$\_\_block\_\_xx1.call(Unknown Source)  
at org.jruby.runtime.CompiledBlock.yield(CompiledBlock.java:  
105)  
at org.jruby.runtime.Block.yield(Block.java:194)  
at org.jruby.RubyArray.eachCommon(RubyArray.java:1635)  
at org.jruby.RubyArray.each(RubyArray.java:1642)  
at org.jruby.RubyArray$i\_method\_0\_0$RUBYFRAMEDINVOKER$each.call  
(org/  
jruby/RubyArray$i\_method\_0\_0$RUBYFRAMEDINVOKER$each.gen)  
at org.jruby.runtime.callsite.CachingCallSite.callBlock  
(CachingCallSite.java:116)  
at org.jruby.runtime.callsite.CachingCallSite.callIter  
(CachingCallSite.java:133)  
at  
ruby.jit.ruby.home.mfromin.jvm.apache\_minus\_tomcat\_minus\_6\_dot\_0\_dot\_14.domains.scholarships\_dot\_sam\_dot\_org.SamScholar.WEB\_minus\_INF.gems.gems.activerecord\_minus\_2\_dot\_2\_dot\_2.lib.active\_record.base.attributes\_with\_quotes1213394\_2293223. **file**  
(base.rb:2808)  
at  
ruby.jit.ruby.home.mfromin.jvm.apache\_minus\_tomcat\_minus\_6\_dot\_0\_dot\_14.domains.scholarships\_dot\_sam\_dot\_org.SamScholar.WEB\_minus\_INF.gems.gems.activerecord\_minus\_2\_dot\_2\_dot\_2.lib.active\_record.base.attributes\_with\_quotes1213394\_2293223. **file**  
(base.rb)  
at org.jruby.internal.runtime.methods.JittedMethod.call  
(JittedMethod.java:102)  
at org.jruby.internal.runtime.methods.DefaultMethod.call  
(DefaultMethod.java:147)  
at org.jruby.internal.runtime.methods.AliasMethod.call  
(AliasMethod.java:76)  
at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall  
(CachingCallSite.java:280)  
at org.jruby.runtime.callsite.CachingCallSite.call  
(CachingCallSite.java:69)  
at  
ruby.jit.ruby.home.mfromin.jvm.apache\_minus\_tomcat\_minus\_6\_dot\_0\_dot\_14.domains.scholarships\_dot\_sam\_dot\_org.SamScholar.WEB\_minus\_INF.gems.gems.activerecord\_minus\_jdbc\_minus\_adapter\_minus\_0\_dot\_9\_dot\_2.lib.active\_record.connection\_adapters.jdbc\_adapter.attributes\_with\_quotes24825033\_2293223. **file**  
(jdbc\_adapter.rb:67)  
at  
ruby.jit.ruby.home.mfromin.jvm.apache\_minus\_tomcat\_minus\_6\_dot\_0\_dot\_14.domains.scholarships\_dot\_sam\_dot\_org.SamScholar.WEB\_minus\_INF.gems.gems.activerecord\_minus\_jdbc\_minus\_adapter\_minus\_0\_dot\_9\_dot\_2.lib.active\_record.connection\_adapters.jdbc\_adapter.attributes\_with\_quotes24825033\_2293223. **file**  
(jdbc\_adapter.rb)  
at org.jruby.ast.executable.AbstractScript. **file**  
(AbstractScript.java:43)  
at org.jruby.internal.runtime.methods.JittedMethod.call  
(JittedMethod.java:119)  
at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall  
(CachingCallSite.java:290)  
at org.jruby.runtime.callsite.CachingCallSite.call  
(CachingCallSite.java:109)  
Dec 21, 2009 10:07:42 AM org.apache.catalina.core.ApplicationContext  
log

Is this issue caused on the upload itself or when the file is  
attempting to be persisted to MySQL? Is it caused when the file is  
uploaded but not yet persisted?

What is the best way to address this? Can I limit the size of the  
file uploaded?

I currently have 64MB heap space - I can update this but don’t want to  
spend more $$ with my host if there is a better solution.

–

You received this message because you are subscribed to the Google  
Groups “Ruby on Rails: Talk” group.  
To post to this group, send email to removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

---

<div class="post-metadata">

**Author:** ![MichaelF](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecc23a/32.png) [@MichaelF](https://www.ruby-forum.com/u/MichaelF)\
**Post date:** [December 22, 2009, 6:13pm UTC](https://www.ruby-forum.com/t/rails-jruby-war-heap-space-issue/180602/2 "2009-12-22T18:13:26Z")

</div>

On Tue, Dec 22, 2009 at 8:59 AM, MichaelF [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am using JRuby / Rails / Glassfish Gem to run an app on Tomcat.

Sorry, right off the bat that makes zero sense.

Are you using Tomcat or the Glassfish gem to run your app? It can’t  
be both.

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

–

You received this message because you are subscribed to the Google  
Groups “Ruby on Rails: Talk” group.  
To post to this group, send email to removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

---

<div class="post-metadata">

**Author:** ![MichaelF](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecc23a/32.png) [@MichaelF](https://www.ruby-forum.com/u/MichaelF)\
**Post date:** [December 22, 2009, 6:34pm UTC](https://www.ruby-forum.com/t/rails-jruby-war-heap-space-issue/180602/3 "2009-12-22T18:34:30Z")

</div>

On Tue, Dec 22, 2009 at 8:59 AM, MichaelF [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am using JRuby / Rails / Glassfish Gem to run an app on Tomcat.

OK, never mind the previous comment – looking at the stack trace  
it’s obviously Tomcat.

> invoke  
> SEVERE: Servlet.service() for servlet default threw exception  
> java.lang.OutOfMemoryError: Java heap space

> Is this issue caused on the upload itself or when the file is  
> attempting to be persisted to MySQL? Is it caused when the file is  
> uploaded but not yet persisted?

Are you really saving a file to MySQL? Not usually recommended.

> What is the best way to address this? Can I limit the size of the  
> file uploaded?

Probably – what are you using to handle the upload now?

> I currently have 64MB heap space -

Regardless of anything else, that seems awfully low. What are the  
startup params for Tomcat?

Have you tried uploading to a local instance with more memory?

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

–

You received this message because you are subscribed to the Google  
Groups “Ruby on Rails: Talk” group.  
To post to this group, send email to removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

---

<div class="post-metadata">

**Author:** ![MichaelF](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecc23a/32.png) [@MichaelF](https://www.ruby-forum.com/u/MichaelF)\
**Post date:** [December 22, 2009, 8:29pm UTC](https://www.ruby-forum.com/t/rails-jruby-war-heap-space-issue/180602/4 "2009-12-22T20:29:13Z")

</div>

I am using both Tomcat and the Glassfish GEM (not Glassfish server).  
The Glassfish gem replaces Mongrel in the stack.

As for the file - I am aware of the pros/cons of storing the file in  
the DB and for this specific app storing the PDF in the DB is indeed  
what I want to do.  
The DB will not ever exceed 500 records and a single person should  
never have more than one file so its easy enough to overwrite what is  
in the db.

As for the heap - what I am really trying to determine is whether or  
not the issue is really heap size or something in MySQL such as  
max\_packet\_size.

On my local test server I have never had heap issues (but I have more  
than 64 MB) but I did get max\_packet\_size errors before increasing  
that on MySQL. From the hosting side I just  
have less control over the server and fewer things I can see myself.

On Dec 22, 10:32 am, Hassan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > When someone submits a large file as an uploaded file I see the  
> > SEVERE: Servlet.service() for servlet default threw exception  
> > Probably – what are you using to handle the upload now?  
> > twitter: @hassan  
> > –

You received this message because you are subscribed to the Google  
Groups “Ruby on Rails: Talk” group.  
To post to this group, send email to removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

---

<div class="post-metadata">

**Author:** ![MichaelF](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecc23a/32.png) [@MichaelF](https://www.ruby-forum.com/u/MichaelF)\
**Post date:** [December 22, 2009, 8:45pm UTC](https://www.ruby-forum.com/t/rails-jruby-war-heap-space-issue/180602/5 "2009-12-22T20:45:02Z")

</div>

On Tue, Dec 22, 2009 at 11:05 AM, MichaelF [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am using both Tomcat and the Glassfish GEM (not Glassfish server).  
> The Glassfish gem replaces Mongrel in the stack.

I use all three in various circumstances, and I can’t begin to imagine  
how you think the GF gem is being used in conjunction with Tomcat.  
But whatever.

> As for the heap - what I am really trying to determine is whether or  
> not the issue is really heap size or something in MySQL such as  
> max\_packet\_size.

Your error log shows an OOM - I’d say it’s pretty obvious. But if you  
want more detail, set up the JVM to heap dump on OOM and look  
at the dump with a profiler.

Or set up your local test system with 64Mb and recreate it there with  
more logging.

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

–

You received this message because you are subscribed to the Google  
Groups “Ruby on Rails: Talk” group.  
To post to this group, send email to removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).
