I’m still trying to learn a bit of F# and I thought of a quite nice experiment.
Since F# supports quotations (for you C# devs, think Linq Expressions on roids) wouldn’t it be possible to serialize such quotation and pass it to a webservice and execute that code there?
Imagine the following code for a fractal calculation:
for y = 0 to 100000 do CloudExec( <@ let Fractal xx yy = .....fractal calculation.... for x = 0 to 100000 do Fractal x y @>)
If “CloudExec” passes the code quote for individual scanlines of the fractal to the cloud, we could get some massive parallelism.
It would be just like PLinq but instead of executing a delegate in multiple threads, we would execute blocks of code on multiple threads on multiple machines (please ignore how naïve the code sample above is).
The biggest problem as far as I can tell would be to pass a result set back to the client in some way (that is missing in the sample code).
Input data doesn’t seem to be a problem since values defined outside the quotes are represented as constants in the quote.
It would ofcourse madness to expose such services to the public since you could pass in any code you want, but maybe it would work in an isolated environment.
Have anyone done such thing already?
//Roger
Yes indeed, now you say new Thread { IsBackground = true }
But soon you will tell new CloudThread { … :)
The code wil automatically be proxied to multiple servers!
Stop trying to send serialized logic over the wire! :)
Why?
You do it every time you execute a Linq query with NHib/LTS.
Or is it only OK when it is in a form you are used to, eg. SQL or Javascript ?
In fact this idea has been around for a long time in functional languages. One of the nice tings about immutable values and the other design features of a functional language. See:
http://www.macs.hw.ac.uk/~dsg/gdh/
We have started a project like that a few years back. It consists of a generic client that (after authentication) executes the .NET code that is sent over the wire and passes the result back to the caller. This can be done pretty safely because the code can be executed in a sandbox.
The part of executing stuff remotely and bringing the result back to the server is solved. However we ran into massive problems with asynchronous communication which I think is needed for good performance, so we have just started our third rewrite of the damn thing!
Maybe you should check M-Brace, a new upcoming cloud framework based on F# that pretty much does what you describe here…
http://www.m-brace.net