C# – Send large byte arrays between AppDomains in the same process

cnetnetworkingremotingwindows

I'm building a network server and starting a lot of AppDomains on the server to which requests are routed. What will be the fastest way to send off a request payload to one of the AppDomains for processing?

  1. Read in the payload from the socket into a byte array and marshal it.
  2. Marshal the network stream (inherits from MarshalByRef) to the AppDomain.
  3. Read the payload. Decode it into objects. Marshal the decoded objects.
  4. Use named pipes to transfer the byte array.
  5. Use loopback sockets.
  6. Maybe there is a way to marshal the actual socket connection?

The decoding mostly creates immutable objects that are used to determine how to fulfill the clients request and the AppDomain then creates a response and marshals it back to the host AppDomain which sends it back through the socket.

The method should prefer less memory over less CPU.

WCF is not an option.

Best Answer

TCP binary remoting is certainly fast, I do not how much faster it is than raw sockets which is probably the fastest, but a royal PIA.

I have run 1500 - 2000 req per second in production using HTTP binary remoting between two boxes. On the same box you should have much high performance using TCP or a name pipes channel, depending in the CPU cycles it takes to process the data.