How much slower is serving static content from Tomcat? - apache

So, I have a webapp with a fair amount of JSPs, servlets, alot of which are using IceFaces. Obviously, most of this will have to stay in Tomcat.
However, I've been told that static content (HTML, Images, etc.) is slower on Tomcat than a pure webserver like Apache. My understanding is that when you're using Tomcat as a stand-alone webserver, it's using a version of Apache in the first place. I may be mistaken on this, of course.
But what is the penalty for serving static images or files from Tomcat? Is it worth breaking out into its own webserver for a low volume site?

See the Tomcat Connector FAQ for some information. For modern versions of Tomcat, the performance difference is much smaller than it used to be. For a low volume site, there is no reason that you cannot supply all content with Tomcat.

I agree except in two circumstances
Tomcat's SSL using JSSE is noticeably slower. There are native versions that can be plugged in, but that tends to be more painful. In general the SSL is a bit less straightforward than the well-understand Apache Httpd server
Fronting with an HTTpd server gives more flexibility re virtual web hosts etc. Tomcat is not as flexible in this regard. Unsurprisingly it lacks all the options in Apache :). An obvious nice one is built in compression of static files is very easy to add in Apache. It's not hard in tomcat extra, but it's more work.
You are mistaken. Apache Httpd Server is a totally different beast and has no code shared with Tomcat.
If neither is an issue, than yeah use tomcat by itself

Related

Server configuration for high traffic website

I'm managing a hosting server and one of my customers will launch a high traffic PHP website. It's a penny auction website and we expect between 25k and 30k visitors per day.
Can you tell me please what should I change in my server configuration (PHP and Apache) to avoid problems? I'm afraid that the server crash with a large number of visitors.
Thank you
Using a lighter web server like nginx as a reverse proxy and a static content server should keep the Apache memory and CPU usage to a minimum which will be a problem on larger sites.
APC as an opcode cache will also be useful in a large site because compiling the PHP scripts to opcode is expensive.
Which Apache forking model are you using for the server? Event and Worker MPM's will probably work better for larger sites with higher concurrent connections.
How is PHP setup within Apache, i.e. FastCGI/CGI/DSO/SuPHP/FPM? SuPHP will be slowest while FastCGI, FPM and DSO will give you much better performance and allow you to use opcode caches.
If you don't need SSL support on the site a free service like https://www.cloudflare.com/ will also lessen the load on your servers.
You could put an opcode cache into use, eAccelerator is a good one for this purpose.
You may also want to consider creating Apache vHosts for static content like images/CSS/javascript to be served from. If these can be put into a CDN, then even better.
There are other tools available for benchmarking, including the Apache benchmarking tool "ab". You can use this to stress-test your site.
There are several areas in which tuning can take place, not just PHP.

Should there always be an Apache in front of a Tomcat (and why)? [duplicate]

I'm trying to set up Apache in front of Tomcat. What do I have Apache serve? I know Apache works better for static pages and images. I currently deploy a war file in Tomcat that contains static pages, images, and Flash files. Should I put those all on the Apache server? How to I reference those pages/images from the Tomcat application?
I would like to use Apache to decrease the war file size and hopefully serve images faster. Is there a good guide for setting up Apache and Tomcat and what to place where?
Do you have a problem with performance/load on your Tomcat server? Do it if you need to(performance, security, etc), but don't make things more complicated if you don't need to.
It used to be the standard to front Tomcat with an Apache server, but recent versions of Tomcat can(and often times are) used as both the HTTP Server and the Servlet Container.
Take a look at the Tomcat Connector FAQ for information on the subject.
Why should I integrate Apache with
Tomcat? (or not)
There are many reasons to integrate
Tomcat with Apache. And there are
reasons why it should not be done too.
Needless to say, everyone will
disagree with the opinions here. With
the performance of Tomcat 5 and 6,
performance reasons become harder to
justify.
...
Speed. Apache is faster at serving
static content than Tomcat. But unless
you have a high traffic site, this
point is useless. But in some
scenarios, tomcat can be faster than
Apache httpd. So benchmark YOUR site.
Tomcat can perform at httpd speeds
when using the proper connector (APR
with sendFile enabled). Speed should
not be considered a factor when
choosing between Apache httpd and
Tomcat

nginx/apache/php vs nginx/php

