Giter Site home page Giter Site logo

zio / zio-actors Goto Github PK

View Code? Open in Web Editor NEW
266.0 20.0 58.0 1.87 MB

A high-performance, purely-functional library for building, composing, and supervising typed actors based on ZIO

Home Page: https://zio.dev/zio-actors

License: Apache License 2.0

Scala 100.00%
scala actor-model functional-programming zio

zio-actors's Introduction

ZIO Logo

Project Stage CI Release Snapshot Issues
Project stage CI Release Artifacts Snapshot Artifacts Average time to resolve an issue
Scaladoc Scaladex Discord Twitter Gitpod
Scaladoc Badge-Scaladex-page Badge-Discord Badge-Twitter Gitpod ready-to-code

Welcome to ZIO

ZIO is a zero-dependency Scala library for asynchronous and concurrent programming.

Powered by highly-scalable, non-blocking fibers that never waste or leak resources, ZIO lets you build scalable, resilient, and reactive applications that meet the needs of your business.

  • High-performance. Build scalable applications with 100x the performance of Scala's Future.
  • Type-safe. Use the full power of the Scala compiler to catch bugs at compile time.
  • Concurrent. Easily build concurrent apps without deadlocks, race conditions, or complexity.
  • Asynchronous. Write sequential code that looks the same whether it's asynchronous or synchronous.
  • Resource-safe. Build apps that never leak resources (including threads!), even when they fail.
  • Testable. Inject test services into your app for fast, deterministic, and type-safe testing.
  • Resilient. Build apps that never lose errors, and which respond to failure locally and flexibly.
  • Functional. Rapidly compose solutions to complex problems from simple building blocks.

To learn more about ZIO, see the following references:


Adopters

Following is a partial list of companies happily using ZIO in production to craft concurrent applications.

Want to see your company here? Submit a PR!

Sponsors

Ziverge

Ziverge is a leading contributor to ZIO.

Scalac

Scalac sponsors ZIO Hackathons and contributes work to multiple projects in ZIO ecosystem.

Septimal Mind

Septimal Mind sponsors work on ZIO Tracing and continuous maintenance.

YourKit

YourKit generously provides use of their monitoring and profiling tools to maximize the performance of ZIO applications.



Code of Conduct

See the Code of Conduct


Support

Come chat with us on Badge-Discord.


Legal

Copyright 2017 - 2024 John A. De Goes and the ZIO Contributors. All rights reserved.

zio-actors's People

Contributors

adamgfraser avatar calvinlfer avatar danielyli avatar francistoth avatar gastonlucero avatar ghostdogpr avatar gitter-badger avatar khajavi avatar ksarath avatar mijicd avatar mtsokol avatar nightscape avatar ragazoor avatar riosgabriel avatar scala-steward avatar softinio avatar terov avatar toxicafunk avatar vigoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zio-actors's Issues

Enhance supervisor

The supervisor takes a schedule, but could also take an "or else" function to do if the retry fails; see IO#retryOrElse0 for inspiration on what this could look like.

Upgrade to ZIO 2.0

ZIO is at Milestone 4, with an RC expected in the next few weeks.
https://github.com/zio/zio/releases/tag/v2.0.0-M4

The API is nearly stable at this point, so any early migration work against this version should pay off towards the official 2.0 release.

The progress is being tracked here:
zio/zio#5470

The Stream Encoding work in progress is the only area where the API might still change before the RC.

To assist with the migration, follow this guide:
https://zio.dev/howto/migrate/zio-2.x-migration-guide/

We are actively working on a ScalaFix rule that will cover the bulk of the simple API changes:
https://github.com/zio/zio/blob/series/2.x/scalafix/rules/src/main/scala/fix/Zio2Upgrade.scala

If you would like assistance with the migration from myself or other ZIO contributors, please let us know!

Logging combinator

