Skip to content

Commit e501bdf

Browse files
committed
Updated README.
1 parent f643779 commit e501bdf

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,46 @@
22
Python simulator of distributed system
33

44
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/xneg/distributed-game/main?labpath=%2Fsrc%2Fsandbox_notebook.ipynb)
5+
6+
# Web-version
7+
https://xneg.github.io/distributed-game/
8+
9+
# How to
10+
You need to implement your own algorithm inheriting [class Node](https://github.com/xneg/distributed-game/blob/main/src/engine/node.py).
11+
There are two abstract methods processing read and write requests:
12+
```python
13+
@WebServer.endpoint(message_type=ClientReadRequest)
14+
@abc.abstractmethod
15+
def process_read_request(self, request):
16+
pass
17+
18+
@WebServer.endpoint(message_type=ClientWriteRequest)
19+
@abc.abstractmethod
20+
def process_write_request(self, request):
21+
pass
22+
```
23+
You can see examples [here](https://github.com/xneg/distributed-game/tree/main/src/algorithms).
24+
25+
# Engine
26+
![diagram_2](https://user-images.githubusercontent.com/5748886/180388311-e00628d9-0408-4e77-8689-0edc327f0975.jpg)
27+
This diagram shows communication between two `WebServers`.
28+
WebServer contains three main methods:
29+
30+
* send_message(receiver_id, message)
31+
32+
* add_message(message)
33+
34+
* process()
35+
36+
The `send_message(receiver_id, message)` method creates a `Signal` (1) object that contains the "message packet" itself and the ID of the receiving server.
37+
In fact, `Signal` after a certain number of steps will call the `add_message(message)` (2) callback already on the recipient side.
38+
39+
The `add_message(message)` method sends a message to one of the server endpoints (3) with the help of typing, decorators and a bit of "pythonic" magic.
40+
Web servers use signals instead of calling each other's methods directly to mimic the asynchronous nature of network.
41+
The signal can have an arbitrary execution time, moreover, it is possible to make the signal "lost" by simulating network breaks.
42+
43+
![diagram_1](https://user-images.githubusercontent.com/5748886/180388323-8a26f1a4-e4e1-41fe-85a9-c982fe55d46b.jpg)
44+
This diagram shows implemented system. The client only knows about the gateway.
45+
Gateway acts as a proxy between the client and the nodes of the system, it knows about anything. The gateway forwards client requests to nodes via round-robin (the first request comes to the first node, the second - to the second).
46+
Then the nodes exchange messages with each other and send the response back to the gateway, which returns it to the client.
47+
All the arrows on the diagram are, in fact, signals.

0 commit comments

Comments
 (0)