I currently have one server with nginx that reverse_proxy to apache (same server) for processing php requests. I'm wondering if I drop apache so I'd run nginx/fastcgi to php if I'd see any sort of performance increases. I'm assuming I would since Apache's pretty bloated up, but at the same time I'm not sure how reliable fastcgi/php is especially in high traffic situations.
My sites gets around 200,000 unique visitors a month, with around 6,000,000 page crawls from the search engines monthly. This number is steadily increasing so I'm looking at perfomrance options.
My site is very optimized code wise and there isn't any caching (don't want that either), each page has a max of 2 sql queries without any joins on other tables, indexes are perfect as well.
In a year or so I'll be rewriting everything to use ClearSilver for the templates, and then probably use python or else c++ for extreme performance.
I suppose I'm more or less looking for any advice from anyone who is familiar with nginx/fastcgi and if willing to provide some benchmarks. My sites are one server with 1 quad core xeon, 8gb ram, 150gb velociraptor drive.
nginx will definitely work faster than Apache. I can't tell about fastcgi since I never used it with nginx but this solution seems to make more sense on several servers (one for static contents and one for fastcgi/PHP).
If you are really targeting performance -and even consider C/C++- then you should give a try to G-WAN, an all-in-one server which provides (very fast) C scripts.
Not only G-WAN has a ridiculously small memory footprint (120 KB) but it scales like nothing else. There's work ahead of you if you migrate from PHP, but you can start with the performance-critical tasks and migrate progressively.
We have made the jump and cannot consider to go back to Apache!
Here is a chart showing the respective performances of nginx, apache and g-wan:
g-wan.com/imgs/gwan-lighttpd-nginx-cherokee.png
apache does not seem to lead the pack (and that's a -Quad XEON # 3GHz).
Here is an independent benchmark for g-wan vs nginx, varnish and others http://nbonvin.wordpress.com/2011/03/14/apache-vs-nginx-vs-varnish-vs-gwan/
g-wan handles much more requests per second with much less CPU time.
NGINX is the best choice as a webserver now a days.
The main difference between Apache and NGINX lies in their design
architecture. Apache uses a process-driven approach and creates a
new thread for each request. Whereas NGINX uses an event-driven
architecture to handle multiple requests within one thread.
As far as Static content is concerned, Nginx overpasses Apache.
Both are great at processing Dynamic content.
Apache runs on all operating systems such as UNIX, Linux or BSD and
has full support for Microsoft Windows & NGINX also runs on several
modern Unix-like systems and has support for Windows, but its
performance on Windows is not as stable as that on UNIX platforms.
Apache allows additional configuration on a per-directory basis via
.htaccess files. Where Nginx doesn’t allow additional configuration.
Request Interpretation-Apache pass file System location. Nginx
Passes URI to interpret requests.
Apache have 60 official dynamically loadable modules that can be
turned On/Off.Nginx have 3rd Party core modules (not dynamically
loadable).NGINX provides all of the core features of a web server,
without sacrificing the lightweight and high-performance qualities
that have made it successful.
Apache Supports customization of web server through dynamic modules.
Nginx is not flexible enough to support dynamic modules and loading.
Apache makes sure that all the website that runs on its server are
safe from any harm and hackers. Apache offers configuration tips for
DDoS attack handling, as well as the mod_evasive module for
responding to HTTP DoS, DDoS, or brute force attacks.
When Choose Apache over NGINX?
When needs .htaccess files, you can override system-wide settings on
a per-directory basis.
In a shared hosting environment, Apache works better because of its
.htaccess configuration.
In case of functionality limitations – use Apache
When Choose NGINX over Apache?
Fast Static Content Processing
Great for High Traffic Websites
When Use Both of them -Together
User can use Nginx in front of Apache as a server proxy.

What should Apache serve and what should Tomcat serve?

I'm trying to set up Apache in front of Tomcat. What do I have Apache serve? I know Apache works better for static pages and images. I currently deploy a war file in Tomcat that contains static pages, images, and Flash files. Should I put those all on the Apache server? How to I reference those pages/images from the Tomcat application?
I would like to use Apache to decrease the war file size and hopefully serve images faster. Is there a good guide for setting up Apache and Tomcat and what to place where?
Do you have a problem with performance/load on your Tomcat server? Do it if you need to(performance, security, etc), but don't make things more complicated if you don't need to.
It used to be the standard to front Tomcat with an Apache server, but recent versions of Tomcat can(and often times are) used as both the HTTP Server and the Servlet Container.
Take a look at the Tomcat Connector FAQ for information on the subject.
Why should I integrate Apache with
Tomcat? (or not)
There are many reasons to integrate
Tomcat with Apache. And there are
reasons why it should not be done too.
Needless to say, everyone will
disagree with the opinions here. With
the performance of Tomcat 5 and 6,
performance reasons become harder to
justify.
...
Speed. Apache is faster at serving
static content than Tomcat. But unless
you have a high traffic site, this
point is useless. But in some
scenarios, tomcat can be faster than
Apache httpd. So benchmark YOUR site.
Tomcat can perform at httpd speeds
when using the proper connector (APR
with sendFile enabled). Speed should
not be considered a factor when
choosing between Apache httpd and
Tomcat

Why use Apache over NGINX/Cherokee/Lighttpd?

Apache has been the de facto standard web server for over a decade, but recent years have brought us web servers that consume less RAM and handle many more requests per second using fewer threads and asynchronous i/o. In my opinion, I also find the configuration of these servers to be more straightforward and minimal.
Why do people use Apache when asynchronous servers are so much more lightweight? Is there any clear benefit?
Ubiquity, "good enough", and familiarity.
Apache's .htaccess provides flexible configuration. This allows users on a shared host to customize certain settings of an apache without having to alter the core apache configs.
It is the standard server bundled in typical LAMP setups, although, many services use other web servers for in conjunction (like static files, video streaming, etc.).
Since Apache is popular, it's easy to find a solution to any problems.
Other than that, other solutions would probably be better.
Apache IS asynchronous if you want it to be with the Event MPM. Unlike Nginx and Cherokee, etc., it is not the default.
Apache's made some important moves in 2.4 so it can be more competitive — esp. as it pertains to serving static requests using the Event MPM. Various benchmarks don't speak well of this, but:
It's very difficult to ascertain how much slower Apache is in 2.4 because Apache's out of the 'box' configuration is detrimental to performance and legacy holds it back in some respects. For example, .htaccess requires stat/reading a multitude of files on every request, which may include many rules and regexes. Nginx doesn't have this problem, nor does Cherokee. Litespeed has .htaccess support in Apache's style, but only if you pay for it. Most benchmarks don't turn off features like those.
Most of the benchmarks are also ridiculous in that they're run locally and over a GbE network or similar. A real web server has to cope well with various speeds, including 3G phones. It could be that Apache's performance is better in the real world.
I doubt it.
Nginx is still faster, and I might choose it, but Apache isn't asleep.