Quantcast
Channel: Akka Libraries - Discussion Forum for Akka technologies
Viewing all 1359 articles
Browse latest View live

Akka Actor logging of line numbers

$
0
0

We are using Akka 2.4.19 with Scala 2.12.12. If I configure logback to log line numbers I only see:

Slf4jLogger.scala:83

which is a class in the akka library. How do I get the real location of the issued log statement or what am I doing wrong?

See also https://stackoverflow.com/questions/64355775/how-to-log-filename-and-linenumber-in-akka-classic-actor

I do use the following pattern:

<pattern>%d{HH:mm:ss.SSS} %-5level [%thread] [%logger] [%F:%L] [%mdc{akkaSource:-}] %msg [%mdc]%n</pattern>

Patrik answered:
"…Short answer is that Akka’s logging is asynchronous so Slf4jLogger is expected. You can create your own slf4j Logger with the LoggerFactory and then you will see your own source code. "

I am not sure if I understand what and why to do. Logback is a backend for Slf4j. Do we have to switch to Slf4j Impl now? And why?

2 posts - 2 participants

Read full topic


Akka Remote Performance issue

$
0
0

I am facing a performance issue in Akka remoting. I have 2 actors Actor1 and Actor2. The message sending between the actor is synchronous ask request from Actor1 to Actor2 and the response back from Actor2 to Actor1. Below is the sample code snippets and config of my Actor:
Actor1.java:

object Actor1 extends App {
  val conf = ConfigFactory.load()
  val system = ActorSystem("testSystem1", conf.getConfig("remote1"))
  val actor = system.actorOf(Props[Actor1].withDispatcher("my-dispatcher"), "actor1")
  implicit val timeOut: Timeout = Timeout(10 seconds)

  class Actor1 extends Actor {
    var value = 0
    var actorRef: ActorRef = null

    override def preStart(): Unit = {
      println(self.path)
    }

    override def receive: Receive = {
      case "register" =>
        actorRef = sender()
        println("Registering the actor")
        val time = System.currentTimeMillis()
        (1 to 300000).foreach(value => {
          if (value % 10000 == 0) {
            println("message count -- " + value + " --- time taken - " + (System.currentTimeMillis() - time))
          }
          Await.result(actorRef ? value, 10 seconds)
        })
        val totalTime = System.currentTimeMillis() - time
        println("Total Time - " + totalTime)
    }
  }

}

Actor2.java:

object Actor2 extends App {
  val conf = ConfigFactory.load()
  val system = ActorSystem("testSystem1", conf.getConfig("remote2"))
  val actor = system.actorOf(Props[Actor2].withDispatcher("my-dispatcher"), "actor2")
  implicit val timeOut: Timeout = Timeout(10 seconds)
  actor ! "send"


  class Actor2 extends Actor {
    var value = 0
    var actorSelection: ActorSelection = context.actorSelection("akka://testSystem1@127.0.0.1:6061/user/actor1")

    override def receive: Receive = {
      case "send" =>
        actorSelection ! "register"
      case int: Int => {
        sender() ! 1
      }
    }
  }


}

application.conf:

remote1 {
  my-dispatcher {
    executor = "thread-pool-executor"
    type = PinnedDispatcher
  }
  akka {
    actor {
      provider = remote
    }
    remote {
      artery {
        transport = tcp # See Selecting a transport below
        canonical.hostname = "127.0.0.1"
        canonical.port = 6061
      }
    }
  }
}

remote2 {
  my-dispatcher {
    executor = "thread-pool-executor"
    type = PinnedDispatcher
  }
  akka {
    actor {
      provider = remote
    }
    remote {
      artery {
        transport = tcp # See Selecting a transport below
        canonical.hostname = "127.0.0.1"
        canonical.port = 6062
      }
    }
  }
}

Output:

