fixes #8
This commit is contained in:
46
README.md
46
README.md
@@ -9,54 +9,74 @@ Distributed Function Caller Framework for Python
|
|||||||
Dependencies:
|
Dependencies:
|
||||||
- websockets
|
- websockets
|
||||||
- fastapi
|
- fastapi
|
||||||
- requests
|
|
||||||
- uvicorn
|
- uvicorn
|
||||||
- pydantic
|
- pydantic
|
||||||
|
|
||||||
## Usage:
|
## Usage:
|
||||||
|
|
||||||
Requires 3 scripts: Client, Broker and Runner
|
Requires 3 scripts: Client, Router and Runner
|
||||||
|
|
||||||
- Broker will mediate load balancing and connection handling, so this should start first. One port should be open.
|
### 1. Router
|
||||||
|
|
||||||
Let broker's IP be `192.168.0.110` and port be `7732`
|
The Router will mediate load balancing and connection handling between the function runners and callers, so this should start first. One port must to facilitate the communication.
|
||||||
|
|
||||||
|
This example starts the router on IP `192.168.0.110` and port `7732`.
|
||||||
```python
|
```python
|
||||||
|
|
||||||
from harmoney import router as rou
|
from harmoney.router import startRouter
|
||||||
|
|
||||||
ro.startRouter("0.0.0.0", 7732)
|
startRouter("0.0.0.0", 7732)
|
||||||
```
|
```
|
||||||
|
|
||||||
- Runner performs the calculations, should contain function definitions. Connects to broker using broker's IP.
|
### 2. Runner
|
||||||
|
|
||||||
|
Runner exposes the function calls and contains all the heavy compute logic. Below code connects one instance of runner to the router.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
|
||||||
from harmoney import runners as run
|
from harmoney.runner import startRunner
|
||||||
|
|
||||||
def customFunction(arg1: int, arg2: str) -> str:
|
def customFunction(arg1: int, arg2: str) -> str:
|
||||||
return arg2*arg1
|
return arg2*arg1
|
||||||
|
|
||||||
funcs = {"custFn": customFunction}
|
funcs = {"custFn": customFunction}
|
||||||
|
|
||||||
run.startRunner(funcs, "192.168.0.110", 7732)
|
startRunner(funcs, "192.168.0.110", 7732)
|
||||||
```
|
```
|
||||||
|
|
||||||
- Client is the main caller of functions. Will contain your main code.
|
Functions must return objects that are pickleable. `None` or no return statement is valid.
|
||||||
|
|
||||||
|
### 3. Client
|
||||||
|
|
||||||
|
Client requests the function - argument combinations to run on runners.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
|
||||||
from harmoney import client as cli
|
from harmoney.client import Client
|
||||||
|
|
||||||
cli.Client("192.168.0.110", 7732)
|
cli = Client("192.168.0.110", 7732)
|
||||||
|
|
||||||
retVal = cli.runSingle("custFn", arg1=10, arg2="arst")
|
retVal = cli.runSingle("custFn", arg1=10, arg2="arst") # run only this combination
|
||||||
|
|
||||||
print(retVal)
|
print(retVal)
|
||||||
|
|
||||||
|
cli.addCall("custFn", arg1=123, arg2="qwf") # add this combination to queue
|
||||||
|
cli.addCall("custFn", arg1=321, arg2="ars") # add this combination to queue
|
||||||
|
res = cli.runAllCalls() # send queued combs at a time.
|
||||||
|
print(res) # Print all the results
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Return values from `runALlCalls` are in the order of their function combination in the queue.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
- [ ] Error catching, keeping the connection to the broker
|
- [ ] Error catching, keeping the connection to the broker
|
||||||
- [ ] Error info should return to the client
|
- [ ] Error info should return to the client
|
||||||
- [ ] Remove dependency on fastapi and requests, move to completely to websockets
|
- [ ] Remove dependency on fastapi and requests, move to completely to websockets
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
~ A Grammer Society Project.
|
||||||
Reference in New Issue
Block a user