5

This has been bugging me for awhile now.

In a deployed PHP web application one can upload a changed php script and have the updated file picked up by the web server without having to restart.

The problem? Ruby, Groovy, & Python, etc. are all "better" than PHP in terms of language expressiveness, concision, power, ...your-reason-here.

Currently, I am really enjoying Groovy (via Grails), but the reality is that the JVM does not do well (at all) with production dynamic reloading of application code. Basically, Permgen out of memory errors are a virtual guarantee, and that means application crash at anytime -- not good.

Ruby frameworks seem to have this solved somewhat from what I have read: Passenger has an option to dynamically reload changed files in polled directories on the next request (thus preventing connected users from being disconnected, session lost, etc.).

Standalone Python I am not sure about at all; it may, like PHP allow dynamic reloading of python scripts without web server restart.

As far as our web work is concerned, invariably clients wind up wanting to make changes to a deployed application regardless of how detailed and well planned the spec was. Telling the client, "sure, we'll implement that [simple] change at 4AM tomorrow [so as to not wreak havoc with connected users]", won't go over too well.

As of 2011 where are we at in terms of dynamic reloading and scripting languages? Are we forever doomed, relegated to the convenience of PHP, or the joys of non-PHP and being forced to restart a deployed application?

BTW, I am not at all a fan of JSPs, GSPs, and Ruby, Python templating equivalents, despite their reloadability. This is a cake & eat it too thread, where we can make a change to any aspect of the application and not have to restart.

virtualeyes
  • 11,147
  • 6
  • 56
  • 91

2 Answers2

4

You haven't specified a web server. If you're using Apache, mod_wsgi is your best bet for running Python web apps, and it has a reloading mechanism that doesn't require a server restart.

ʇsәɹoɈ
  • 22,757
  • 7
  • 55
  • 61
  • Thanks Forest, I was not sure about standalone Python. I assume with Django, Pylons, Turbo Gears, etc. one will need to restart (e.g. when making a change to persistence layer/model). Python drew me initially, but the explicit self method param is tough, and lambda/closure functionality is not yet at Ruby or Groovy levels. Saying that, Python does seem to win the standalone reloading battle without the performance penalties that Ruby & Groovy suffer from. – virtualeyes Feb 16 '11 at 17:30
  • I'm not sure what you mean by standalone Python. All the frameworks you mentioned work with WSGI (Python's standard interface for web frameworks to connect with web servers), which means they will work with Apache, mod_wsgi and its reloading mechanism. I don't consider that standalone. (To me, standalone means just Python and its standard library.) If you're using the mini-servers built-in to those frameworks, I guess that's closer to standalone, but you're not likely to get very good performance from them; those are mainly good for development & debugging work. – ʇsәɹoɈ Feb 16 '11 at 20:25
  • Also, you might try getting to know Python a bit better before writing it off. Lambda forms have been more or less deprecated for quite a while; you can do a lot more with generators and locally-defined functions. Also, explicit self might seem awkward at first, but with it comes power (and you can always name it something shorter like "s"). – ʇsәɹoɈ Feb 16 '11 at 20:35
  • By standalone I meant Python plus some web container, like WSGI apache module. Django, Pylons, etc. will likely have same issues with reloading (e.g. persistence layer/model, which may be unavoidable). As for Python as a language, sure, one can define self method param as anything (s, this, foo, etc.), but not being a pythonista, just having to define it at all is the issue. Does python have built-in closures like each, collect, inject, etc. a la Ruby? Also, how does Python achieve Meta Object Programming (MOP), like adding properties & methods to classes at runtime, mixins, etc? – virtualeyes Feb 16 '11 at 22:49
  • Ah, so much to know. :) I'm not planning to write a python tutorial on stackoverflow, but I wish you luck and fun in with your drive to learn multiple programming languages. – ʇsәɹoɈ Feb 16 '11 at 23:17
  • You sly dog, keeping the tricks of the trade in-house ;--) You've peaked my interest again in Python, however, did not think Python did MOP – virtualeyes Feb 17 '11 at 02:29
4

I think you're making a bigger deal out of this than it really is.

Any application for which it is that important that it never be down for 1/2 a minute (which is all it takes to reboot a server to pick up a file change) really needs to have multiple application server instances in order to handle potential failures of individual instances. Once you have multiple application servers to handle failures, you can also safely restart individual instances for maintenance without causing a problem.

Steve Jorgensen
  • 11,725
  • 1
  • 33
  • 43
  • 1
    Steve, thanks, but I disagree; it's not only 1/2 minute downtime, but also lost session state (logged in users logged out), botched shop cart transaction, and other, imo, very important events regardless of enterprise or mom & pop website. If you have multiple servers at your disposal behind an F5 load balancer, more power to you; I certainly do not... – virtualeyes Feb 16 '11 at 17:23
  • steve, I did upvote you, btw, for the magic workaround. I actually have a client who runs several apache servers behind an F5 load balancer (expensive appliance!). Your solution would indeed solve all of the problems in my reply above (with exception of actually having to restart each instance in order to see code change implemented) – virtualeyes Feb 16 '11 at 17:33
  • Web applications should generally not be maintaining state in memory such that session state would be lost. There is no such issue with a typical Rails app, for instance. Also, it is not necessary to have a heavy-weight load balancer or multiple physical systems just to get fail-over across multiple application server instances. For Rails (for instance) we have Mongerel Clusters: http://wiki.rubyonrails.org/deployment/apache-mongrel#mongrel_and_mongrel_cluster. – Steve Jorgensen Feb 16 '11 at 17:38