message count -- 10000 --- time taken - 5871
message count -- 20000 --- time taken - 9043
message count -- 30000 --- time taken - 12198
message count -- 40000 --- time taken - 15363
message count -- 50000 --- time taken - 18649
message count -- 60000 --- time taken - 22074
message count -- 70000 --- time taken - 25487
message count -- 80000 --- time taken - 28820
message count -- 90000 --- time taken - 32118
message count -- 100000 --- time taken - 35634
message count -- 110000 --- time taken - 39146
message count -- 120000 --- time taken - 42539
message count -- 130000 --- time taken - 45997
message count -- 140000 --- time taken - 50013
message count -- 150000 --- time taken - 53466
message count -- 160000 --- time taken - 57117
message count -- 170000 --- time taken - 61246
message count -- 180000 --- time taken - 65051
message count -- 190000 --- time taken - 68809
message count -- 200000 --- time taken - 72908
message count -- 210000 --- time taken - 77091
message count -- 220000 --- time taken - 80855
message count -- 230000 --- time taken - 84679
message count -- 240000 --- time taken - 89089
message count -- 250000 --- time taken - 93132
message count -- 260000 --- time taken - 97360
message count -- 270000 --- time taken - 101442
message count -- 280000 --- time taken - 105656
message count -- 290000 --- time taken - 109665
message count -- 300000 --- time taken - 113706
Total Time - 113707

Is there any wrong I am doing here?. Any observation or suggestion to improve the performance?

1 post - 1 participant

Read full topic

Akka 2.5.32 released

$
0
0

Dear hakkers,

We are pleased to announce the 2.5.32 patch release of Akka 2.5. The release backports some fixes.

This is expected to be one of the last releases in the 2.5 series, and we
encourage any users to plan their upgrade to 2.6. Our
migration guide
should help here.

Notable changes:

  • Fix TLS 1.3 issues on JDKs which support it #29121
  • Handling of onSpinWait and its absence in AffinityPool #28945
  • Testkit: more resilient check for available loopback addresses in SocketUtil on MacOS #29608

A total of 4 issues were closed since 2.5.31. The complete list can be found on the 2.5.32 milestone on github.

Credits

For this release we had the help of 5 committers – thank you very much!

commits  added  removed
      3    123       54 Johannes Rudolph
      1    128       10 Bartłomiej Szwej
      1     42       20 Yury Gribkov
      1     39       15 Viktor Klang (√)
      1      2        2 Arnout Engelen

The Akka core team is employed by Lightbend. If you’re looking to take your Akka systems to the next level, let’s set up a time to discuss our enterprise-grade expert support, self-paced education courses, and technology enhancements that help you manage, monitor and secure your Akka system from development to production.

Happy hakking!

– The Akka Team

1 post - 1 participant

Read full topic

Connection was closed while response was still in-flight with localstack-s3

$
0
0

Hello, i’m running locally

docker run -e SERVICES='s3' -e DEFAULT_REGION='eu-west-1' -p 4566:4566 -it localstack/localstack:0.11.6
  • create bucket with aws cli:
aws --endpoint-url=http://localhost:4566 s3 mb s3://testBucket
  • when calling:
S3.checkIfBucketExists("testBucket")

it fails with error:
Connection was closed while response was still in-flight

Am i missing something ?

2 posts - 2 participants

Read full topic

How to restart the stopped Actor?

$
0
0

Hi everyone,

We somehow fall into this NonFatal exception, we can see its log.
Then the consumer gets stopped and doesn’t restart itself. It stays shut.

Can anyone help why it may occur and maybe we can solve it?
Or, as a quick workaround, at least how can we auto-restart it?

We have this code in supervisor but it doesn’t help:

case ex: Exception =>
Restart

Here is the log message we get:
[6baf9] Exception when polling from consumer, stopping actor: org.apache.kafka.common.KafkaException: Unexpected error from SyncGroup: The server experienced an unexpected error when processing the request.

2 posts - 2 participants

Read full topic

Cluster Sharding - Persistence - Multiple Keyspaces

$
0
0

Hi everybody,

I have a question about Akka Casssandra Persistance Plugin and Cluster Shard Persistence Plugin…

In our project, we initially used one single Keyspace for Akka Cassapersistance Plugin and Cluster Shard Persistence Plugin, when we discerned our Cassandra Cluster overloaded, we started making some Load Tests and tried to write Akka Casssandra Persistance Plugin to one Cassandra Keyspace (for our Business Logic) and Cluster Shard Persistence to another Keyspace,

At the end we discovered %50 of writes to Cassandra caused by the Cluster Shard Persistence Plugin and the other %50 Akka Casssandra Persistance Plugin(our Business Logic) and now we are considering to use for our business logic a Cassandra Cluster and Cluster Shard Persistence another Cassandra Cluster…

