我有一个简单的WCF主机和客户端在Windows中运行良好,但在Mono 2.10.8 / 9上性能极差。
WCF主机在自托管控制台应用程序中运行。 WCF客户端也是一个简单的控制台应用程序。 他们在没有任何安全性的情况下使用netTcpBinding。
这是主机app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MetadataBehavior">
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MetadataBehavior" name="EmployeeServiceLib.EmployeeService">
<clear />
<endpoint address="net.tcp://localhost:8888/EmployeeService/tcp"
binding="netTcpBinding" bindingConfiguration="ultra" name="EmployeeService"
contract="EmployeeServiceLib.IEmployeeService" listenUriMode="Explicit" />
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="ultra" transactionFlow="false" transferMode="Streamed">
<reliableSession enabled="false" />
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>
客户端app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="EmployeeService" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
transferMode="Streamed" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="65536" maxBufferSize="65536" maxConnections="10"
maxReceivedMessageSize="1048576">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8888/EmployeeService/tcp"
binding="netTcpBinding" bindingConfiguration="EmployeeService"
contract="EmployeeService.IEmployeeService" name="EmployeeService" />
</client>
</system.serviceModel>
</configuration>
WCF服务类:
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single,
AddressFilterMode = AddressFilterMode.Any)]
public class EmployeeService : IEmployeeService
{
private readonly List<Employee> m_Employees = new List<Employee>();
#region IEmployeeService Members
public void AddEmployee(Employee employee)
{
m_Employees.Add(employee);
}
// ... snipped ...
}
客户端做的是调用OperationContract 100次并对呼叫进行基准测试。
var employee = new Employee { ... };
var client = new EmployeeServiceClient("EmployeeService", "net.tcp://localhost:8888/EmployeeService/tcp");
client.Open();
Console.Write("Adding 100 employees...");
var startTime = Environment.TickCount;
for (int i = 0; i < 100; i++)
{
client.AddEmployee(employee);
}
var timeTaken = Environment.TickCount - startTime;
Console.WriteLine(" Done.");
基准测试结果:
.NET 4.0 = 62 ms
Mono 2.11.1 = 1672 ms
Debian 6中的Mono 2.10.9在VM中运行= 9632 ms(CPU使用率徘徊在1%左右)
我可以做些什么来加速Debian中Mono esp上的WCF性能?