SitePoint Sponsor

User Tag List

Results 1 to 20 of 20
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2006
    Location
    Halifax, Canada
    Posts
    498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Server-side java: Best performance?

    I have been playing with an application that I wrote in PHP. I built the PHP version as a prototype, intending to eventually re-write it in Java. Now I am wondering, what is the best way to set up the Java applications to run on an Apache server in terms of performance?

    It is actually more of a web based app than a web site. Since each request would go through the same app, it would be ideal to keep the app in memory only once, but I do not know if this is possible or how to do it.

    Also - I don't need any template engine or anything, it would just get in the way.
    Paul Butler.org
    JSSpamBlock - Reduce WordPress spam.

  2. #2
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Pittsburgh, Los Angeles
    Posts
    706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is really no way to run a java application in apache (no stable way at least), instead you run a container like Tomcat, Resin etc both of which are basic web servers. A few different things you can do are:

    - Run a standalone servlet container like tomcat, resin etc. These work as basic web servers and can deal with the dynamic as well as the static content. Although each
    isn't as feature rich as apache.

    - Run both tomcat (resin etc) and apache. Where tomcat deals with the dynamic content
    and apache the static content. This is ideal in cases where you have a lot of static content. Although the difference is small apache is faster for static content than tomcat etc.

    - Use apache as a front-end server and proxy requests for dynamic content to tomcat (or resin etc). This is usually what people end up doing because you can take advantage of all the features of apache, have apache easily deal with static content and then proxy dynamic results to tomcat etc. You can do this easily using the apache module mod_jk, or if you are using apache 2.2 you can use mod_proxy_ajp. Although with this solution you do lose a bit of performance due to the proxy (it isn't so bad though).

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2006
    Location
    Halifax, Canada
    Posts
    498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the info. I will look into Tomcat, it seems to be exactly what I need.
    Paul Butler.org
    JSSpamBlock - Reduce WordPress spam.

  4. #4
    SitePoint Zealot
    Join Date
    May 2005
    Location
    Mud people of Worksop
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't waste your time running an Apache frontend to Tomcat unless you need access to Apache only features.

    In my experience, Resin will out perform Apache with Tomcat or just Tomcat.

    I've not yet tried Glassfish although I shall be deploying a server with it later this week.

  5. #5
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    Mission Viejo, CA, USA
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What are you refering to when you say Apache? It sounds like it's a separate piece of software from Tomcat while I know Apache as the organization that oversees the development of products like Tomcat. What am I missing here?
    SalaryMap.com - Your salary on the map
    Mix Breed Dog Pictures

  6. #6
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tbarr60 View Post
    What are you refering to when you say Apache? It sounds like it's a separate piece of software from Tomcat while I know Apache as the organization that oversees the development of products like Tomcat. What am I missing here?
    apache is the actual web server being discussed, while Tomcat is the servlet container for serving servlets and JSp pages.

    If you're only going to serve Java content, then I'd use Tomcat. However if there's other dynamic content such as PHP, etc, then use Apache to handle that other content.
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd

  7. #7
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Pittsburgh, Los Angeles
    Posts
    706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't waste your time running an Apache frontend to Tomcat
    If you care about reliability, then you are most likely going to want to load balance 2+ instances of tomcat. Using an apache frontend is the
    easiest way to do this.

    Also apache does better on static content than both tomcat and resin, partciularly for small/medium files so if there is a lot of such content then it makes sense to also use apache.

  8. #8
    SitePoint Zealot
    Join Date
    May 2005
    Location
    Mud people of Worksop
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Snaily View Post
    If you care about reliability, then you are most likely going to want to load balance 2+ instances of tomcat.
    Why ? I'm a bit simple so you'll have to fill me in.

    Quote Originally Posted by Snaily View Post
    Also apache does better on static content than both tomcat and resin, partciularly for small/medium files so if there is a lot of such content then it makes sense to also use apache.
    Does it? Based on what evidence Sir ?

  9. #9
    SitePoint Evangelist
    Join Date
    Apr 2006
    Location
    Halifax, Canada
    Posts
    498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sks View Post
    Does it? Based on what evidence Sir ?
    I havn't tried it myself, but it makes perfect sense that a web server like Apache would be more optimized for static content. This would be more noticeable on small files as the speed overhead would be more apparent.

    Quote Originally Posted by Snaily View Post
    If you care about reliability, then you are most likely going to want to load balance 2+ instances of tomcat. Using an apache frontend is the
    easiest way to do this.

    Also apache does better on static content than both tomcat and resin, partciularly for small/medium files so if there is a lot of such content then it makes sense to also use apache.
    I'm not going to worry about load balancing yet as this is a small, personal project. Thanks for the advice though.

    Quote Originally Posted by sks View Post
    Don't waste your time running an Apache frontend to Tomcat unless you need access to Apache only features.

    In my experience, Resin will out perform Apache with Tomcat or just Tomcat.
    Thanks, I think this is what I will do.

    Quote Originally Posted by tbarr60 View Post
    What are you refering to when you say Apache? It sounds like it's a separate piece of software from Tomcat while I know Apache as the organization that oversees the development of products like Tomcat. What am I missing here?
    The Apache Foundation's main product is the Apache web server, I think you are confusing the two.

    --------

    Thanks for all the replies
    Paul Butler.org
    JSSpamBlock - Reduce WordPress spam.

  10. #10
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Pittsburgh, Los Angeles
    Posts
    706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why ? I'm a bit simple so you'll have to fill me in.
    I guess you are. I really don't see why its hard to understand that having redundance improves your sites reliability. Why in the world would you want a hot back-up for your site? Gee I wonder. With apache you can rather trivially load-balance or have a hot back-up. Of course the benefits are greater if the instances aren't on the same server, but you gain a bit even if they are on the same server. Of course there are other ways you can do this (e.g., specialized hardward etc) but Apache offers a good solution for medium sized applications.
    Does it? Based on what evidence Sir ?
    Benchmarks, feel free to run your own it doesn't take long. It shouldn't be suprising that apache which is written in really optimized C does better than a web server written in Java. After all the underlying IO calls to the OS cost more than they do with Apache. This is also why the difference is greater for small/medium files. There is also the issue that Apache tends to do better under heavy loads than tomcat, resin etc, but that is of course harder to prove via benchmarks.

  11. #11
    SitePoint Zealot
    Join Date
    May 2005
    Location
    Mud people of Worksop
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Snaily View Post
    Benchmarks, feel free to run your own it doesn't take long. It shouldn't be suprising that apache which is written in really optimized C does better than a web server written in Java. After all the underlying IO calls to the OS cost more than they do with Apache. This is also why the difference is greater for small/medium files. There is also the issue that Apache tends to do better under heavy loads than tomcat, resin etc, but that is of course harder to prove via benchmarks.
    Come on, get in the real world ! It makes sod all difference. You're serving up 50K Gif files. It's not rocket science. ****s sake man, you're going on as if Apache is doing something special. You can write a static content server in about 30 minutes. Resin, Tomcat, Apache, they're all tested and reliable. Stop reading crap on the internet and get a job!

  12. #12
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Pittsburgh, Los Angeles
    Posts
    706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you're going on as if Apache is doing something special.
    No, I mentioned that its written in great C code which is naturally faster than Java.
    Resin, Tomcat, Apache, they're all tested and reliable.
    I never stated that Tomcat, Resin can't reliably serve static content, rather that they do it slower and with more resources than Apache. The post after all asked about performance, so that is what I posted about.
    Stop reading crap on the internet and get a job!
    Yeah, reading is very bad.

    Anyhow, this is pointless.

  13. #13
    SitePoint Zealot
    Join Date
    May 2005
    Location
    Mud people of Worksop
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Snaily View Post
    I never stated that Tomcat, Resin can't reliably serve static content, rather that they do it slower and with more resources than Apache. The post after all asked about performance, so that is what I posted about.
    But the overhead from apache connecting to tomcat might be (and in experience is) greater than just running Resin for serving static content.

  14. #14
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Pittsburgh, Los Angeles
    Posts
    706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But the overhead from apache connecting to tomcat might be (and in experience is) greater than just running Resin for serving static content.
    Well..this sort of thing is relative to your particular application. Certainly in some cases this may true, but usually requests for static resources greatly out number those for dynamic resources. Although I have no idea what the exact ratio between static/dynamic requests is required before you still a real gain in performance.

  15. #15
    SitePoint Zealot
    Join Date
    May 2005
    Location
    Mud people of Worksop
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Snaily View Post
    Well..this sort of thing is relative to your particular application. Certainly in some cases this may true, but usually requests for static resources greatly out number those for dynamic resources. Although I have no idea what the exact ratio between static/dynamic requests is required before you still a real gain in performance.
    But as I say you overestimate how hard it is to read a gif from the filesystem and stream it to a browser.

    You do realise that in Resin Pro it uses its on C library for IO anyway ?

  16. #16
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Pittsburgh, Los Angeles
    Posts
    706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You do realise that in Resin Pro it uses its on C library for IO anyway ?
    Eh? Standard Java uses a C library for IO too, it has to... Maybe Resin's is more efficient I have no idea, but the same issues apply regardless.

  17. #17
    SitePoint Zealot
    Join Date
    May 2005
    Location
    Mud people of Worksop
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Resin Pro bypasses the Java IO API and uses its own native C API. Now since you said before Apache was written in 'great c' then surely you are happy with that. If not then you're contradicting yourself.

  18. #18
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Pittsburgh, Los Angeles
    Posts
    706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Resin Pro bypasses the Java IO API and uses its own native C API.
    Java's IO api is a wrapper around C code (again it has to be, its making OS calls), how is Resin's any different? Perhaps its more efficient by bypassing security issues? I don't know.... But the same issues apply a Java application needs to call native code and this creates an overhead that Apache does not have. The only way resin would not have this overhead is if it was pure C, but that is impossible after all its a Java application server. Anyhow there is no contradiction...java's native interface is the issue this effects standard java as well as whatever resin has done.

  19. #19
    SitePoint Zealot
    Join Date
    May 2005
    Location
    Mud people of Worksop
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Snaily View Post
    Java's IO api is a wrapper around C code (again it has to be, its making OS calls), how is Resin's any different?
    Because only the essential IO calls are written in C in the Java IO API.

  20. #20
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Pittsburgh, Los Angeles
    Posts
    706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because only the essential IO calls are written in C in the Java IO API.
    You are just making things up now. Caucho implemented some low level socket calls (using jni) that targeted their supported platforms better than the
    standard Java implementation, they did not implement a bunch of "non-essential IO calls".
    Standard Java can't do this....as the api would not be consistent.

    Anyhow, this is truly a waste of time.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •