I'm new to Clojure as well and am also writing a server. Side effects are hard to avoid when doing things like I/O, so I wouldn't feel too bad about it. From the looks of your code, you've done a nice job separating things like network communication from the business logic of your chat server. I had a look at server-socket in clojure.contrib when I started my project, but it appeared to create a thread per connection, so I opted against it. I'm no expert, but I think you might get better scalability using something like ThreadPoolExecutor to manage your threads. It probably doesn't matter in your case as you've said it was a proof of concept, but I'm just throwing that out there. To test the basics of my server, I setup something in ruby to make thousands of concurrent connections and see how Clojure would scale. Somewhere in the 3000-4000 simultaneous connection range, the ruby script crashed with an error of "too many files open". Meanwhile the Clojure program had 15 threads open and was chugging along nicely ;-). Of course, this was with Ruby 1.8.x, so things might be better in the 1.9 branch.
Travis On Apr 28, 7:27 pm, Chris McClellen <chris.mcclel...@gmail.com> wrote: > I wanted to write an example server in clojure to show some folks at > the office what a full from the ground up application might look like > in clojure. I wanted a non-trivial example, but not one so complex > that a new clojure user wouldn't understand it. I had ported some > decent algorithms we used over to clojure and was impressed at the > expressiveness (moving something that took 500+ lines to express in a > more popular language down to 71 sloc). However, that effort was not > an application, just a set of functions running against test data. > > I ended up writing a chat server in clojure, thats weighs in at about > 189 lines of code (not counting comments and blank lines). I am > fairly new to clojure so I was hoping people could take a look at it > and give constructive comments about what I did right and what I did > wrong. > > The server implements users, chat rooms, private messaging and so > forth. It also uses the concurrency built in so I could attempt to > show off the concurrent nature of clojure to my colleagues. > > Some things to note: > > * I am new to clojure. I have about 4 weeks of experience now, about > half of it spent reading up on clojure so I could write this thing. I > am sure the code will show that off :( > * I realize there is a specification for IRC. I wanted something > simpler. > * This server is just an example, and it is built around people using > telnet to connect to it. It is not robust. Simple things like a > client not reading its input will eventually hang a user thread. > * Lots of IO, so unfortunately, quite a bit of side effects. > > I'll probably add features over time. But please, look at it and give > me feedback so I can get better at clojure. > > Here's the link > > http://github.com/cmcclellen/crm.chat-server/tree/master --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---