We are using WCF for transferring data from a server application to several clients. Actually, for most of the traffic, client and server are running on the same machine, so I would expect the transfer to be really fast.
However, when transferring large arrays (16-bit grayscale images), it takes several seconds until the data is transferred. For a 16 MB image, it takes around 3-5 seconds!
Initially, we were using ushort arrays because it is the most suitable data type for storing 16-bit grayscale image data. However, this was extremely slow: something around 20-25 seconds for 16 MB. When we copy the data to a byte array before serialization using Buffer.BlockCopy, it is reduced to 3-5 seconds for some reason. However, 3-5 seconds for transferring 16 MB from one application to another running on the same machine still seems far too long to me!
Therefore, my question is: How can we improve the performance for such a scenario?
I already investigated protobuf-net from Marc Gravell, but I am uncertain whether it would help in this case… Any experiences or other suggestions?
Here is the source code of one of our data classes (containing the image data):
[DataContract(IsReference = true)]
public class ImageData
{
private ushort[] m_pixelData;
public ushort[] PixelData
{
get
{
return m_pixelData;
}
set
{
m_pixelData = value;
OnPropertyChanged("PixelData");
}
}
[DataMember]
public override byte[] FileData
{
get
{
if (this.PixelData == null)
{
return null;
}
return ListHelper.ConvertToByteArray(this.PixelData);
}
set
{
if (value == null)
{
this.PixelData = null;
return;
}
this.PixelData = ListHelper.ConvertToUshortArray(value);
}
}
}
Note that only the FileData property is marked as [DataMember], so that the PixelData property is not serialized!
Here are the relevant parts of the server’s app.config:
<system.serviceModel>
<services>
<service name="Services.ImageDataService" behaviorConfiguration="ServicesBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8008/ImageDataService" />
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" bindingConfiguration="NetTcpBindingLargeFileTransfer" contract="Services.IImageDataService" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServicesBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding
name="NetTcpBindingLargeFileTransfer"
openTimeout="00:01:00" closeTimeout="00:01:00" receiveTimeout="infinite" sendTimeout="infinite"
transactionFlow="false" transactionProtocol="OleTransactions"
transferMode="Buffered" hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="2097152" maxBufferSize="1073741824" maxConnections="10" maxReceivedMessageSize="1073741824">
<readerQuotas
maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="infinite" enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
And the client’s app.config:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding
name="NetTcpBindingLargeFileTransfer"
openTimeout="00:01:00" closeTimeout="00:01:00" receiveTimeout="infinite" sendTimeout="00:10:00"
transactionFlow="false" transactionProtocol="OleTransactions"
transferMode="Buffered" hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="2097152" maxBufferSize="1073741824" maxConnections="10" maxReceivedMessageSize="1073741824">
<readerQuotas
maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="infinite" enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint
address="net.tcp://localhost:8008/ImageDataService"
binding="netTcpBinding"
bindingConfiguration="NetTcpBindingLargeFileTransfer"
contract="Services.IImageDataService"
name="Services.IImageDataService"
behaviorConfiguration="ServicesBehavior" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="ServicesBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"></dataContractSerializer>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
On the same machine try named pipes.
Choosing a Transport