views:

409

answers:

8

I need to create a simple Chat system like facebook chat and a twitter-like app. What is the best concurrent program languages in this case ?

Erlang, Haskell, Scala or anything else ?

Thanks ^_^

+2  A: 

This is actually a relatively easy problem to solve that can be done by any language with decent threading support including (eg Java, C# and others). The model is fairly simple:

  1. Each client connects to a Web server with an AJAX request that is configured on the server not to timeout;
  2. If it does timeout for any reason the client is configured to issue another AJAX request;
  3. The server endpoint for that AJSX call does a thread wait operation on some monitor waiting for updates;
  4. When the user sends a chat it is sent to the server and any relevant monitors are signaled;
  5. Any threads listening to that monitor are woken up, retrieve any messages waiting for them and return that as the AJAX result to the client;
  6. The client renders those messages and then issues another AJAX request to listen to for messages.

This is the basic framework but isn't the end of the story. Any scalable chat system will support either internal or external federation (meaning the clients can connect to more than one server) but unless you're Google, Facebook or Twitter you're unlikely to have this problem.

If you do you need some kind of message queue/bus for inter-server communication.

This is something you need a heavy duty multithreaded language like Erlang for but it, Haskell and others are of course capable of doing it.

cletus
Sorry to be a bore, but Erlang isn't a multithreaded programming language. It supports Erlang processes which are not threads.
Gordon Guthrie
@Gordon what I really mean is that Erlang is *concurrency-oriented* rather than talking about threads specifically.
cletus
...but you forgot about the 'thread police'. We're always watching you know... :)
Gordon Guthrie
+6  A: 

Chat system like facebook chat

Facebook chat is written in Erlang, http://www.facebook.com/note.php?note_id=14218138919

and a twitter-like app

What aspect? Message delivery? The web frontend? It's all message routing ultimately. Haskell's been used recently for a couple of real time production trading systems, using heavy multicore concurrency. http://www.starling-software.com/misc/icfp-2009-cjs.pdf

More relevant: what's the scale: how many users do you expect to serve concurrently?

Don Stewart
actually twitter is all DATABASE ultimately, it has very little to do with messaging or routing and everything about how to store and retrieve all the tweets int the database, nothing simple there at that scale
fuzzy lollipop
Except the stuff you see doesn't come out of a database anymore. It's in a different kind of store.
Tom
+1  A: 

I would go for erlang, it's efficiency in comet-enabled apps is largely proven.

Go with a framework such as nitrogen, where you can start comet requests just as easily as Jquery does ajax.

Berzemus
+4  A: 

Erlang is my choice of drug for something like that. But I would also check out Node.js if you feel more comfortable in JavaScript.

Jon Gretar
+1  A: 

F# for future.

  1. Client/Server chat F#
  2. Concurrent Programming - A Primer

Also take a look at Twisted(Python).

TheMachineCharmer
F# for a proprietary solution.
Roberto Aloi
I've seen several benchmarks on twisted, and it seems to scale badly. It isn't capable of utilizing more than one CPU, and I'm not sure what polling backends it supports. We mostly use it for clients, bots and other small services like that, but I guess it could work for you, if you don't expect more than, say a few hundred clients.
Amadiro
+1  A: 

If it's actually going to be a simple application (and not under very high load), then the answer is to use whichever language you already know that has decent threading. Erlang, Scala, Clojure, Haskell, F#, etc., all do a perfectly good job at things like this--but so do Java and C#. You'll be fine if you pick whichever of these you know and/or like.

If you're using this as an excuse to learn a new generally useful language, I'd pick Scala as a nice blend of highly performant (which Erlang is not in general, though it is fantastic with efficient concurrency), highly functional (which Java and C# are not), highly deployable (due to running on the JVM), and reasonably familiar (assuming you know C-ish languages).

If you're using this as an excuse to practice fault-tolerant concurrency, use Erlang. That's what it was designed for and it does it extremely well.

Rex Kerr
+3  A: 

Complete chat application source code using Scala/Lift.

8 minutes and 20 seconds real-time, unedited, webcast writing a chat app from scratch using Scala/Lift.

Daniel
+2  A: 

I'd recommend taking a look at Akka (www.akkasource.org)

It's a Scala Actor framework with ALOT of plumbing for making scalable backend applications.

Out of the box it supports:

Actor Supervision Remote actors Cluster Membership Comet over JAX-RS (Project Atmosphere) HTTP Auth for your services Distributed storage engine support (Cassandra, MongoDB) + a whole lot more

Viktor Klang