You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+87-8
Original file line number
Diff line number
Diff line change
@@ -19,10 +19,20 @@ Python User Language Support for [Spawn](https://github.com/eigr/spawn).
19
19
-[Packing with Containers](#packing-with-containers)
20
20
-[Defining an ActorSytem](#defining-an-actorsytem)
21
21
-[Defining an ActorHost](#defining-an-actorhost)
22
+
-[Activators](#activators)
22
23
23
24
24
25
## 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).
26
36
27
37
## Getting Started
28
38
@@ -140,10 +150,18 @@ poetry run python3 spawn_py_demo/main.py
140
150
And this is it to start! Now that you know the basics of local development, we can go a little further.
141
151
142
152
## 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.
144
155
145
156
### 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.
147
165
148
166
### Side Effects
149
167
TODO
@@ -211,8 +229,16 @@ TODO
211
229
212
230
## Using Actors
213
231
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
+
214
238
### Call Named Actors
215
239
240
+
To invoke an actor named like the one we defined in section [Getting Started](#getting-started) we could do as follows:
241
+
216
242
```python
217
243
# Get abstract actor reference called mike
218
244
actor: ActorRef = Spawn.create_actor_ref(
@@ -229,8 +255,48 @@ print("Invocation Result Status: " + status)
229
255
print("Invocation Result Value: "+str(result.response))
230
256
```
231
257
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
+
232
260
### Call Unnamed Actors
233
261
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
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
+
234
300
```python
235
301
# Get abstract actor reference called mike
236
302
actor: ActorRef = Spawn.create_actor_ref(
@@ -249,17 +315,30 @@ print("Invocation Result Value: " + str(result.response))
249
315
```
250
316
251
317
### 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:
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.
256
331
257
332
### Packing with Containers
258
333
TODO
259
334
260
335
### 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.
262
338
263
339
### 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.
0 commit comments