Skip to content

Commit 751b477

Browse files
committed
More info on readme
1 parent 6af7cf1 commit 751b477

File tree

1 file changed

+87
-8
lines changed

1 file changed

+87
-8
lines changed

README.md

+87-8
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,20 @@ Python User Language Support for [Spawn](https://github.com/eigr/spawn).
1919
- [Packing with Containers](#packing-with-containers)
2020
- [Defining an ActorSytem](#defining-an-actorsytem)
2121
- [Defining an ActorHost](#defining-an-actorhost)
22+
- [Activators](#activators)
2223

2324

2425
## Overview
25-
TODO
26+
27+
Spawn is a Stateful Serverless Runtime and Framework basead on the Actor Model and operates as a Service Mesh.
28+
29+
Spawn's main goal is to remove the complexity in developing microservices, providing simple and intuitive APIs, as well as a declarative deployment and configuration model and based on a Serverless architecture and Actor Model.
30+
This leaves the developer to focus on developing the business domain while the platform deals with the complexities and infrastructure needed to support the scalable, resilient, distributed, and event-driven architecture that microservices-driven systems requires.
31+
32+
Spawn is based on the sidecar proxy pattern to provide a polyglot Actor Model framework and platform.
33+
Spawn's technology stack, built on the [BEAM VM](https://www.erlang.org/blog/a-brief-beam-primer/) (Erlang's virtual machine) and [OTP](https://www.erlang.org/doc/design_principles/des_princ.html), provides support for different languages from its native Actor model.
34+
35+
For more information consult the main repository [documentation](https://github.com/eigr/spawn).
2636

2737
## Getting Started
2838

@@ -140,10 +150,18 @@ poetry run python3 spawn_py_demo/main.py
140150
And this is it to start! Now that you know the basics of local development, we can go a little further.
141151

142152
## Advanced Use Cases
143-
TODO
153+
154+
Spawn Actors abstract a huge amount of developer infrastructure and can be used for many different types of jobs. In the sections below we will demonstrate some of the features available in Spawn that contribute to the development of complex applications in a simplified way.
144155

145156
### Types of Actors
146-
TODO
157+
158+
First we need to understand how the various types of actors available in Spawn behave. Spawn defines the following types of Actors:
159+
160+
* **Named Actors**: Named actors are actors whose name is defined at compile time. They also behave slightly differently than unnamed actors and pooled actors. Named actors when they are defined with the stateful parameter equal to True are immediately instantiated when they are registered at the beginning of the program, they can also only be referenced by the name given to them in their definition.
161+
162+
* **Unnamed Actors**: Unlike named actors, unnamed actors are only created when they are named at runtime, that is, during program execution. Otherwise they behave like named actors.
163+
164+
* **Pooled Actors**: Pooled Actors, as the name suggests, are a collection of actors that are grouped under the same name assigned to them at compile time. Pooled actors are generally used when higher performance is needed and are also recommended for handling serverless loads.
147165

148166
### Side Effects
149167
TODO
@@ -211,8 +229,16 @@ TODO
211229

212230
## Using Actors
213231

232+
There are several ways to interact with our actors, some internal to the application code and others external to the application code. In this section we will deal with the internal ways of interacting with our actors and this will be done through direct calls to them. For more details on the external ways to interact with your actors see the [Activators](#activators) section.
233+
234+
In order to be able to call methods of an Actor, we first need to get a reference to the actor. This is done with the help of the static method `create_actor_ref` of the `Spawn` class. This method accepts some arguments, the most important being `system`, `actor_name` and `parent`.
235+
236+
In the sections below we will give some examples of how to invoke different types of actors in different ways.
237+
214238
### Call Named Actors
215239

240+
To invoke an actor named like the one we defined in section [Getting Started](#getting-started) we could do as follows:
241+
216242
```python
217243
# Get abstract actor reference called mike
218244
actor: ActorRef = Spawn.create_actor_ref(
@@ -229,8 +255,48 @@ print("Invocation Result Status: " + status)
229255
print("Invocation Result Value: " + str(result.response))
230256
```
231257

258+
Calls like the one above, that is, synchronous calls, always returned a tuple composed of the invocation status message and the response object emitted by the Actor.
259+
232260
### Call Unnamed Actors
233261

262+
Unnamed actors are equally simple to invoke. All that is needed is to inform the `parent` parameter which refers to the name given to the actor that defines the ActorRef template.
263+
264+
To better exemplify, let's first show the Actor's definition code and later how we would call this actor with a concrete name at runtime:
265+
266+
```python
267+
from domain.domain_pb2 import State, Request, Reply
268+
from spawn.eigr.functions.actors.api.actor import Actor
269+
from spawn.eigr.functions.actors.api.settings import ActorSettings, Kind
270+
from spawn.eigr.functions.actors.api.context import Context
271+
from spawn.eigr.functions.actors.api.value import Value
272+
273+
abstract = Actor(settings=ActorSettings(
274+
name="abs_actor", stateful=True, kind=Kind.UNNAMED))
275+
276+
277+
@abstract.action("setLanguage")
278+
def set_language(request: Request, ctx: Context) -> Value:
279+
print("Request -> " + str(request))
280+
print("Current State -> " + str(ctx.state))
281+
282+
reply = Reply()
283+
reply.response = "erlang"
284+
new_state = State()
285+
new_state.languages.append("python")
286+
return Value().of(reply, new_state).reply()
287+
```
288+
289+
The important part of the code above is the following snippet:
290+
291+
```python
292+
abstract = Actor(settings=ActorSettings(
293+
name="abs_actor", stateful=True, kind=Kind.UNNAMED))
294+
```
295+
296+
This tells Spawn that this actor will actually be named at runtime. The name parameter in this case is just a reference that will be used later so that we can actually create an instance of the real Actor.
297+
298+
Finally below we will see how to invoke such an actor. We'll name the royal actor "mike":
299+
234300
```python
235301
# Get abstract actor reference called mike
236302
actor: ActorRef = Spawn.create_actor_ref(
@@ -249,17 +315,30 @@ print("Invocation Result Value: " + str(result.response))
249315
```
250316

251317
### Async calls and other options
252-
TODO
318+
319+
Basically Spawn can perform actor functions in two ways. Synchronously, where the callee waits for a response, or asynchronously, where the callee doesn't care about the return value of the call. In this context we should not confuse Spawn's asynchronous way with Python's concept of async because async for Spawn is just a fire-and-forget call.
320+
321+
Therefore, to call an actor's function asynchronously, just inform the parameter async_mode with the value True:
322+
323+
```python
324+
some_actor.invoke(
325+
action="setLanguage", request=request, async_mode=True)
326+
```
253327

254328
## Deploy
255-
TODO
329+
330+
See [Getting Started](https://github.com/eigr/spawn#getting-started) section from the main Spawn repository for more details on how to deploy a Spawn application.
256331

257332
### Packing with Containers
258333
TODO
259334

260335
### Defining an ActorSytem
261-
TODO
336+
337+
See [Getting Started](https://github.com/eigr/spawn#getting-started) section from the main Spawn repository for more details on how to define an ActorSystem.
262338

263339
### Defining an ActorHost
264-
TODO
265-
340+
341+
See [Getting Started](https://github.com/eigr/spawn#getting-started) section from the main Spawn repository for more details on how to define an ActorHost.
342+
343+
### Activators
344+
TODO

0 commit comments

Comments
 (0)