Friday, June 20, 2008

jSuneido - server (yet again)

Ok, so the plan is to use Java Channel's, Selector, and Executor to build a Reactor style server. How hard can it be :-)

The problem is multi-threading concurrency. Why isn't that surprising?

It turns out that using Selector with multiple threads requires some tricky locking. At first, looking at Architecture of a Highly Scalable NIO-Based Server it didn't seem too bad.

But then, I found How to Build a Scalable Multiplexed Server With NIO Mark II (large pdf) and it started to seem harder. I downloaded his source code and at least it was small enough to be comprehensible. Full frameworks tend to be too big to easily grasp.

At first I was just going to use his code as an example. But after a half hour of copy and paste I came to my senses. Although I was simplifying it a little, I was basically ending up duplicating his code. Not a good plan. Especially since his code is still "preliminary" and could change.

I threw out what I'd done and dropped his code into my project. And so far it's working. We'll see.

1 comment:

Anonymous said...

Hi Andrew,
I think you should consider the use of Scala to implement the DB Server.The reason for this suggestion is Scalas Actor model (Erlang -style processes)
I have seen some really remarkable benchmarks. You can find them under Documents/Scala Actors on the Scala Home page :
http://www.scala-lang.org/docu/papers.html
Nana
Probabely also to say : Welcome back Generics ...