views:

185

answers:

6

I am an open source developer, and I need to write a highly-scalable web service. For a variety of reasons (basically poor support for concurrency), I am using Ruby on Rails for my app front-end but not for the back-end (read: http://www.ddj.com/go-parallel/article/showArticle.jhtml?articleID=212903282). My web service will need to call several partner APIs for each request, so it needs to be smart about threading to have high throughput.

What language / stack does the community recommend for writing such a web service? I haven't written Java in a while (and it seems really old school :D). I need to be able to prototype this service quickly.

A: 

To prototype quickly:

  • Python (scripting lauange like Ruby which may help you learn quickly)
  • or JSP since you've learned Java before.
Francis
A: 

It depends on the rest of your requirements.

For example, if you want to use .NET then you may want to use F# for your backend. If you use

Expert F#

the author will show how to use F# in web pages.

If you want to use something like Java then look at Scala as an option.

Or, if you want very scalable, where, if you add new machines you don't have to change any code, then you can look at Erlang.

You can get threading to work with OOP languages but it won't tend to be as efficient, as the test and set way of locking may not be as efficient as desired.

James Black
A: 

There is nothing wrong with spawning Ruby processes for this. As long as you design them to be independent (from each other and from the database), your scalability will be ok. You can get higher performance from the same hardware with other languages and environments, but introducing a new language in an open source project is a big no-no. It will basically reduce the number of available developers too much.

Stephan Eggermont
+2  A: 

A little known but good option is C++. There are a number of frameworks ranging from high level AJAX abstractions (Wt: http://webtoolkit.eu/) to simple CGI libraries (e.g. http://cgi.sourceforge.net/). The performance is very good and development is fast otherwise, but the need for recompiling all the time may obstruct your development. Another issue to consider is the smaller number of readily available webdev libraries and APIs, but I have found everything that I need (e.g. SOCI, LibXML++ and Boost.ASIO).

C# and Java are also high performance options but development in them might be slower than C++, largely depending on what you are used with. On the other hand you get plenty of libraries and support.

While most scripting languages (most notably Python and Ruby) lack proper support for multithreading due to them using global interpreter locks, this is not really a problem for web services. The problem can be worked around by running a separate process for each user. This has somewhat larger memory requirements, but in general it works well and it certainly is safer.

The bigger problem with Python and Ruby is that they execute the code extremely slowly. To make the problem even worse, Rails is a very slow framework, compared to other Ruby libraries. I have successfully created high-load web services with Ruby (using Ramaze web framework). Manual optimization on source code level is required for reaching acceptable performance levels, but for what I worked on this was enough and we could keep using Ruby.

Tronic
+3  A: 

What language / stack does the community recommend for writing such a web service? I haven't written Java in a while (and it seems really old school :D). I need to be able to prototype this service quickly.

Then I would definitely recommend to use Java and the JAX-WS API which, like other Java EE 5 APIs, is annotation-based to ease the development. In other words, you annotate a Java class and voilà, you're done and can deploy it as web service. This is really perfect for prototyping (even if I would switch later to contract-first approach). For an implementation of this API, you can use the reference implementation (JAX-WS RI) which is included in Java 6 (since Java 6u4) and also used in Metro, the web service stack of GlassFish (Metro = JAX-WS RI + WSIT). Another (very good) stack which also implements JAX-WS is Apache CXF.

If you want some numbers about the performances of JAX-WS RI, have a look at this benchmark, it will give you an idea of its capabilities (and/or of the hardware you'll need).

And to get an idea of what this API looks like, have a look at Introducing JAX-WS 2.0 With the Java SE 6 Platform, Part 1 and Introducing JAX-WS 2.0 With the Java SE 6 Platform, Part 2 (the complexity may not be very representative of real life though).

Update: I've mentioned JAX-WS RI, Metro, Apache CXF and I would understand if you tell me that this is confusing. The problem is that if you google for JAX-WS, you'll meet all these terms/acronyms. So I tried to give the minimal informations to clarify what they are. If you need any clarification or more details, just let me know.

Pascal Thivent
I have been very pleased with the annotation approach, which decouples from the actual implementation. We did not go for a JEE5 server, but added the Metro jars to a servlet 2.5 container, but the annotation approach means that it should be very easy to adapt to any JEE5 container.
Thorbjørn Ravn Andersen
Indeed, JAX-WS RI, Metro, Apache CXF, they can all be deployed on a servlet container.
Pascal Thivent
A: 

If you choose to go on the Java path, then I recommend using jax-ws (metro implementation, already included by default in Java 6) for two reasons:

  • It is easy and more intuitive than the alternatives.
  • It is faster, and you mentioned that performance is important. See here a very recent article about performance.
Yoni