Skip to content

Conversation

joshgarnett
Copy link
Contributor

The existing implementation of ProtobufSerializer requires RegisterFileDescriptor to be called with the file descriptor of every protobuf message that will be serialized. This adds a significant amount of boilerplate to serialize protobuf messages automatically. To work around this, I've updated the fromBinary method to lookup the MessageParser at runtime based on the type. This brings it inline with how the JVM Akka protobuf serializer works.

The existing implementation of ProtobufSerializer requires RegisterFileDescriptor to be called with the file descriptor of every protobuf message that will be serialized.  This adds a significant amount of boilerplate to serializer protobuf messages automatically.  To work around this, I've updated the fromBinary to lookup the MessageParser at runtime based on the type.  This brings it inline with how the JVM Akka protobuf serializer works.
@alexvaluyskiy
Copy link
Contributor

Have you benchmarked it?

@joshgarnett
Copy link
Contributor Author

I have not benchmarked this specific change, but benchmarks of Activator.CreateInstance with the default constructor, which we are using in this case, show that the overhead is minimal, plus we are caching the lookup, so at that point we'll only pay the cost of getting the key from the concurrent dictionary.

@joshgarnett
Copy link
Contributor Author

TryGetValue is lockfree for ConcurrentDictionary btw

@Danthar
Copy link
Member

Danthar commented Aug 28, 2017

So to be clear. What this PR aims to fix is the following.
When a user want to use protobuff for its remoting messages. This PR makes that easier. Because instead of writing a serializer that acts as a mapper between your message and the protobuff parser. You added support in the Remotings, protobuffserializer. By allowing you to register your own message descriptors so you don't have to define your own protobuff serializer implementation.

Correct ?

I would like to see a few snippets of code about how you would retrieve the serializer instance and register your own descriptors.

@joshgarnett
Copy link
Contributor Author

Correct, the idea is that if a user wants to send IMessage over the wire, the remoting protobuf serializer would automatically pick this up without any additional work from the user.

throw new ArgumentException("Need a protobuf message class to be able to serialize bytes using protobuf");
}
// MethodParser is not in the cache, look it up with reflection
IMessage msg = Activator.CreateInstance(type) as IMessage;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's clever.

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Updating CI.

@Aaronontheweb
Copy link
Member

Going to run a local ping pong once I pull this down. the NBench numbers were in the 20k range.

@Aaronontheweb
Copy link
Member

Benchmark numbers while I was running ~8 instances of Visual Studio on my machine:

ProcessorCount:                    8
ClockSpeed:                        0 MHZ
Actor Count:                       16
Messages sent/received per client: 20000  (2e4)
Is Server GC:                      True

Num clients, Total [msg], Msgs/sec, Total [ms]
         1,   20000,     42373,     472.50
         5,  100000,     44884,    2228.36
        10,  200000,     52070,    3841.58
        15,  300000,     55361,    5419.78
        20,  400000,     50814,    7872.45
        25,  500000,     52643,    9498.59

It's right on with top numbers I recorded before 1.3.0. Good to go on the perf IMHO.

@alexvaluyskiy
Copy link
Contributor

alexvaluyskiy commented Aug 29, 2017

@Aaronontheweb I'm not sure that we are talking about the same things. Because we did not have this ProtobufSerializer before 1.3.0
https://github.com/akkadotnet/akka.net/blob/v1.2.3/src/core/Akka.Remote/Serialization/ProtobufSerializer.cs

@Aaronontheweb
Copy link
Member

@alexvaluyskiy I'm talking about the work done on the 1.3.0 branch, when I added the benchmark.

@Aaronontheweb Aaronontheweb merged commit d5aecca into akkadotnet:dev Aug 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants