Tasty.
If you read the original Flux paper carefully, there are several things that the Flux tool provides:
○ A data-flow-like top-level language which describes
- How the C++ functions in the application should be composed to complete the task flow in the program.
- How to protect common resources these functions manipulate using atomicity constraints.
- The C++ types and arguments passed from one task to another (though the Flux compiler itself does not comprehend the types very deeply).
- Abstracting concurrency issues from the developer writing the lower level C++ functions as much as possible.
- Trying not to block when doing synchronized work
- Completing work which it has already underway (so don't begin something new when there is a partially complete and runnable task available).
- High re-use of existing code (they cite the migration of an existing BitTorrrent client to Flux).
- Deadlock avoidance is part of the design
- Performance analysis and prediction
Webserver Example
This example demonstrated nicely how to use the basic parts of the Flux language and how to mentally visualize the program:
/* Your basic web server flow */ node Page (int socket) => (); node ReadRequest (int socket) => (int socket, bool close, const char* request); node Reply (int socket, bool close, int length, const char* content, const char* output) => (); node ReadWrite (int socket, bool close, const char* file) => (int socket, bool close, int length, const char* content, const char* output); node Listen () => (int socket); node FourOhFour (int socket, bool close, const char* file) => (); node BadRequest (int socket) => (); source Listen -> Page; Page = ReadRequest -> ReadWrite -> Reply; handle error ReadWrite -> FourOhF; handle error ReadRequest -> BadRequest;
Visualized as a graph the source node Listen listening to an accept socket passes the request socket to its successor node. The Page node is just an abstract node or expression for what follows (ReadRequest in this case). ReadRequest reads the request from the socket and determines if there is any HTTP keep-alive in the request.
This flow is straight-through handling except that there are error handles along the way for mis-formed requests (BadRequest) and resources which the webserver does not have (FourOhFour named after the famed 404 HTTP return code).
In terms of concurrency the run-time will juggle the system calls that are used to read files, read requests from sockets and write responses on those sockets. Without bothering the application programmer very much about it, the ability to have multiple threads reading different resources (possibly separate files that are not paged into virtual memory yet) at the same time is cool. In this case we say that there are several threads running events for a node like ReadWrite.
No comments:
Post a Comment