Now our application also use ‘remember entities’ functionality of the Cluster Sharding, now when I have two Keyspaces in Cassandra I can see that Cluster Sharding writing to one Keyspace and Business Logic to another Keyspace but after the shutdown the Akka Cluster and restart with two Keyspace solution, Akka Cluster does not remember (recover) the entities but when I configure to write one Keyspace (Cluster Sharding and Business Logic)then ‘remember entities’ functions.

Does the ‘remember entities’ to work Cluster Sharding and Akka Cassandra Persistence Plugin must be configured to same Keyspace? (I don’t think there is a problem with the configuration of the Cassandra Connection oder Plugin while Sharding writes to correct ‘mysharding_akka’ Keyspace, I can see everything in 'messages ’ and Akka Cassandra Plugin writes correctly to another ‘my_akka’ Keyspace for business logic)…

Below is my Akka configuration for both plugins, one for single keyspace ‘my_akka’ configuration (and ‘remember entites’ works) the other one with two keyspaces ‘my_akka’ and ‘mysharding_akka’ which don’t but as you can see only change is the Keyspace configuration…

I am stuck with a little bit of an old version of Akka 2.5.x,

One Keyspace:

cassandra-journal {
contact-points = [“localhost”]
port = 9042
keyspace = “my_akka”
events-by-tag.enabled = false
}

cassandra-snapshot-store {
contact-points = [“localhost”]
port = 9042
keyspace = “my_akka”
}

cassandra-journal-sharding {
contact-points = [“localhost”]
port = 9042
keyspace = “my_akka”
}

cassandra-snapshot-store-sharding {
contact-points = [“localhost”]
port = 9042
keyspace = “my_akka”
}

akka {
cluster {
min-nr-of-members = 1
seed-nodes = [“akka://mysystem@127.0.0.1:2552”]
}
remote.artery {
enabled = on
transport = tcp
canonical.hostname = “127.0.0.1”
canonical.port = 2552
}
}

Two Keyspaces:

cassandra-journal {
contact-points = [“localhost”]
port = 9042
keyspace = “my_akka”
events-by-tag.enabled = false
}

cassandra-snapshot-store {
contact-points = [“localhost”]
port = 9042
keyspace = “my_akka”
}

cassandra-journal-sharding {
contact-points = [“localhost”]
port = 9042
keyspace = “mysharding_akka”
}

cassandra-snapshot-store-sharding {
contact-points = [“localhost”]
port = 9042
keyspace = “mysharding_akka”
}

akka {
cluster {
min-nr-of-members = 1
seed-nodes = [“akka://mysystem@127.0.0.1:2552”]
}
remote.artery {
enabled = on
transport = tcp
canonical.hostname = “127.0.0.1”
canonical.port = 2552
}
}

1 post - 1 participant

Read full topic

Unable to access akka documentation, server seems to be down and have a config issue

Actor Architecture: How to

$
0
0

Hello everyone.
I’m extremely new to the Akka framework. I followed a lightbend certification on academy, and the full IoT tutorial on akka website.
But now it’s time to try to put hands on it.
I am trying to create a simple trading bot, let’s say.

But I already umh, got lost in the correct way to architect my actors hierarchy.
My idea is having an Actor Trader that follows a single currency.
Each Trader than will spawn 2 actors, one for buy and one for sell, and they will save the status of last operation in a instance variable.

So let’s Say we have a Trader for BTC
It starts with status of lastOperation = None
it Spawns 2 new actors (Buy-BTC, Sell-BTC)
when a message CoinPrice arrives on the status of lastOperation it will forward a new message to the correct Actor. I do this because I want ofc implement different logic on buying/selling.
Does it make sense to follow a thing like this?
or would you suggest a different approach?

I know it’s very generic question, but since it’s my first project and I don’t have anyone I can ask to, here I am.
Thank you

1 post - 1 participant

Read full topic


How to persist messages with new sequence Number in case of Recovery Failures

$
0
0

How to make sure that in case of Recovery failures, the queued messages for actor are persisted to Journal.
I am using classic actors. But if the recovery fails, the messages in the queue are not saved to the journal db. Tried reading the documentation, after calling onRecoveryFailure, it directly terminates the actor. Is there any way to persist the newly received message before terminating the actors.
following is my createReceiveRecover:

@Override
    public Receive createReceiveRecover() {
        return receiveBuilder()
                .match(Message.class, m -> {
                    retryDecorator().apply(m);
                    save();
                })
                .match(
                        RecoveryCompleted.class,
                        r -> log.info("Recovery Completed for Actor {}", persistenceId()))
                .match(
                        SnapshotOffer.class,
                        ss -> {
                            // do some stuff
                        })
                .matchAny((s) -> log.info("Message replay {} ", s))
                .build();
    }

I have noticed, that in case of messages coming in batch, even if first sequence fails, some messages with higher sequence numbers are also persisted. I am guessing that till that time , recovery doesnt starts and hence some higher number sequences gets saved.
But if the recovery happens, none of the higher sequence messages are saved to journal.

Thanks

1 post - 1 participant

Read full topic

SOLVED: Scala Akka Typed: how to add a Jackson module to avoid de-serialization error of Address

$
0
0

Hi,

I am having trouble de-serializing a Map[Address,Job] inside a State object. The problem stems from the fact that the de-serializer for the Address is not found. For this test:

    k.testKit.serializationTestKit.verifySerialization(trq1)

I get the error:

Test concurrency.WorkStealSpec.testJacksonSerializationState failed: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot find a (Map) Key deserializer for type [simple type, class akka.actor.Address]
 at [Source: (byte[])"�estate�dtypeiTestStatedjobs��kjobsPending�takka://WorkStealSpec�dtypeiFailFirstbidP�V��Lk����r�hattemptshdurationdPT0SangCPUTimefPT0.1SpCPUDeviationTimedPT0SffailAt�dtypefNoFail���jjobsFailed��mjobsRemaininggCPUTimefPT0.1SpCPUDeviationTimedPT0SffailAt�dtypefNoFail��greplyToxAakka://WorkStealSpec@127.0.0.1:25255/system/testProbe-1#981770887�"; line: -1, column: 13] (through reference chain: concurrency.Consumer$ProducerState["state"]), took 1.977 sec

So I encoded a Jackson de-serializer as follows:

case class AkkaAddressOut() extends KeyDeserializer {
  override def deserializeKey(key: String, ctxt: DeserializationContext): Address = {
    AddressFromURIString(key)
  }
}

case object MyAkkaJacksonModule extends SimpleModule {
    addKeyDeserializer( classOf[Address], AkkaAddressOut() )
}

If I test directly in Jackson so:

    val tstate = TestState(1, 100.millis, 0.millis, NoFail())

    val cborTJ1: Array[Byte] = mapper.writeValueAsBytes(tstate)
    val tj1p  = mapper.readValue(cborTJ1, classOf[TestState])
    assertEquals("Same state (7)", ntstate, tj1p)

This works correctly. So I can confirm its the Map that is the problem. Now here is the issue, how do I add this module via the configuration file? The following attempt does not work:

akka.serialization.jackson {
    jackson-modules += "concurrency.MyAkkaJacksonModule"
} 

What is more intriguing is that I have found:

That leads me to:

So I assume that the associated de-serializer should already be available. What is more this is part of the internal API so I do not have access to it.

EDIT: The problem here is that we need a KeyDeserializer which os not what is in the AddressModule. Maybe this should be added to all Akka serializers/deserializers?

Appreciate any pointers as I have been wrestling with this for more than a day.

TIA

3 posts - 1 participant

Read full topic

Error while saving snapshot: (persistence_id, sequence_number) already exists

$
0
0

Hi, folks , I am getting the below error sometimes:
Detail: Key (persistence_id, sequence_number)=(MEMBERSHIP-d8ec1971-f095-43d2-a69f-39772463fd90, 43) already exists.

I am using postgres as database with classic actors

I found the below issues on github, but could not find a fix in those issues:
SnapShot Issue
Journal issue

I am not getting issue while saving into journal, it is only the snapshots which are not getting saved intermittently. Sometimes they get saved after throwing the above error , sometimes they are not saved. This can be problematic as some entries in the journal gets replayed, which is not desirable.
In this
Comment
Please, help me out.

Thanks.

1 post - 1 participant

Read full topic

Akka-Cluster: "Failed to persist event" =>"Retry request for shard"

$
0
0

Hi everyone,

we are using Akka-Cluster-Sharding with the following components

akka: 2.5.31
scala: 2.11
akka-persistence-cassandra: 0.102

We got an temporary perstistence issue after a GC pause on one of the cassandra instances.

Failed to persist event type [akka.cluster.sharding.Shard$EntityStopped] with sequence number [96688] for persistenceId [/sharding/REGIONShard/3684].

The nodes getting the error happend are logging this every few seconds:

<REGION>: Retry request for shard [3684] homes from coordinator at [Actor[akka://systemname/system/sharding/REGIONCoordinator/singleton/coordinator#-192485395]]. [232] buffered messages.

Two nodes where affected. On one node the log message went away after 14 hours. After restarting the other node (containing the shard coordination actor) the log messages dispeared, too.

Expected: The affected Shard actors should be restarted after a while.

Actual: The Shard could not be reached anymore.

I would be grateful for help.

Thanks in advance
Thomas

1 post - 1 participant

Read full topic

Typed actor references from Receptionist

$
0
0

I’m using akka 2.5.21, in Java.

After registering the actors (and also spawning them) to a Receptionist I tried to look them up in another class with Receptionist.Find message.

For this I created a temp actor with Receptionist.Listing behavior and invoked Receptionist.Find message, like this context.getSystem().receptionist().tell(Receptionist.find(myLookupServiceKey, this));

But the on the Receptionist.Listing response from Receptionist when I do .getServiceInstances(myLookupServiceKey) I get an empty set.

This seems like a simple way to find references to typed actor previously spawned elsewhere in the system, but looks a dead end :pensive:.

Appreciate any help.

2 posts - 1 participant

Read full topic

Akka 2.6.9 Artery Implementation listening on default port always i.e. 25502

$
0
0

I am using Akka 2.6.9 version in Java project. Project consist of multiple modules having port 2551 for 1st module and 2552 port for 2nd module with a common hostname(localaddress) and fetching the values dynamically like below in application.conf

  1. akka {
  2. actor {
  3. provider = remote
  4. }
  5. remote {
  6. artery {
  7. enabled = on
  8. canonical.hostname = ${hostname}
  9. canonical.port = ${port}
  10. }
  11. }
  12. }
    Logs:
    [ArteryTcpTransport (akka://sys)] Remoting started with transport [Artery tcp]; listening on address [akka://sys@127.0.0.0.1:25520] with UID [6678542467887787]

Problem: On starting both the modules it is always listening on the port 25520 not taking 2551 or 2552. Because of this One module starts fine but I am getting address already in use Exception for the other module.

Can anyone please help?

3 posts - 2 participants

Read full topic

Slick custom profile

$
0
0

Hello!

Is there somewhere an example on how a Slick custom profile should look like ?
Context: I want to use streaming with Slick/Alpakka with Dremio. It’s a little bit of a weird system (they don’t publish the JDBC driver, by example, so you have to download it and provide it locally), but works pretty nice in certain cases, like replacement for Presto in AWS with data in S3.
I got it running with Doobie-> FS2-> Akka streams, but I would would love to have a Akka-only solution. And that implies, to my current understanding, writing a custom profile, generic JDBC has been removed. Or ?
Thanks!

1 post - 1 participant

Read full topic


Must EventSourcedBehavior.emptyState() return a new object?

$
0
0

Hello all,

I’m new to this forum. Greetings!

I’m using EventSourcedBehavior in Java.
When implementing the emptyState() method, does the method body need to create a new instance of the state, or is it ok to pass in the initial state as constructor parameter to EventSourcedBehavior?

1 post - 1 participant

Read full topic

Akka http parameter optional dsl error

$
0
0

I have a route like /test?format=xx
and parameter format is optional

in scala, I wrote:

path("test") {
    parameters("format".optional) {format =>
      get {
        complete(...)
      }
    }

But I got the following error:
value optional is not a member of String
parameters(“format”.optional) {format =>

I already imported
import akka.http.scaladsl.server.{Directive0, Directives}

and
import Directives._

what am I missing?

Thanks.

6 posts - 2 participants

Read full topic

Akka Persistence Cassandra - High RU/s on tag_views table

$
0
0

I’m currently using Akka Persistence w/ the Datastax Cassandra plugin against CosmosDB. I also leverage Akka Persistence Query to create a projection from a Cassandra Read Journal. (see below)

The thing is, running our projections with no new events coming in, I’m seeing ~186 RU/s (approximately, requests/second) against our DB on the akka.tag_views table when the projection is running. I’m running 12 instances of a projection. My tags are “aggregate-slice-{1,12}” naturally. This load seems incredibly high and it feels like the DB is extremely busy. How do I configure it to do, for example 1 read per second? This seems a lot more reasonable…

How do I stop akka persistence query from sending so many requests/s? Am I running too many projections? Is my eventual consistency too low? Am I missing some unknown config? Is it backtracking too much for some reason? My config is provided below, I’ve played with some numbers but nothing seems to help “that” much.

Edit: It appears to be the high-frequency backtracking interval that’s causing a ruckus.

cassandra {
  events-by-tag {
    bucket-size = "Day"
    eventual-consistency-delay = 200ms # i've tinkered with this from 200ms to 5s
    flush-interval = 50ms
    pubsub-notification = on
    first-time-bucket = "20201102T00:00"
    gc-grace-seconds = 0
  }

  query {
    refresh-interval = 2s
  }
    SourceProvider<Offset, EventEnvelope<Message>> sourceProvider = EventSourcedProvider
        .eventsByTag(
            system,
            CassandraReadJournal.Identifier(),
            tag
        );

    return CassandraProjection.atLeastOnce(
        ProjectionId.of(PROJECTION_NAME, tag),
        sourceProvider,
        new CfsProjectionHandler(system, tag, producer)
    );

1 post - 1 participant

Read full topic

Akka design advice

$
0
0

Hi everyone,

I am very new to Akka and therefore an absolute beginner. I am trying get more familiar with it by writing a small personal project with Akka and so I am wondering how to do it “the right way”.

So the basic idea is to build an app that crawls some data. So for the crawling part I built three Actors:

  1. ProxyActor
    This actor is instantiated everytime a new proxy comes up. This actor maintains the state of the proxy it holds and checks frequently if the proxy is still alive.

  2. ProxiesActor
    This actor checks for new proxies and spawns new ProxyActor’s accordingly. This actor is meant to be a singleton within the Actorsystem and may be called to obtain an alive Proxy (by querying all ProxyActor’s with tail chopping).

  3. CrawlerActor
    This actor is instantiated by any actor who needs to crawl a website. This actor needs access to an alive proxy and therefore needs to talk to ProxiesActor.

Unfortunetly the ProxiesActor/ProxyActor are spawned under a dedicated branch (ActorSystem -> ProxiesActor(1) -> ProxyActor (N)) and the CrawlerActor may be spawned on other branches by whoever actor needs it.

So the point where i am stuck is how to obtain a ProxiesActor instance within every CrawlerActor the right way. The only thing i found to talk to actors outside your branch is the Receptionist-Pattern. Is this the way to go here or do I miss something that may be simpler or better in the context of modelling actors?

If the Receptionist-Pattern is the right choice, I am wondering if its the only way and how it is meant to be used. Do I understand it correctly that it is the only correct way to obtain an ProxiesActor instance by subscribing to the Receptionist (as CrawlerActor) and swap the internal reference to the ProxiesActor every time I get an update from the Receptionist? I was wondering why there is no mechanism to register for specific actor events in this case (like Created or Removed) but only a simple query like servicesWereAddedOrRemoved, which tells me nothing about the concrete actor referenced by getAllServiceInstances.

Cheers,
Aleks

1 post - 1 participant

Read full topic

Akka 2.6.9 -> Message Serialization failing with Artery and Java 8

$
0
0

Sending message remotely from one Node1 to other remote Node2 getting below error:
Encoder[(akka://sys)] Failed to serialize message [ActorSelection(Class RemoteMessage)].
RemoteMessage class implements Serializable

Which Serializer and Serialization-binding to add in application.conf

Can anyone help please!

2 posts - 2 participants

Read full topic

Viewing all 1359 articles
Browse latest View live