We should have an actor combinator that adds logging to input messages, and another that adds logging to output messages, for some suitable type class that allows printing (again, let's define our own to avoid pulling in any dependencies).

Add Lifecycle Hooks

It would be nice to have access to the lifecycle hooks of an actor. Especially a start event would be useful for spawning child actors after startup.

Implement "become" functionality

Akka provides a mechanism to change the current Behavior, but zio-actor does not.

The persistence sample from Akka is unusual since it uses a conditional test rather than changing the Behavior.

zio-actor currently cannot implement many of the other Akka samples. e.g. FSM.

Receiving multiple responses asynchronously

Hi all,

I'm trying to write a zio-actor for the originally Akka based Petri Net implementation Kagera.
The Akka implementation does one thing that I don't know how to do in zio-actors:
When an actor A sends the Petri Net actor B a command to fire a transition, B sends a corresponding TransitionResponse (that's easy to do in zio-actors), but then other transitions can automatically fire and in the Akka implementation this sends additional TransitionResponses back to A asynchronously whenever the automatic transitions have fired (corresponding test).
Afais, a Stateful actor never gets to know the actor who sent it a message, so just sending A an additional TransitionResponse via ! won't work.
The only idea I have for implementing this in zio-actors is to return a Seq[TransitionResponse], but that means that one has to await all transitions to finish before sending the response.

I hope this is understandable without knowing too much about Petri Nets.

Is there any way to get something like this to work?

Migrate to use zio version 0.6.x

Migrate project to use zio 0.6.x.

There are breaking changes moving from 0.5.0 to 0.6.0 which result in these compiler errors:

[error] /home/salar/projects/scalaz-actors/src/main/scala/scalaz/actors/Actors.scala:33:66: value complete is not a member of scalaz.zio.Promise[E,A]
[error]         completer     = ((s: S, a: A) => state.set(s) *> promise.complete(a)).tupled
[error]                                                                  ^
[error] /home/salar/projects/scalaz-actors/src/main/scala/scalaz/actors/Actors.scala:34:23: value redeem is not a member of Any
[error]         _ <- receiver.redeem(
[error]                       ^
[error] /home/salar/projects/scalaz-actors/src/main/scala/scalaz/actors/Actors.scala:37:30: type mismatch;
[error]  found   : Any
[error]  required: scalaz.zio.IO[E,?]
[error]                   .supervise(receiver, e)
[error]                              ^
[error] /home/salar/projects/scalaz-actors/src/main/scala/scalaz/actors/Actors.scala:38:40: value error is not a member of Any
[error]                   .redeem(_ => promise.error(e), completer),
[error]                                        ^
[error] /home/salar/projects/scalaz-actors/src/main/scala/scalaz/actors/Actors.scala:56:32: value get is not a member of scalaz.zio.Promise[E,A]
[error]             value   <- promise.get
[error]                                ^
[error] 5 errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 8 s, completed Jan 27, 2019 8:08:46 AM

Request for The Next Release

I noticed that the latest version of the Caliban-deriving library is not available on the website. This means that users who rely on the website for documentation may not have access to the most up-to-date information.

We want to reflect the latest version of docs on the zio.dev website across all zio ecosystem libraries. In order to update the website with the latest documentation, we need a new library release

Passing zio actor references between Scala objects

Hi,
I am wondering if it is possible to instantiate inside an object in Scala (called for example FirstObject) a zio actor, and then be able to pass the reference of this actor into another Scala object (called for example SecondObject), and to call in SecondObject the ask method (?) on the actor reference , so as to send messages to the actor.

I have this doubt because I have done some trials, but only if I send messages to the actor via the ask method in the object in which the actor is created (FirstObject), do I get a response from the actor, otherwise if I call the ask method in SecondObject, the application remains blocked waiting for the response of the actor (without ever receiving it).

I tried in FirstObject to save the actor reference in the variable reference


  val myAppLogic = for {
    system <- ActorSystem("mySystem")
    MyActorReference <- system.make("MyActor ", Supervisor.none, (), stateful)
  } yield (reference = MyActorReference )

and then pass this variable inside SecondObject, so as to insert it in the zio effect:

 val myAppLogic = for {
   response<- reference ? MyCommand(SomeCommand)
   _   <- printLine("The response is:  ",response)
  } yield ()

Could someone help me figure out what is wrong with my code, or in general if it is possible to implement this behavior?

Actor Persistence

Requirements

  • Add ability to persist actor state to enable recovery
  • Events by actor stored in a supported data store
  • Events are stored by appending and never mutated
  • Add recovery and reply ability by utilizing the persisted events
  • Support ability to recover from full history or a given checkpoint
  • Ability to set a checkpoint

Data Stores to support as a minimum

It would be ideal to have ZIO implementations as an optional dependency on maven for these datastores

  • Postgresql (ZIO Wrapper around Doobie or Skunk)
  • Kafka (Using zio-kafka)
  • Cassandra / ScyllaDB
  • Redis

Notes

  • This feature needs to be split up into multiple issues

Migrate project to CircleCI

  • Migrate Project to CircleCI
  • Use CircleCi env variables for sonatype credentials
  • Update README and code to use new name for repo

Add support for user defined message serialization

Java object serialization isn't a good default for message serialization. Users should be able to provide their own serializer and deserializer for their messages.

@mtsokol Can you help come up with a way to implement this?

I see two ways of doing it:

  1. Option to pass a user defined Serialization[Envelope] to an ActorSystem. The problem I have is that Command message type is any and the response A must be wrapped in an Envelope as well when send over the wire.
  2. Pass a Serialization[F[A], A] each time creating an Actor[F[A]] that can serialize and deserialize the DSL for this Actor
  3. maybe some other approach

Validate actorName in make method

The make method allows actor names that do not match select's regex:

val regex = "^(?:zio:\\/\\/)(\\w+)[@](\\d+\\.\\d+\\.\\d+\\.\\d+)[:](\\d+)[/]([\\w|\\/]+)$".r

The same Regex should be used to validate the actor's full path before creating it.


Failing example:

for {
  system <- ActorSystem("actorSystem", Some("0.0.0.0", "9000"))
  actor  <- system.make("actor-123", Supervisor.none, Unit, stateful)
  _      <- system.select(s"zio://[email protected]:9000/actor-123") // fails with Exception: "No such actor in local ActorSystem"
} yield ()

Caching combinator

We should have an actor combinator that wraps an actor and adds caching, assuming a suitable type class is defined for the input message (hashable and equality?).

We should define our own type classes and remove dependencies on Scalaz, just keep the ZIO dependencies.

CircleCI Release job fails

Circle Release Job issues

  • The release job fails waiting for GPG password to be entered at the sbt releaseEarly step resolve.

  • Also check if its correct to use dev.zio as the Sonatype org name

Sample Failed build:

https://circleci.com/gh/zio/zio-actors/23

Error:

Please enter PGP passphrase (or ENTER to abort): Too long with no output (exceeded 10m0s)

Multiple types of messages/responses

Currently actors are designed as Actor[+E, -A, +B].
Let's say we want our actor to handle 2 types of messages and return a different response type for each.

sealed trait Msg
case class Msg1() extends Msg
case class Msg2() extends Msg

sealed trait Resp
case class Resp1() extends Resp
case class Resp2() extends Resp

We want to return a Resp1 when we receive a Msg1 and a Resp2 when we receive a Msg2.

If we have an Actor[E, Msg, Resp], there is no guarantee for the caller about which subtype it will receive.

The way Akka Typed solved this is by having an ActorRef[T] replyTo as part of the message if a reply is needed. If we restrict ourselves to a single node, this is similar to passing a promise as part of the message:

case class Resp1()
case class Resp2()

sealed trait Msg
case class Msg1(p: Promise[Nothing, Resp1]) extends Msg
case class Msg2(p: Promise[Nothing, Resp2]) extends Msg

So we can have a simple Actor[+E, -A] that returns Unit, and might complete given promises when handling messages.

@jdegoes @softinio and others:
Do you see other possible designs? How do you think we should handle this case?

Installation failure following provided docs

Hi! I'm having trouble following the installation guide, I included both lines:

resolvers += Resolver.sonatypeRepo("snapshots")
libraryDependencies += "dev.zio" %% "zio-actors" % "0.1.0"

I get not foudn error with sbt:

error] (update) sbt.librarymanagement.ResolveException: Error downloading dev.zio:zio-actors_3:0.0.0+1-16e9d9e5-SNAPSHOT
[error]   Not found
[error]   Not found
[error]   not found: /home/myusername/.ivy2/localdev.zio/zio-actors_3/0.0.0+1-16e9d9e5-SNAPSHOT/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/dev/zio/zio-actors_3/0.0.0+1-16e9d9e5-SNAPSHOT/zio-actors_3-0.0.0+1-16e9d9e5-SNAPSHOT.pom
[error]   not found: https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-actors_3/0.0.0+1-16e9d9e5-SNAPSHOT/zio-actors_3-0.0.0+1-16e9d9e5-SNAPSHOT.pom

Is any other repo missing in the documentation?
Also the sonartype repo is not mentioned in the zio.dev but it is on the overview
I would guess is a out of date documentation, if I find the way to make it work I'll comment here and open a pr

Supervising actor

We could have an actor that just reads error messages from other actors and decides what to do, it provides a supervisor that interacts with that "error actor" through promises. This might make it possible to have supervision logic that decides what to do based on looking at all the actors being supervised.

Add Stash Functionality

  • Add ability to stash messages away from processing till request to unstash them is received
  • Ability to have a filtering criteria for messages to stash
  • When unstashing offer options to:
    • unstash All
    • unstash a certain number of messages at a time
    • unstash messages based on a filtering criteria

Add support for mysql for persistence

The idea is to add a new field to the config called "driver".
Then we can set the driver on the data source(ds.setDriverClassName(dbConfig.dbDriver.value)).

Question: should we add the mysql driver as a dependency or the users will add it if they want to use mysql for persistence?

Remoting actor

If the input and output messages can be serialized, we can send an actor request across the wire to a remote system (chosen from among some set of nodes according to some possibly non-deterministic choice function), have it processed there, and then retrieve the result asynchronously.

This could be implemented as some sort of combinator around an existing actor system.

Performance Benchmarks

Evaluate the performance of zio actors.
Ideally this should cover a range of cases similar to the ones covered by akka performance benchmarks https://github.com/akka/akka/tree/master/akka-bench-jmh/src/main/scala/akka/actor

At minimum provide experiments for

  1. Ping pong example (as in https://github.com/akka/akka/blob/master/akka-bench-jmh/src/main/scala/akka/actor/typed/TypedBenchmarkActors.scala)
  2. See how tuning ZIO runtime environment impacts this simple experiment performance (https://github.com/akka/akka/blob/master/akka-bench-jmh/src/main/scala/akka/actor/typed/TypedForkJoinActorBenchmark.scala)

Memory leak during actor creation.

When creating a new actor in the following code:

map <- refActorMap.get
finalName <- buildFinalName(parentActor.getOrElse(""), actorName)
_ <- if (map.contains(finalName)) IO.fail(new Exception(s"Actor $finalName already exists")) else IO.unit
path = buildPath(actorSystemName, finalName, remoteConfig)
derivedSystem = new ActorSystem(actorSystemName, config, remoteConfig, refActorMap, Some(finalName))
childrenSet <- Ref.make(Set.empty[ActorRef[Any]])
actor <- stateful.makeActor(
sup,
new Context(path, derivedSystem, childrenSet),
() => dropFromActorMap(path, childrenSet)
)(init)
_ <- refActorMap.set(map + (finalName -> actor))

If the actor stops and calls dropFromActorMap before it gets added to the actor map at line 143, the map will be updated with a reference to a dead actor, which creates a memory leak.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.