From 04ffae022593527845866d2c9257a7c45c419714 Mon Sep 17 00:00:00 2001 From: Petr Stefan Date: Wed, 15 Jun 2016 21:07:20 +0200 Subject: [PATCH] Updated Communication (markdown) --- Communication.md | 85 ++++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/Communication.md b/Communication.md index e7cef0e..ebd67af 100644 --- a/Communication.md +++ b/Communication.md @@ -4,46 +4,57 @@ This section gives detailed overview about communication in ReCodEx solution. Ba ![Communication Img](https://github.com/ReCodEx/GlobalWiki/raw/master/images/Backend_Connections.png) -Red connections are through ZeroMQ sockets, Blue are through WebSockets and Green are through HTTP. +Red connections are through ZeroMQ sockets, Blue are through WebSockets and Green are through HTTP. All ZeroMQ messages are sent as multipart with one string (command, option) per part, with no empty frames (unles explicitly specified otherwise). + ## Internal worker communication +Communication between the two worker threads is split into two separate parts, each one holding dedicated connection line. These internal lines are realized by ZeroMQ inproc PAIR sockets. For this section assume that the thread of the worker which communicates with broker is called _listening thread_ and the other one, which is evaluating incoming jobs is called _job thread_. _Listening thread_ is at both cases server (here is called `bind()` method), but because of ZeroMQ function it's not much important (`connect()` call in clients can precede server `bind()` call with no issue). + +### Main communication + +Main communication is on `inproc://jobs` sockets. _Listening thread_ is waiting for any messages (from broker, jobs and progress sockets) and handle incoming requests properly. + +Commands from _listening thread_ to _job thread_: +- **eval** - evaluate a job. Requires 3 arguments: + - `job_id` - identifier of this job + - `job_url` - URI location of archive with job configuration and submitted source code + - `result_url` - remote URI where results will be pushed to + +Commands from _job thread_ to _listening thread_: +- **done** - notifying of finished job. Requires 2 arguments: + - `job_id` - identifier of finished job + - `result` - response result, one of "OK" and "ERR" + +### Progress callback + +Progress messages are sent through `inproc://progress` sockets. This is only one way communication from _job thread_ to the _listening thread_. + +Commands: +- **progress** - notice about evaluation progress. Requires 2 or 4 arguments: + - `job_id` - identifier of current job + - `state` - what is happening now. One of "DOWNLOADED" (submission successfuly fetched), "UPLOADED" (results are uploaded to fileserver), "STARTED" (evaluation started), "ENDED" (evaluation is finnished) and "TASK" (task state changed - see below) + - `task_id` - only present for "TASK" state - identifier of task in current job + - `task_state` - only present for "TASK" state - result of task evaluation. One of "COMPLETED" and "FAILED". + + ## Broker - Worker communication -When a worker is started, it registers itself with the broker by sending the -`init` command followed by its hardware group and headers that describe its -capabilities (such as the number of threads it can run simultaneously, -languages it can work with...). The headers are expected to be in following -format: `header_name=value`. Every header shall be in a separate frame. - -Whenever the broker receives an assignment suitable for the worker, it just -forwards the evaluation request message it originally received from the -frontend. The worker has to: - -- Download the archive containing the submission and an isoeval configuration - file -- Download any supplementary files based on the configuration file, such as test - inputs or helper programs (This can be done on demand, using a `fetch` command - in the assignment configuration) -- Download the source codes of the student's submission -- Evaluate the submission according to the assignment's configuration -- Upload the results of the evaluation to the file server -- Notify the broker that the evaluation is finished - -Thanks to this message structure, it's possible to cache the configuration file -and only download the student's submissions when the same assignment is -evaluated repeatedly for different students (a common case for homeworks and -classroom assignments). - -After finishing the evaluation, worker notifies the broker of this fact by -sending: - -- The `done` command -- The job id - -This allows the broker to reliably distribute messages - if a worker doesn't -succeed in processing a request (it doesn't respond in a time limit), the -request can be sent to another worker. +Broker is server when comminicating with worker. IP address and port are configurable, protocol is TCP. Worker socket is DEALER, broker one is ROUTER type. + +Commands from broker to worker: +- **eval** - evaluate a job. See **eval** command in [[Communication#main-communication]]. +- **intro** - introduce yourself to the broker (with **init** command) +- **pong** - reply to **ping** command, no arguments + +Commands from worker to broker: +- **init** - introduce yourself to the broker. Useful on startup or after reestablishing lost connection. Requires at least two arguments: + - `hwgroup` - hardware group of this worker + - `header` - additional header describing worker capabilities. Format must be `header_name=value`, every header shall be in a separate message frame. There is no maximum limit on number of headers. +- **done** - job evaluation finished, see **done** command in [[Communication#main-communication]]. +- **progress** - evaluation progress report, see **progress** command in [[Communication#progress-callback]] +- **ping** - tell broker I'm alive, no arguments + ## Worker - File Server communication @@ -84,4 +95,6 @@ processes the request. This issue remains to be resolved. ## Monitor - Browser communication -## Frontend - Browser communication \ No newline at end of file +## Frontend - Browser communication + +**TODO:** \ No newline at end of file