jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Jetty
  • JETTY-188

Use a timer for session cleanup rather than blocking a thread

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 6.0.0
  • Fix Version/s: 6.1.2rc1
  • Component/s: None
  • Labels:
    None

Description

I've noticed that for each HashSessionManager that's created – and Jetty seems to create one per web app context – Jetty takes a thread out of the thread pool and blocks that thread to do periodic session cleanup. So, we end up creating a thread per web app context, and each such thread spends most of its time sleeping.

It'd be a lot more scalable if Jetty used a timer for this, so that there can be one thread per Jetty server that is doing the cleanup for lots of web apps. That way, we have fewer threads. Furthermore, this way the thread pool remains to be used for short-running tasks, which is what thread pools are good for, rather than for one task that typically lasts for the lifetime of the web app.

I was able to add this feature pretty easily to "trunk" by adding a "TimerManager" interface to org.mortbay.thread, and an implementation that uses the java.util.Timer class. Then, it was a pretty small change to AbstractSessionManager to get it to use this, and it also meant that a bunch of complex code could be eliminated from that class. I'll attach the patch.

The downside of what I did is that it uses java.util.Timer, which I believe may not be available on all editions of Java (such as Java ME). If that's an issue, I'm sure we can come up with a timer implementation that does not require this class from the JVM.

The JAR that I attached includes three new classes for the "org.mortbay.thread" package, plus patches for AbstractSessionManager and Server to use them.

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Hide
    Java Archive File
    timer-patch.jar
    05/Dec/06 4:09 PM
    4 kB
    Greg Brail
    1. File
      META-INF/MANIFEST.MF 0.1 kB
    2. Text File
      diff.txt 7 kB
    3. Java Source File
      modules/util/.../JavaTimerManager.java 1 kB
    4. Java Source File
      modules/util/src/.../thread/Timer.java 0.2 kB
    5. Java Source File
      modules/util/.../thread/TimerManager.java 0.6 kB
    Download Zip
    Show
    Java Archive File
    timer-patch.jar
    05/Dec/06 4:09 PM
    4 kB
    Greg Brail

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Greg Wilkins added a comment - 08/Dec/06 5:58 AM

probably a good idea.... but I think I will defer for a few weeks.
The solution must work on 1.4 - but a pluggable 1.5 solution would be good.
There are quiet a few things that need this timer behaviour, so I would want a solution that
could be used for sessions, rollover logs, etc, etc.

So thanks for the patch.... ping me if I have not commented on it in 2 weeks.

Show
Greg Wilkins added a comment - 08/Dec/06 5:58 AM probably a good idea.... but I think I will defer for a few weeks. The solution must work on 1.4 - but a pluggable 1.5 solution would be good. There are quiet a few things that need this timer behaviour, so I would want a solution that could be used for sessions, rollover logs, etc, etc. So thanks for the patch.... ping me if I have not commented on it in 2 weeks.
Hide
Permalink
Greg Brail added a comment - 08/Dec/06 9:41 AM

Sounds like a fine thing to me – I just wanted to get this issue onto the queue.

Just so you know, java.util.Timer was added in JDK 1.3. It's present in any Java SE version that we should expect Jetty to be running on. However, I don't believe it's in Java ME (aka J2ME), so if the intention is to have Jetty function in this environment as well, then we'd want to use a different default implementation other than java.util.Timer.

The patch includes an abstract "org.mortbay.thread.Timer" interface, plus an implementation, so that people embedding Jetty (like me) can plug in their own timer implementation if they want (and I do)!

Show
Greg Brail added a comment - 08/Dec/06 9:41 AM Sounds like a fine thing to me – I just wanted to get this issue onto the queue. Just so you know, java.util.Timer was added in JDK 1.3. It's present in any Java SE version that we should expect Jetty to be running on. However, I don't believe it's in Java ME (aka J2ME), so if the intention is to have Jetty function in this environment as well, then we'd want to use a different default implementation other than java.util.Timer. The patch includes an abstract "org.mortbay.thread.Timer" interface, plus an implementation, so that people embedding Jetty (like me) can plug in their own timer implementation if they want (and I do)!
Hide
Permalink
Greg Wilkins added a comment - 18/Mar/07 11:24 PM

Was fixed in last release

Show
Greg Wilkins added a comment - 18/Mar/07 11:24 PM Was fixed in last release

People

  • Assignee:
    Greg Wilkins
    Reporter:
    Greg Brail
Vote (0)
Watch (0)

Dates

  • Created:
    05/Dec/06 4:09 PM
    Updated:
    18/Mar/07 11:24 PM
    Resolved:
    18/Mar/07 11:24 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.