Slashdot Mirror


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.

5 of 49 comments (clear)

  1. Ease-of-use by DarkRyder · · Score: 3

    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...
  2. Servlet Experience by billr · · Score: 3

    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
  3. (ker-thump) Another log for the fire by h2odragon · · Score: 4

    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.

  4. Two Different Tools For Two Different Uses by marvinx · · Score: 5
    Yes, you can certainly build interactive, dynamic web sites with both servlets and mod_perl. But to correctly build the site, you have to look at the scope of the site.


    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

    • client
    • presentation
    • business logic
    • data


    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.

  5. mod_perl tip by Matts · · Score: 5

    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.