public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Per Bothner <per@bothner.com>
To: Matthieu Vachon <matthieu.o.vachon@gmail.com>,
	Damien MATTEI <Damien.Mattei@unice.fr>
Cc: "kawa@sourceware.org" <kawa@sourceware.org>
Subject: Re: kawa and apache tomcat
Date: Fri, 15 Jan 2016 18:41:00 -0000	[thread overview]
Message-ID: <56993D3C.20105@bothner.com> (raw)
In-Reply-To: <CAOTvmok1GsBotq=vRfScz0JV08XhqF9M0E4yAiMmNr-gzoMmBg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1106 bytes --]



On 01/15/2016 10:10 AM, Matthieu Vachon wrote:


> This is not a problem in a standard JVM application because once the
> application closes, nothing needs to be done. But in a container
> environment, that's another story since thread a kinda re-used over
> multiple requests. On high load, this can create huge memory leaks
> depending on the what is actually stored.

As I understand it, the problem is not normal usage, but when a servlet is re-loaded.
That creates a new ClassLoader, with a new set of Classes which causes
some complicated interaction with the GC (which I don't properly understand).

In normal usage,with no ClassLoader churn, there might be some temporary leak,
but the garbage should become collectible when a thread services a new request.

Could you try the attached patch?  I haven't actually tested it (except
to verify it compiles).  Let me know if it makes a difference.
It is possible it might *reduce* the number but not eliminate the
warnings.  If so, we would be on the right track, though with more to do.

-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

[-- Attachment #2: servet.patch --]
[-- Type: text/x-patch, Size: 1849 bytes --]

Index: gnu/kawa/servlet/KawaServlet.java
===================================================================
--- gnu/kawa/servlet/KawaServlet.java	(revision 8666)
+++ gnu/kawa/servlet/KawaServlet.java	(working copy)
@@ -41,17 +41,9 @@
     throws ServletException, IOException
   {
     CallContext ctx = CallContext.getInstance();
-    HttpRequestContext hctx = HttpRequestContext.instance.get();
-    Context sctx;
-    if (hctx instanceof Context)
-      sctx = (Context) hctx;
-    else
-      {
-        sctx = new Context();
-        Context.setInstance(sctx);
-      }
-    sctx.init(this, request, response);
+    Context sctx = new Context(this, request, response);
     ctx.consumer = sctx.getConsumer();
+    Context.setInstance(sctx);
     // FIXME should path be relative to context?
     Path.setCurrentPath(Path.valueOf(request.getRequestURL().toString()));
     ctx.values = Values.noArgs;
@@ -100,6 +92,7 @@
       }
     finally
       {
+        Context.setInstance(null);
         sctx.servlet = null;
         sctx.request = null;
         sctx.response = null;
@@ -115,8 +108,8 @@
     ServletContext context;
     Map<String,Object> requestParameters;
 
-    public void init(HttpServlet servlet, HttpServletRequest request,
-                     HttpServletResponse response)
+    public Context(HttpServlet servlet, HttpServletRequest request,
+                   HttpServletResponse response)
     {
       if (response == null)
         throw new Error("init with null response");
@@ -317,7 +310,7 @@
     public List<String> getRequestHeaders (String name)
     {
       java.util.Enumeration<java.lang.String> e = request.getHeaders(name);
-      List<String> list = new ArrayList();
+      List<String> list = new ArrayList<String>();
       while (e.hasMoreElements())
         {
           list.add(e.nextElement());

  reply	other threads:[~2016-01-15 18:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-15 10:53 Damien MATTEI
2016-01-15 18:10 ` Matthieu Vachon
2016-01-15 18:41   ` Per Bothner [this message]
2016-01-19 14:07     ` Damien MATTEI

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56993D3C.20105@bothner.com \
    --to=per@bothner.com \
    --cc=Damien.Mattei@unice.fr \
    --cc=kawa@sourceware.org \
    --cc=matthieu.o.vachon@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).