Using ByteString(s) with Remote Actors

149 views
Skip to first unread message

Oliver Schulz

unread,
Mar 3, 2012, 3:38:05 PM3/3/12
to akka...@googlegroups.com
Hi,

is it OK to exchange ByteString(s) over the network
with remote Actors? I just ask because the ByteString
classes don't seem to implement Serializable.


Cheers,

Oliver

√iktor Ҡlang

unread,
Mar 3, 2012, 3:43:07 PM3/3/12
to akka...@googlegroups.com

Hi,

Just create a Serializer for it and add it to your akka config.

Cheers,
V

--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/E_iV77EAIRMJ.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

Jonas Bonér

unread,
Mar 3, 2012, 3:43:42 PM3/3/12
to akka...@googlegroups.com
Can't you do this?

val bytes = byteString1.toArray
... // send bytes over the wire
val buffer2 = ByteString(bytes)

> --
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/akka-user/-/E_iV77EAIRMJ.
> To post to this group, send email to akka...@googlegroups.com.
> To unsubscribe from this group, send email to
> akka-user+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/akka-user?hl=en.

--
Jonas Bonér
CTO
Typesafe - The software stack for applications that scale
Phone: +46 733 777 123
Twitter: @jboner

√iktor Ҡlang

unread,
Mar 3, 2012, 3:46:07 PM3/3/12
to akka...@googlegroups.com

No, don't do that manually, create a Serializer.

Jonas Bonér

unread,
Mar 3, 2012, 3:50:08 PM3/3/12
to akka...@googlegroups.com
2012/3/3 √iktor Ҡlang <viktor...@gmail.com>:

> No, don't do that manually, create a Serializer.

Sure that is best. I was just asking if he had missed that you could
marshal/demarshal bytestrings to byte arrays

√iktor Ҡlang

unread,
Mar 3, 2012, 4:11:24 PM3/3/12
to akka...@googlegroups.com
On Sat, Mar 3, 2012 at 9:50 PM, Jonas Bonér <jo...@jonasboner.com> wrote:
2012/3/3 √iktor Ҡlang <viktor...@gmail.com>:
> No, don't do that manually, create a Serializer.

Sure that is best. I was just asking if he had missed that you could
marshal/demarshal bytestrings to byte arrays

Good point



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: @viktorklang

Oliver Schulz

unread,
Mar 3, 2012, 4:50:04 PM3/3/12
to akka...@googlegroups.com
Hi,


Can't you do this?

val bytes = byteString1.toArray

> No, don't do that manually, create a Serializer.

Sure that is best. I was just asking if he had missed that you could
marshal/demarshal bytestrings to byte arrays

I know about ByteString.toArray, but I since Arrays aren't immutable,
I don't want to use them in messages between Actors.
Also, if I use ByteString between local actors, the "toArray" will
result in a copy, which will cost performance and memory.
Naturally I'd the possible remoting to be transparent to the
actors, so I can't use ByteString locally and Array remotely.

Concerning the custom serializer - I was really hoping to avoid
the additional complexity ... :-)
Also, I was planning to use ByteString inside other immutable
message objects (case-class instances). I'd then have to make
custom serializers for all of them, too, right?

√iktor Ҡlang

unread,
Mar 3, 2012, 4:53:24 PM3/3/12
to akka...@googlegroups.com
On Sat, Mar 3, 2012 at 10:50 PM, Oliver Schulz <oliver...@tu-dortmund.de> wrote:
Hi,


Can't you do this?

val bytes = byteString1.toArray

> No, don't do that manually, create a Serializer.

Sure that is best. I was just asking if he had missed that you could
marshal/demarshal bytestrings to byte arrays

I know about ByteString.toArray, but I since Arrays aren't immutable,
I don't want to use them in messages between Actors.
Also, if I use ByteString between local actors, the "toArray" will
result in a copy, which will cost performance and memory.
Naturally I'd the possible remoting to be transparent to the
actors, so I can't use ByteString locally and Array remotely.

Concerning the custom serializer - I was really hoping to avoid
the additional complexity ... :-)

Complexity? It's dead simple, and is for config only, so it won't impact your user-land code at all.
 
Also, I was planning to use ByteString inside other immutable
message objects (case-class instances). I'd then have to make
custom serializers for all of them, too, right?

You have to do that anyway, unless you're planning on using Java Serialization for Remoting, which usually is terribly non-performant.

Cheers,
 

--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/uyacsGxD4x0J.

To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

Oliver Schulz

