akka cluster + kryo

178 views
Skip to first unread message

Muthu Jayakumar

unread,
Aug 28, 2017, 12:31:51 PM8/28/17
to Akka User List
Hello there,

I am building a micro-service that uses akka-cluster. I am running into an issue with serialization. I am using akka 2.4.16 and scala 2.11. 
These warnings have started to come when I switched from default java-serialization to kryo. I am using "com.github.romix.akka:akka-kryo-serialization_211:0.4.2" of akka-kryo and have added the following into the config...

kryo  {
type = "graph"
idstrategy = "default"
resolve-subclasses = true
kryo-custom-serializer-init = "com.wd.perf.scheduler.swh.utils.KryoInit"
}
serializers {
akka-cluster = "akka.cluster.protobuf.ClusterMessageSerializer"
java = "akka.serialization.JavaSerializer"
kryo = "com.romix.akka.serialization.kryo.KryoSerializer"
//proto = "akka.remote.serialization.ProtobufSerializer"
}
serialization-bindings {
"akka.cluster.ClusterMessage" = akka-cluster
//"akka.cluster.routing.ClusterRouterPool" = akka-cluster

"java.io.Serializable" = none

"java.lang.String" = kryo
"java.lang.Boolean" = kryo

//"com.google.protobuf.Message" = proto
"scala.Product" = kryo
"akka.actor.ActorRef" = kryo
"scala.collection.immutable.TreeMap" = kryo
"[Lscala.collection.immutable.TreeMap;" = kryo
"scala.collection.mutable.HashMap" = kryo
"[Lscala.collection.mutable.HashMap;" = kryo
"scala.collection.immutable.HashMap" = kryo
"[Lscala.collection.immutable.HashMap;" = kryo
"scala.collection.mutable.AnyRefMap" = kryo
"[Lscala.collection.mutable.AnyRefMap;" = kryo
"scala.collection.immutable.LongMap" = kryo
"[Lscala.collection.immutable.LongMap;" = kryo
"scala.collection.mutable.LongMap" = kryo
"[Lscala.collection.mutable.LongMap;" = kryo
"scala.collection.immutable.HashSet" = kryo
"[Lscala.collection.immutable.HashSet;" = kryo
"scala.collection.immutable.TreeSet" = kryo
"[Lscala.collection.immutable.TreeSet;" = kryo
"scala.collection.immutable.BitSet" = kryo
"[Lscala.collection.immutable.BitSet;" = kryo
"scala.collection.mutable.HashSet" = kryo
"[Lscala.collection.mutable.HashSet;" = kryo
"scala.collection.mutable.TreeSet" = kryo
"[Lscala.collection.mutable.TreeSet;" = kryo
"scala.collection.mutable.BitSet" = kryo
"[Lscala.collection.mutable.BitSet;" = kryo
"scala.collection.immutable.Vector" = kryo
"[Lscala.collection.immutable.Vector;" = kryo
"[Ljava.lang.Object;" = kryo
"[[I" = kryo
}
serialization-identifiers {
"akka.cluster.protobuf.ClusterMessageSerializer" = 5
}

I could only get it past errors to the following warnings, after I had added "akka-cluster" in the application.conf (which I copied from reference.conf of akka-cluster). 


[WARN] [SECURITY][08/28/2017 09:19:03.286] [sftp-scheduler-akka.remote.default-remote-dispatcher-14] [akka.serialization.Serialization(akka://sftp-scheduler)] Multiple serializers found for class akka.cluster.InternalClusterAction$InitJoin$, choosing first: Vector((interface scala.Product,com.romix.akka.serialization.kryo.KryoSerializer@40d4d844), (interface akka.cluster.ClusterMessage,akka.cluster.protobuf.ClusterMessageSerializer@36ccff98))
[WARN] [SECURITY][08/28/2017 09:19:03.355] [sftp-scheduler-akka.remote.default-remote-dispatcher-15] [akka.serialization.Serialization(akka://sftp-scheduler)] Multiple serializers found for class akka.cluster.InternalClusterAction$Join, choosing first: Vector((interface scala.Product,com.romix.akka.serialization.kryo.KryoSerializer@40d4d844), (interface akka.cluster.ClusterMessage,akka.cluster.protobuf.ClusterMessageSerializer@36ccff98))
[WARN] [SECURITY][08/28/2017 09:19:03.369] [sftp-scheduler-akka.remote.default-remote-dispatcher-15] [akka.serialization.Serialization(akka://sftp-scheduler)] Multiple serializers found for class akka.cluster.ClusterHeartbeatSender$HeartbeatRsp, choosing first: Vector((interface scala.Product,com.romix.akka.serialization.kryo.KryoSerializer@40d4d844), (interface akka.cluster.ClusterMessage,akka.cluster.protobuf.ClusterMessageSerializer@36ccff98))

Also, I wonder if I may be able to use Remoting-Artery in-place of netty while using clustering?

Please advice on what could be the next steps.

Thanks,
Muthu

Konrad “ktoso” Malawski

unread,
Aug 28, 2017, 9:35:49 PM8/28/17
to akka...@googlegroups.com, Muthu Jayakumar
I would not encourage setting scala.Product or java.lang.Object as kryo serialized - pick specific classes (this is also for security reasons actually).
Or create a marker type that you’d include in your messages that are to be serialized using kryo and use that.

Sure you can use Artery if you want to, read it’s docs about how to configure http://doc.akka.io/docs/akka/current/scala/remoting-artery.html

PS: I’d recommend upgrading to 2.5.x, it’s fully binary compatible with 2.4.x so it will be very simple and it includes many new features and hardening updates in Artery specifically.


Konrad `kto.so` Malawski
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Muthu Jayakumar

unread,
Aug 29, 2017, 12:32:01 AM8/29/17
to Akka User List, babl...@gmail.com
Thanks for the great tip. Now my config contains the following. And the warning messages disappeared. 

serialization-bindings {

"java.io.Serializable" = none

"java.lang.String" = kryo
"java.lang.Boolean" = kryo

  //All messages that are sent around in the application.
"com.mypackage.MyMarkerTrait" = kryo

"scala.collection.immutable.$colon$colon" = kryo

}

Also upgrade to 2.5.x has been stable with most of the test cases so far.

Thanks a bunch Konrad!

Thanks,
Muthu
Reply all
Reply to author
Forward
0 new messages