I code multithread in C++, I would strongly disagree your statement that my code would have problems catching up Erlang code.
Quote from nitro:
I have an arbitrage strategy that I am implementing that requires a humongous number of cores/threads to implement. The main problem is, that the languages that I am competent in, threads have all sorts of problems, and in .Net they are hardly lightweight.
This led me to this library:
http://blogs.msdn.com/b/daniwang/archive/2008/12/29/lightweight-threading-using-c-iterators.aspx
It is interesting that C# scales almost as well as Erlang on this test. Funny how C++/C# would crush Erlang on most computational tests, but when it comes to large number of threads, other languages have a hard time keeping pace with Erlang.
It is interesting, this pattern, because most arbitrage type trading requires you to scan large ammounts of data for opportunity. So say you are looking at an option chain, and need to compare that chain against other option chain, where any two options from each chain could be an opportunity. You can begin to see that even for a small number of strikes/months, the combinatorial explosion of computations would overwhelm most computers even with lots of cores.
I always look to simpler domains where it is both fun and educational, and mirrors the problem in the more complex domain. I realized that Conway's Game of Life has many features that, adding the constraint that it must be as fast as possible, that this problem shares many of the techniques that would be useful for this type of high frequency trading.
So, I pose a challenge. Post your best program that uses Erlang to compute the Game of Life. Note that a non-threaded version is not interesting!
Quote from nitro:
I have an arbitrage strategy that I am implementing that requires a humongous number of cores/threads to implement.
Quote from Kevin Schmit:
Nitro, this statement is almost certainly not true.
Before you you run out and buy a machine with a "humongous number of cores" (or rent them on the cloud) and try to run 10,000+ simultaneous threads, I suggest you try redesigning your code. That has got to be an easier solution.
Quote from nitro:
BTW, this seems to be the way to do lightweight threads within a Microsoft solution:
http://msdn.microsoft.com/en-gb/magazine/cc163556.aspx
http://msdn.microsoft.com/en-us/library/bb648752.aspx
Quote from braincell:
I'm not sure about the depth of the analysis you're talking about but did you consider an event driven system? Each will fire it's own thread when needed and terminate with the end of analysis. This can be on a per tick basis for example, or per bid/ask update. If the computation takes less time than each tick (and it should if i understand what you're doing) then you don't have to have threads running at all times. If the computation takes a bit too long, you might need to consider optimizing it by reverting to simpler data structures like 1d arrays etc which are faster than e.g. lists and so on.
Other than that, you can simply do distributed computing where you network multiple CPUs to compute data coming from the central server. Then you don't need a CPU with multiple cores, just any kind of solid data center with a bunch of them networked together. I did this for a similar task.
Finally, the fastest multithreading is done with Assembly language, so consider learning it. I could answer your challenge in ASM but i'm coding too much anyway.
Quote from NetTecture:
Actually no, you still waste. I would basically in C# use a custom TaskScheduler for X threads as above and schedule tasks. See, they do NOT happen at the same time - a CPU core can only execute one hardware thread at the same time ANYWAY. That is 1 thread per core on AMD, 2 on Intel with Hyperthreading. Called hardware. Having less threads in this case is less task switching, on top of a lot less wasted memory. Everyone using 800 threads for something like option chain calculation... better des not claim to be more than a junior developer. Waste of resources and time.
Quote from rufus_4000:
Ok, I will bite. Those who know me knows that I am not a .NET person by any means. But for a large number of concurrent lightweight threads (with the computing threads and I guess the arbitrage opportunity seeking threads), I would think some language constructs like "coroutines" maybe close to the desired goal. I am currently using a customized version of coroutines (libpcl with stack jumps for anyone that cares) along with my thread pool library in production platform, and it has yielded significant performance improvements (over simple "green-ish" threads). I believe MSFT calls coroutines "Fibers" under the .NET, but that's about the extent of my knowledge there.
For those of you who are not familiar with coroutines (other than the original Don Knuth's definition), lookup the Wikipedia entry. I think of it as a concurrency semantics free (as concurrency is implied in the "Yield" operation) cooperative execution, which, incidentally (!), works quite well for data processing, analytics generating, etc.