Generators in D

Jose Armando Garcia jsancio at gmail.com
Tue May 17 12:07:46 PDT 2011


>
> If serialization will be clever enough, these fibers could even be shared
> across different servers! This is really a requirement in load balanced
> environments.
>

A very old research paper (I think it was for the amoeba project)
wrote a long time ago (I don't remember the wording) that is usually a
bad idea to migrate already running tasks (process, thread, fiber,
etc). Leading to the observation that it is probably best to do
offloading/load-balancing before the work is started. That is how most
modern scale-able architectures work. This is just an observation
since you haven't exactly said how to use Fiber to save Http sessions.

On Tue, May 17, 2011 at 11:37 AM, Piotr Szturmaj <bncrbme at jadamspam.pl> wrote:
> Piotr Szturmaj wrote:
>>
>> Hi,
>>
>> I've written some proof of concept code of generator pattern, example:
>>
>> void genSquares(out int result, int from, int to)
>> {
>> foreach (x; from .. to + 1)
>> {
>> yield!result(x * x);
>> }
>> }
>>
>> void main(string[] argv)
>> {
>> foreach (sqr; generator(&genSquares, 10, 20))
>> writeln(sqr);
>> }
>>
>> posted on github:
>>
>> https://github.com/pszturmaj/dgenerators
>>
>> Thanks to Sean Kelly who wrote Fiber code.
>>
>> Piotr
>
> Well, I've just found this:
> http://www.mail-archive.com/digitalmars-d@puremagic.com/msg30204.html. It
> seems someone did it before ;)
>
> In regards to serializable fibers, I've found some interesting potential
> usage - session handling in HTTP server. Fiber code could represent session
> and could be saved to disk in the middle of execution, just like sessions
> are saved in PHP. This is used to offload memory when handling great number
> of sessions.
>
> If serialization will be clever enough, these fibers could even be shared
> across different servers! This is really a requirement in load balanced
> environments.
>
> Piotr
>


More information about the Digitalmars-d mailing list