VincentMassol | 2009/05/05 20:03
Niels, no there's no plan but we can now support any language using macros so feel free to provide a clojure macro if you're interested. Shouldn't be too hard to do, especially if there's a JSR-223 implementation (in which case simply dropping the jar in WEB-INF/lib should be enough - you'd then use it using the script macro).I hope someone is inspired to try this out. I think it could be a surprisingly easy way to do web-programming in Lisp, by leveraging a flexible platform like Xwiki.
I mostly agree with the above, just to extend it a bit: PHP is an
interpreter which means a new process is fired up on every request.
Java is abysmally slow if you try to use it in the same way since you
have to instantiate the whole VM everytime (besides the fact that you
have to serialize all state incl. caches to disk to survive a
request). What you need is a resident JVM process to answer your
requests. If you're using Apache in front to handle the requests you
can use more than one strategy, there should be enough tutorials
around to help you with that (start at
http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html to
get an idea).
This is quite a bit different from PHP, but also Rails etc. usually
have a resident process that you're talking to (FastCGI etc.). It
makes some other things in the end a lot easier. If you try to just
have something small up and running without a lot of hassle, try to
make it on Google App Engine. There you have a (restricted) managed
JVM and you just have to supply a servlet (standard API for writing
HTTP handler in Java land). Otherwise, there are a few companies that
have JVM hosting in Virtual machines on offer (e.g. Kattare:
http://www.kattare.com/).
Rant: I also find it annoying and unnecessarily complex to have JVM
based webapplications running online. Not many managed JVM
environments are available in comparison to PHP, Python, Perl, Ruby,
et al. The reason is that until now it's still not really possible to
reliably partition applications (code, resources consumption, kill of
only one applicaton) within a single JVM, that means, JVM don't really
mix with shared hosting plans (the solutions are so called MVMs with
true separation of resources inside a JVM). Until these MVMs arrive,
you really need are Hypervisor based solutions, Xen etc. to constrain
ressource usage. I hope that someone is going to tackle that problem
soon, there's a pile of cash waiting to be made if you can pull it off
for the masses.
Hope that helps.
Cheers,
Daniel
I have read trough the page that you linked to and the issues listed
ain't any different from the issues associated with developing PHP
applications.
---- I mostly agree with the above, just to extend it a bit: PHP is an
---- interpreter which means a new process is fired up on every request.
---- Java is abysmally slow if you try to use it in the same way since you
---- have to instantiate the whole VM everytime (besides the fact that you
---- have to serialize all state incl. caches to disk to survive a
---- request).
Why is the jvm so slow at starting up? Both PHP and Python are byte code
compiled and run in a VM, but the runtime environments for both of these
languages start up almost instantly.
---- Rant: I also find it annoying and unnecessarily complex to have JVM
---- based webapplications running online. Not many managed JVM
---- environments are available in comparison to PHP, Python, Perl, Ruby,
---- et al. The reason is that until now it's still not really possible to
---- reliably partition applications (code, resources consumption, kill of
---- only one applicaton) within a single JVM, that means, JVM don't really
---- mix with shared hosting plans (the solutions are so called MVMs with
---- true separation of resources inside a JVM). Until these MVMs arrive,
---- you really need are Hypervisor based solutions, Xen etc. to constrain
---- ressource usage. I hope that someone is going to tackle that problem
---- soon, there's a pile of cash waiting to be made if you can pull it off
---- for the masses.
This is exactly why I do not want the complexity of proxying various servers
behind apache, I am running my own development server, which is set up to
mimic the average shared hosting environment, PHP and CGI applications run
as separate users to prevent the compromise of one application form effecting
anything else.
Running other servers doesn't fit with this environment very well, and
embedding more modules into apache is something that I am trying to avoid,
as they often provide no way of running code as different users.
---- You could use FastCGI to accomplish this, though you would have to
---- write the interface.
---- http://www.fastcgi.com/
---- FastCGI would remove the long startup times for the JVM, etc.
I will look into fast CGI.
---- One thing I would say, though, is that PHP apps don't "Just Work", you
---- have to have mod_php (in Apache) or
---- some other support in the web server.
I know, however from the viewpoint of the end user, php does just work, just
upload a .php file, and run it. Which is why PHP has bean so successful
compared to other technologies, even though the language is a complete mess.
---- If you want very easy to deploy web apps, I would suggest Compojure:
---- http://github.com/weavejester/compojure/tree/master
---- You can always use a proxy to front a compojure app, which is how a
---- lot of web apps do it.
Compojure requires running a second server and proxying it, which as
described above, I am trying to avoid. Is there any way of developing
a application with Compojure completely without shell access to the server?
Lisp seams like a very good language for developing web applications, mostly
due to its macro system and doorman specific languages. However there seam
to be no practical ways of developing with it.
It is possible to compile your Compojure application to a WAR file
that can be deployed into any standard servlet container. You would
still need a host that supports Tomcat (or similar) but you wouldn't
need shell access.
Your pain is my pain. Writing your web app in PHP, Ruby,
Python etc. means that you have your pick of a very large
number of cheap hosting services. Depending on the service,
you may be able to simply copy over your script source and
have it run almost automatically, or you may need to create
a CGI and/or ask that the interpreter for whatever language
be installed, but still this is very commonly available.
Especially for a low-volume, low-revenue sites these
inexpensive options are very attractive.
Java and therefore Clojure does not play nicely in this
niche as far as I can tell. Even if a service allows ssh
access such that you can install a JVM, Clojure, etc. it's
almost certain you will not be allowed to keep
a long-running process going (which rules out simple Jetty
solutions). A simple CGI, while usually possible in such an
environment, incurs such a heavy CPU and time cost on JVM
startup that it's not a practical solution.
FastCGI is indeed a theoretical option. While not as
widely supported as plain CGI by cheap hosting services,
you'd still have many providers to choose from. There is
even a Java interface. I attempted to use this several
months ago, but failed for reasons I don't remember --
I hope you have more success.
The reason that FastCGI is works when other kinds of
separate-server-processes don't is because the web server
(Apache or lighttpd) can start up and shut down these
processes on demand based on policies controlled by the
server admin.
I even got working a solution where a very small CGI
(written in C) forwards requests to a separate server
process (which could be running Jetty or whatever), but if
no such server is available the little CGI would start it
up. Unfortunately my hosting service still got sore about
the long-running process -- perhaps if the server shut
itself down after a few idle minutes that would keep the
admins happy, but I didn't pursue it.
So as far as I can tell, your best options for hosting
a Clojure web app are still either to get FastCGI working or
pay for a more expensive service: Java servlet container
provider, private virtual machine, co-locate, or on up from
there.
--Chouser
The google app engine looks like an interesting platform, However I
cannot create an account as I don't have a phone.
---- Trying to use CGI sounds like a bad idea. It's always full of
---- security issues
I have read trough the page that you linked to and the issues listed
ain't any different from the issues associated with developing PHP
applications.
Why is the jvm so slow at starting up? Both PHP and Python are byte code
compiled and run in a VM, but the runtime environments for both of these
languages start up almost instantly.
-Xshare:dump can help improve startup performance on some installations. When run as root (or whatever user you have the JVM installed as) it will dump a shared-memory file to disk containing all of the core class data. This file is much faster to load then re-verifying and re-loading all the individual classes, and once in memory it's shared by all JVMs on the system. Note that -Xshare:off, -Xshare:on, -Xshare:auto set whether "Class Data Sharing" is enabled, and it's not available on the -server VM or on 64-bit systems. Mac users: you're already using Apple's version of this feature, upon which Hotspot's version is based.
As Daniel mentioned, Google App Engine can host java. It's very easy, just upload a war with your clj AOT-compiled.
See http://elhumidor.blogspot.com/2009/04/clojure-on-google-appengine.html
If Clojure has a JSR-223 implementation, you could easily leverage all the same Xwiki API's you normally access from Velocity or Groovy:
Niels, no there's no plan but we can now support any language using macros so feel free to provide a clojure macro if you're interested. Shouldn't be too hard to do, especially if there's a JSR-223 implementation (in which case simply dropping the jar in WEB-INF/lib should be enough - you'd then use it using the script macro).VincentMassol | 2009/05/05 20:03