unread,
Mar 3, 2012, 4:59:47 PM3/3/12
to akka...@googlegroups.com
You have to do that anyway, unless you're planning on using Java Serialization for Remoting, which usually is terribly non-performant.

Uh, honestly ... I was planning to do exactly that. :-)
Is it really that bad? My remote messages would mostly be big chunks of
data (Byte, Int, Double), not very deep and complex object structures ...

Thanks for the help!

Oli

√iktor Ҡlang

unread,
Mar 3, 2012, 5:03:14 PM3/3/12
to akka...@googlegroups.com
It's rather bloated, yes.

Cheers,
 

Thanks for the help!

Oli

--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/h9GGuSmB4isJ.

To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

Oliver Schulz

unread,
Mar 3, 2012, 5:14:51 PM3/3/12
to akka...@googlegroups.com
Ok, I looked a bit more closely at ByteString - should have don't that before,
sorry!

I agree, default serialization is probably a bad idea for ByteString1 and ByteStrings,
because they're likely to be non-compact.

What I really like about ByteString, is that it is a high-performance, immutable
array-like Byte storage. Of course you can use a Scala WrappedArray, but
performance is bad, in my experience, because it's not specialized.

So, an idea for the future - how about a

  final case class CompactByteString (private val bytes: Array[Byte]) extends ByteString

as a result of ByteString.compact? It would serve as a clearly labled, compact, fast and
immutable Byte storage. Any operation on it would, of course, expand it to
an instance of ByteString1 or ByteStrings. As a case class, it would, of course, also
have a default serializer.

Do you like it?

√iktor Ҡlang

unread,
Mar 3, 2012, 5:22:54 PM3/3/12
to akka...@googlegroups.com
Open a Pull Request and I'll review it ;-)

Cheers,
 


--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/1W7soqzS59kJ.

To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

Oliver Schulz

unread,
Mar 3, 2012, 5:33:19 PM3/3/12
to akka...@googlegroups.com
Open a Pull Request and I'll review it ;-)

Ok. :-)


Concerning the custom serializers (I guess i really should look into that), uhm
I hesitate to ask, cause you'll probably tell me that I shouldn't do it, but ... ;-)

Do custom serizalizers work with remote typed Actors?
Or, in other words will the serializers specified in the config be used
for the parameters in a MethodCall object?
Or can I always specify a custom serializer even for objects nested into
other objects? Sorry, am a bit new to that stuff.

√iktor Ҡlang

unread,
Mar 3, 2012, 5:37:03 PM3/3/12
to akka...@googlegroups.com
On Sat, Mar 3, 2012 at 11:33 PM, Oliver Schulz <oliver...@tu-dortmund.de> wrote:
Open a Pull Request and I'll review it ;-)

Ok. :-)


Concerning the custom serializers (I guess i really should look into that), uhm
I hesitate to ask, cause you'll probably tell me that I shouldn't do it, but ... ;-)

Do custom serizalizers work with remote typed Actors?
Or, in other words will the serializers specified in the config be used
for the parameters in a MethodCall object?

 
Or can I always specify a custom serializer even for objects nested into
other objects? Sorry, am a bit new to that stuff.

If the serializer of an object delegates to Serialization, then yes.

Cheers,
 


--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/AcF61xQWEPsJ.

To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

Oliver Schulz

unread,
Mar 3, 2012, 8:24:18 PM3/3/12
to akka...@googlegroups.com
Open a Pull Request and I'll review it ;-)

Ok, I whipped something up ...

    https://github.com/oschulz/akka/tree/CompactByteString


Jeffrey Aguilera

unread,
Jul 30, 2014, 5:22:11 PM7/30/14
to akka...@googlegroups.com
What if you don't control the code? What if you're trying to forward an HttpRequest to another actor that happens to be remote?  HttpData uses ByteString, so you're dead and location transparency is violated.  

Roland Kuhn

unread,
Aug 12, 2014, 9:30:42 AM8/12/14
to akka-user
Hi Jeffrey,

ByteStrings can of course trivially be serialized, but that has nothing to do with implementing Serializable (which is strictly the worst possible choice available for this job). Fortunately serialization within Akka is fully configurable and customizable, so you can just register a schema for ByteString and the issue is solved.

Regards,

Roland

--
>>>>>>>>>> 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.



Dr. Roland Kuhn
Akka Tech Lead
Typesafe – Reactive apps on the JVM.
twitter: @rolandkuhn


Reply all
Reply to author
Forward
0 new messages