Thanks for all the suggestions, folks. I am using case class (enclosing the 
real data) for all my messages and I am trying to use protobuf to serialize 
my message instead of java serializer. Based on your comment, the case 
class(not the data inside it) will determine the serializer to use. 
However, it's difficult to make case class serializable by protobuf unless 
each of the case class (a lot!) message be generated by the protobuf 
compiler.

I am thinking about the following trade-off plan: still using java 
serializer, but for the actual data structures (not many) which are 
contained in the case class, provide customized readObject/writeObject 
method for the java serliazer, and inside those methods use purely profobuf 
logic to convert the obj to binary and from binary. What do you think of 
this plan? Since case class is really thin and the most heavy part of the 
message is the data structure, would this still give me most of the benefit 
in terms of message size and speed?

Thanks.

On Tuesday, September 6, 2016 at 9:39:51 AM UTC-4, Konrad Malawski wrote:
>
> Hi there,
> not quite. If you use java serialization of X that contains Y things, then 
> Java serialization serializes the entire thing.
> For example, if you serialized a List using java serialization, it also 
> will serialize the things inside the list - that's how it works.
>
> Akka always wraps your serialized message in a binary (protobuf serialized 
> nowadays) envelope, the envelope contains your message,
> serialized using whichever serializer was configured for it. 
>
> So with the List + Java example you'll end up with a java serialized list 
> of java serialized items, within an akka envelope.
>
> Tips:
> a) Don't send around raw lists anyway, define proper message types - it's 
> your message protocol, take good care of it. 
> b) Define a good serializer for your messages. You can start out with 
> akka-kryo-serialization, it's simple to set up, pretty fast etc.
>
> -- 
> Konrad `ktoso` Malawski
> Akka <http://akka.io> @ Lightbend <http://lightbend.com>
>
> On 6 September 2016 at 08:33:36, Viktor Klang ([email protected] 
> <javascript:>) wrote:
>
> Akka encloses the binary data in an envelope to track message size. It is 
> recommended to send small messages for the same reason it is recommended to 
> to send huge packets through normal post boxes. :-)
>
> --
> Cheers,
> √
>
> On Sep 6, 2016 08:00, "Wei" <[email protected] <javascript:>> wrote:
>
>> Hello, 
>>
>> I am trying to write a custom serializer in akka. While deriving from the 
>> Serializer trait and implementing the fromBinary(byte, clazz) methods, I 
>> started to think of a questions: does the byte given to this method always 
>> one whole message? Could it be partial or multiple message in the byte? In 
>> other words, how does akka determine message boundary when getting the byte 
>> from the network stream? 
>>
>> Thanks a lot.
>>
>> --
>> >>>>>>>>>> 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 [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/akka-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> >>>>>>>>>> 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 [email protected] <javascript:>.
> To post to this group, send email to [email protected] 
> <javascript:>.
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to