Mod Perl or Servlets?
A nameless submittor dropped this in my inbox: "I've heard people comment that Java Servlets are better than Perl CGI scripts. I've also heard the counter comment that while Java Servlets beat Perl, Mod Perl beats Servlets. I don't want to start a flame war, but I'm like to see the meat of this debate. Which is the better tool for server side web development? This is an area I'm about to get into and I'd like to see the pros and cons of each." I won't comment, if I did it would show my obvious Perl bias.
Santa was very good to me and brought me the java servlets book, as well as the mod_perl book. A recent project forced me to look for a way to implement pooled database connections. The servlet implementation seems quite nice, and I intend to invest some time with java. But as I wrote it in perl, I would be interested in how to do it under mod_perl. Is it as simple as never destroying the dbh? I found very little information, much less code snippets, but did discover that mod_perl makes you write clean CGI!
I personally have only used perl (and mod_perl) and I can tell you that mod_perl is *fast*. And it does encourage you to write cleaner perl code. But, as with most things perl, you can also twist it and kludge around mod_perl's requirements/limitations with even uglier code :)
Given that performance was similar, I would probably choose to use Java servlets, if only because Java is a cleaner language than perl (IMHO).
This has been hashed b4 countless times.
To recap :
[a] Perl is a quick hack of a shell scripting language that has grown exponentially by adding crap to it.
[b] Java is a properly structured OO language that requires massive CPU power to do anything useful, hotspot VM engine or no hotspot engine.
In short :
[c] If your project is really small (think search engine/ website candy etc) and runs on shit hardware choose perl.
[d] If you have a large maintainable project to write (think large banking app) choose Java..and your hardware better be decent or else.
I'm quite surprised that some guys only talks about personal preferences & this sort of stuff. Ok, it's important but to me, the project itself should be more important than any other thing. The questions should be "what sort of data do I have to access/modify/process", "where will the stuff will run", "what is the most important thing to the project : speed/maintenance/etc..."
/Personal hint
I don't preach a ISO900*. analysis each time you do a cgi but if you plan to create a medium size ou bigger site, don't hesitate !! Ask the correct questions, sketch your data & your methods to process it, find the minimal requirements of your project ( speed/size/etc... ) and then choose the technologies/OS/languages.
Personal hint
If it's only to play with cgi, then choose Perl, it's so fun & easy especially with the right modules as ePerl or Text::Templates. And perl can help you anytime ( it's very powerfull and very extendable --- there's already a ton of modules ( at the CPAN ) for all your needs !!
Yet Another Anonymous Coward
Have a peek at http://www.chamas.com/hello_world.html. This is a comprehensive benchmarking site for all types of backkends for webservers and includes mod_perl and jserv/servlets.
According to the site your servlets will be running about 10 times slower than perl.
Firstly, who is going to be maintaining the code? If you're going to be the only programmer working on the project, the decision is easier, but if there are several people involved, you need to take overall effort into consideration.
:)
Secondly, which language is more familiar? To programmers who have worked primarily in strongly-typed languages (especially C/C++), trying to learn Perl is quite often a maddening process, whereas Java requires a much smaller mental shift. A Perl programmer trying to learn Java or C++, on the other hand, often finds it restrictive or unforgiving.
Thridly, which do you prefer? Personal preference for one language or another can change the way you feel about a project, and how much time you're going to devote to making things 'just right' even if it's already 'good enough'.
In fact, the only reason I've found to prefer one over the other on a purely funcional basis is that (IMHO, anyway) Java code is easier to share between programmers, because it tend to develop in better-defined blocks (let's hear it for OOP!).
And in the end, of course, trust your own experience above the opinions of others
Unless, of course, scissors can't cut rock...
First of all, I recommend the O'Reilly Servlet book.
Second, pick your servlet engine carefully. I saw the reference to some hello world tests in a previous post. The servlet tests look like they were run on Apache's servlet engine. Too bad its dog slow (last I read about it that is ~6 months ago--I'm sure that they will catch up). We used Servlet Exec, and it works well. Also, be careful to not to let yourself be misled by micro benchmarks.
Third, consider your needs. In our servlets we were able to take advantage of object caching, sophisticated object to relational mapping tools and CORBA connectivity to back end services. There's a very nice java servlet framework called Webmacro, which is free (as in software not beer). I also see potential in JSP's, although I have no direct experience with them.
I also saw some comments about Java being slow. Yes, that's true. However I would venture to guess that its fast enough for all but the most demanding applications. Comments from another post said that you'll require serious hardware to do servlets. No doubt. However, computers are getting faster and so are Java VM's. I'm sure that Java will be fast enough for those demanding applications in the next couple of years, and my opinion is that if you want to be ready to slide down that slippery slope (like Chevy Chase in Christmas vacation) when its slick enough, then there's no better time to start greasing up with the right lubricant and getting the experience than now.
In short, we've had good luck with servlets. Developement has been quick (most of the development speed gained in Java is cut out from debugging when compared to c/c++ I can't compare it to perl though). The web sites have performed well. Personally, I believe that developer time is more valuable than CPU time, so I would recommend (IMHO) spending the extra dollars on hardware, and saving on the developement and maintenence.
Good Luck
I've finally found the off by one erro
...at my place of work, and settled on mod_perl. Part of the decision was based on performance: our site will have a lot of other junk slowing things down, so the scripting language has to be as fast as is practical. The main reason, though, was the documentation available. In a few weeks of scouring the net and the bookstores for information about doing the sorts of things that we'll be doing, I was much happier with the quality and quantity available for mod_perl.
ISP's, Programming languages, Operating systems, CPU Architecture, Pretty coloured workstations... can you see a pattern developing here?
Everyone has their own personal favorites be they better or worse, faster or slower, and most people will defend to the death their personal choice even in the face of logical debate. I wouldn't be so naive to state for one moment that PERL is the definitive and only choice. It happens to be my personal favorite for many reasons. I'm always happy to learn new code, new tricks and new languages to get results but always consider the options within my current capabilities first.
One word I would prefer not to involve in this debate is the word "better". I wouldn't say that PERL is necessarily "better" than Java Servlets, nor vice-versa. What I would say is that I am comfortable with PERL, I can bodge a script together quickly and see results with the minimum of debugging time. Determining what language is "better" in a particular scenario depends very much on the programmer as much as on the language options themselves.
I'm quite sure that I've used PERL where Java Servlets may be mare efficient, possibly quicker and perhaps even more versatile. What is important to me is that I can achieve the end result I require, and I can hack and hack at the script to my hearts content should my end result change at any time. There may come a time when I decide that investing the time to learn Java to a high level is a valid use of my time, but for now I'll stick with what I know for as long as it works.
My advice would be not to start a holy war with both sides adamant their code is better. If it works and you're comfortable with it, use it. If you're struggling and perhaps starting out and wondering which path to choose, then listen to both sides and then decide. Most importantly, a script that works reliably is infinitely better than a flashy, high speed application riddled with bugs.
Incidentally, although you can see my obvious bias towards PERL, much of the work for my customers does actually contain Java Servlets - just that I don't personally write them. I have a team of 4, and don't particularly care how we achieve results as long as I have the backup and knowledge in my team to ensure our products work reliably and we can confidentally put our names to them.
I never forget a face Madam, but in your case I'l make an exception - Groucho Marx
Philosopher (n) - a wise person who is calm and rational; someone who lives a life of reason with equanimity
I used to use mod_perl on my machine but I found
php (http://www.php.net) to be much easier and
very nice built in database support makes it easy
to link to a database. Coding php is very similar
to asp but with more power, yet is not as complex
as perl. I still use perl for system scripts (cron jobs)
and stuff but php is my web backend.
I have been doing PERL CGI for a few years and just recently decided to look into java. After playing with java servlets for a few weeks, I was blown away. The database pooling that you can do makes the servlet blazing fast. I was so amazed with the speed and java libraries that I am doing a new large project in java. It is going very well, and it is extremely fast. I wish that I had explored java servlets earlier.
Some of these problems could have been fixed with a redesign of the perl code (such as using a database to manage all the data we have).
The replacement app uses database access, XML, XSL, business rules, etc. It also has to support thousands of sites.
I've chosen to implement the replacement with Java servlets. Specifically I'm using Apache JServ, with MySQL as the database (soon to be Oracle). JServ11b3 performance is now on a par with the other servlet engines (they did some work with thread re-use). But more critically it is hardware scalable (i.e. you can cluster a bunch of machines together to increase your throughput). The Tomcat project (www.jakarta.apache.org) will also be an implementation to look out for.
I've posted some material on servlet and Perl performance on my web site at Working Java. This includes a comparison of Perl to Servlet performance in a real life application.
There are also a set of 'pure' helloworld benchmarks for Perl, Servlets, PHP, etc on lots of different hardware at ..... (the URL escapes me, anyone?)
As the other posters have pointed out, your choice will depend on your requirements.
For a simpler problem I may have gone with a simpler solution: Perl or PHP. (Actually I probably wouldn't becuase I'm comfortable/productive in the Java environment, but someone who was into Perl may do).
I can vouch for a trouble-free time developing with servlets, lots of reference material, good implemetations of the spec to choose from, acceptable performance (and scalable across hardware), a productive environment, decent maintenance prospects (how does the joke go? Java is WORA - write once run anywhere. Perl is WO - write once and never understand again.
I see the opposite in those same benchmarks. I'm not promoting Java. I'm just looking at the table you refer to. Look at the hits per second *per MHz*, not the simple hits/s column. Java is running on a machine with only half the processor speed, and when you compensate for that, Java servlets outperform mod_perl (again, in *these* benchmarks, for what they're worth.)
"Those who have never entered upon scientific pursuits know not a tithe of the poetry by which they are surrounded."
I don't think anybody's mentionioned Python yet. Without extensive knowledge of the other alternatives, all I can say is that with a little care PyApache works for me. It's much like usual CGI in use, with some tricks like a dictionary for each Apache child process.
There's a different implementation of the same idea (embedding the python interpreter) called httdapy, I think, that's a little deeper into Apache interface-wise; I seem to recall it would work with Zope, too. That project is a "web application server" done in Python, if you haven't heard of it yet.
Jave Servlets sound promising. Perl is proven. PHP receives raves. Can anyone shed light on which of these has the best security? Poorly written (or well exploited) Perl cgi is all over the place. How do servlets and PHP stand up with regards to security?
you haven't rehashed anything but your own bias towards tired language designs.
For quick and dirty sites, and if you already love Perl, then mod_perl is fine (personally I think PHP is easier). For sites that have a very limited scope, and for those which code maintanence does not matter, go ahead and pick a scripting language you are comfortable with. The whole point of those scripting languages is to enable rapid development. mod_perl allows you to take the rapid development to a web server.
If your application is large, or needs to scale, you will need to engineer the site, not just hack/script it. Today's extensive interactive sites need to cope with thousands of users and millions of hits. True, mod_perl will handle it as far as execution is conserned, but a n-tier, engineered application will create a better solution.
For those n-tier type applications, servlets are only part of the solution.
In a true n-tier web application, you will see many partitions emerge. Some of those partitions are
You will also see that servlets (and Java Server Pages) only fit in the presentation layer. To create a scalable application, you will want to abstract the business logic from the presentation. There are many solutions for business logic, and the Java universe promotes EJB.
The point is that to correctly choose a development environment, look at the scope of the application. If it's large, it must be correctly engineered, and a true OO language such as Java has a lot of advantages going for it. Those advantages include architectures such as servlets, JSP, fast server side VMs, rich class heirarchy, EJB, and support for latest XML/XSL technologies.
Please don't bullshit us with your biased benchmarks of servlets vs Perl CGI. This "Ask Slashdot" is talking about mod_perl vs servlets.
Matt. Want XML + Apache + Stylesheets? Get AxKit.
I work purely with mod_perl, so I won't disservice you with biased rumblings of how I think mod_perl is better - follow the advice of another poster here: Pick whichever tool your company/team has more experience with, and feels most comfortable working with. That's the only decision that should matter. Good perl people are expensive (as are good Java people - but the perl ones are harder to find/employ) though.
My tip is simply if you go the mod_perl route, please don't pick the no-brainer Apache::Registry route (this is a CGI-emulation mode). It will just in the long term cause you more troubles than it's worth. If you're working on an application complex enough to require choosing between either mod_perl or servlets then it's large enough to sit down and design it well. First design it without even thinking about the language: Think objects. Then work that into mod_perl. And use the mod_perl API to the full - there are some very cool things in there, like the $r->notes and $r->pnotes methods.
Also, mod_perl is far more than just a way to develop applications. You can do anything you can imagine to the actual Apache server with mod_perl - which makes it an indispensible tool for sysadmins. Witness Randall Schwartz's recent web techniques column on stopping naughty IE5 offline downloaders from sucking all available bandwidth, all done in mod_perl. (may not be available on stonehenge.com yet - try the mod_perl mailing list archives).
Finally, buy some books:
"Writing Apache Modules in Perl and C" by Doug MacEachern and Lincoln Stein. Excellent guide to everything mod_perl.
"Object Oriented Perl" by Damian Conway. Superb guide to doing things right the OO way in perl.
Matt. Want XML + Apache + Stylesheets? Get AxKit.
Don't forget that Perl provides taint mode, which can help considerably (if used correctly).
Which is the better tool for server side web development?
Maybe there is more to choosing a web development environment than mod_perl vs perl?
(Expecting to get at least the 2 points for this post that the above flame got)
I cannot agree with the Apache::Registry comment more. That way lies pure madness. If you don't know what a closure is or do not understand the intracies of perl's scoping rules then do not use Apache::Registry for more than your simplest application. Weird things happen. Your variables will take on values that mystify you. You will post lame questions to the modperl list about it.
mod_perl has so much more to offer than just Apache::Registry. Do not try to maintain CGI compatibility. Just bite the bullet and start writing mod_perl-specific scripts.
I thought that Apache::Registry was the "good" way to use mod_perl and Apache::Perlrun was the "bad" way to run "dirty" CGI scripts. What am I missing? What do you use instead of Apache::Registry?
The first book you name seems to imply that you have to use CGI.pm to do things like take apart POST requests, and therefore you couldn't avoid ::Registry altogether. There's a ::RegistryLite (or somesuch) that does the same with slightly less emphasis on strict CGI compatibility, and there's a module designed to do away with the need for ::Registry but that hasn't been released to CPAN yet because it's barely ready.
So what am I missing?
--
Xenu loves you!
Taking apart requests is really really simple. You can either do it yourself (rip the code out of CGI.pm if you want to - it's only about 40 lines if you ignore the extraneous crap), or use the aprequest library and Apache::Request, which is on CPAN in DOUGM's directory (called libapreq IIRC). Read the book. It's all there.
Matt. Want XML + Apache + Stylesheets? Get AxKit.
Read the context though. The whole question is about mod_perl or servlets. In that context, "which" becomes "which (mod_perl or servlets)". So please don't give us biased benchmarks. If you have benchmarks to give comparing mod_perl to servlets (and not using Apache::Registry), then I'd love to see them.
Matt. Want XML + Apache + Stylesheets? Get AxKit.
I just completed a project using Servlets. We were able to complete the project on time and close to on budget (we'd have been below budget except for a last minute scope change). This was an upgrade away from a system written in perl (not mod_perl though). The customer's complaint was that the implementors of the previous system hadn't done a good job in documenting their code and as a result, the in-house maintainers couldn't follow the code and that led to large amounts of rewrite. Our system was half the number of lines of code and was twice the speed. But a lot of that optimization could be attributed to a very good analyst who gave us solid specs to code by. It's been my experience (and I've been at this a while now) that perl code is useful for smaller or single-shot systems. If the code has to be maintained by anyone else (or a different team) be kind to them and use Servlets.
James
Use the straight apache API. Or use something like HTML::Mason, which is implemented on top of the apache API.
Yeah, yeah, yeah...
Of course everyone here brings their personal baggage with them to these discussions. The point, however, is not to determine which is best. It is to get some insight into the communities group experience. One person saying PHP is the best is meaningless. One person saying we tried PHP and Servlets and mod_perl and choose X. The reasons we found are... is extremely helpful. We can ask ourselves does there situation apply to us, is this helpful. It's kinda like life that way.
If we were all to bring flowers to this discussion and reply "Dude, it's ok. Use whatever you prefer. It's all good.", there would be little point in even stopping by.
First let me say I am a unix programmer, currently doing full-time web development for a startup company.
I love perl, I love C, and I develop in vi. Let me recount my experiences here at work with several of these languages.
I developed a custom Java server-client solution for updateing a web page on the fly. The java applet works fine except for the fact that it won't work with the mac JVM, and I have not had time to research fully why. The java server is running on a Solaris machine, it falls over (crashes hard) every day, now that the site is getting a larger number of hits. I will be porting this server to C and adding alot of features to it. As far as server based applications Java is CRAP . As my boss put it "you could throw that thing on a 128 proccessor symmetric server and it would instantly consume ALL of the processor cycles." This is based purely on experience and several java applications run on the command line.
As for Perl/CGI, I developed a web-based email system from scratch, which works beautifully. I used barely any modules (a personal preference) and have it doing "almost" everything that say hotmail does. It works wonderfully, even in large scale, although as a CGI it is slower than I would like.
I am in the middle of developing a C-Apache-API web-based web page editor. This is FAST !!! The development equally SUCKS !!! The reason I am sticking with it is we hope to sell this as a commercial product to other ISP's and we do not want the source code available. The email system will eventually be ported as well so we can sell it.
Being overworked as I am I am also doing a large amount of development in php3/mysql. I love php3. At first I did not like it compared to Perl/CGI, but then I started to work with it. The clincher was I could write a php3 and throw it at the webdevelopers and they could just throw the graphics in! no escapes like in a perl script! Big benefit for me! I can do design, but not like they can, makes everyone concerned much happier.
Bottom line:
Java is a good idea but the implementation sucks. It is too slow and kludgy.
The most hardcore and coolest language is straight assembly or binary, but development time is a key issue in the Real world. Given that: C beats Assembly, Perl beats C, and php3 beats Perl/cgi. Java as I said sucks on the server end and shouldn't be used.
If you have valid arguments, since I am always trying to be more efficient at work, email me at badbrain@fastband.com.
Recently, I've investigated using Java, specifically Java Server Pages and Java Servlets, to develop web applications. I found some important benefits to using Java rather than Perl. They are as follows...
Pros:
1 - Java is object oriented, Perl is not (although this is debatable). From a developer's view, the lack of OO features in Perl made the development cumbersome and less than elegant. By using OO, the code and application should be more versatile. I also think the OO features make Java much easier to maintain than Perl.
2 - By mixing JSP and Servlets one can use the Model-View-Controller pattern. (As far as I know there is no way to do this with Perl or PHP.) This is a great way to develop web applications because it allows you to separate the presentation of your data with the logic that processes your data. If you look at some of the perl pages, they are a huge pain to read because of all the HTML mixed with the code. This means that a graphic artist could develop the "look" of the web page, and a software engineer could add a few lines of code to insert the data rather than doing all the programming and presentation in the same perl page. This will allow for concurrent development of the presentation and the logic.
3 - Maybe the biggest benefit is that JSP and Servlets are platform independent. This is a quote from one JSP/Servlet developer: "All of these packages are Open Source and Pure Java and should run in any JSDK 2.0 or higher servlet engine and on any platform that the engine supports. Without *any* code changes. How cool is that?
Cons:
1 - The Apache JServ engine seems to be pretty fast, but a good JSP engine costs $$. The performance issues can be can be overcome with a native compiler.
Okay, I'll respond directly to this since you :-)
...
can't play nicely with others...
I'm in the process of replacing a bunch of mod_perl scripts for a large internet game
company. The problem the company had was that
the mod_perl stuff was eating up all memory
to the point where it was regularly crashing
their machine - this, just to handle their
daily newsletter and other subscription services.
In my opnion, the scripts used to handle this
basic service were hacked and not developed
properly at all - I had to search down mutlitple
scripts and lay out exactly what call what
It was a mess and to top it off, no documentation.
Also, the scripts were writing to a dbm file to
store things that had grown to over 66Megs in
size - incredible when I found that most books
recommended dbm for only small database stuff...
Anyhoo, I've replace this with jdbc talking to
oracle to maintain the lists and registration
info - and with a servlet, this is a one time hit
to open and keep the database connection - huge
saving compared to having to thwack IO everytime
with the dbm implementation and mod_perl. Also,
my java servlet doesn't grow - it's been at a stable
size... - compared to the mod_perl parts that
were growing to 20Megs each (with 7 - 10 of
these running at a time)... not good on a
machine that only has 256M... Finally, I
get portability - the code easily transfers to
other platforms as we will eventually upgrade
to more powerful machines...
Anyway, just my 0.02 - yer mileage may vary...
Oh, we're running Sparc-intel with Solaris 7,
Apache and jserv with mod_perl also...
peace. JOe...