【发布时间】:2015-04-22 14:47:52
【问题描述】:
我正在尝试设置一些测试来了解 WCF 服务的工作方式。对于 basicHttp、netTcp、netPipe 绑定,我有类似的代码调用带有这些绑定的 WCF 服务。
using (_log = new StreamWriter(@"C:\TestRunnerLog.txt", true))
{
var methodCallInformation = new MethodCallInformation { Method = NetPipeServiceCall, TotalTimeTakenForAllMethodCalls = new TimeSpan(), TotalNumberOfTimesMethodCalled = 0, TimesErrored = 0 };
for (var i = 0; i < 25000; i++)
{
try
{
var stopwatch = new Stopwatch();
stopwatch.Start();
using(var channelFactory = new ChannelFactory<IChatHub>(new NetTcpBinding { Security = new NetTcpSecurity { Mode = SecurityMode.None } }, "net.tcp://localhost/test/test.svc"))
{
var channel = channelFactory.CreateChannel();
await channel.GetPeople();
}
stopwatch.Stop();
return stopwatch.Elapsed;
methodCallInformation.TotalTimeTakenForAllMethodCalls += stopwatch.Elapsed;
}
catch (Exception e)
{
methodCallInformation.TimesErrored++;
}
methodCallInformation.TotalNumberOfTimesMethodCalled++;
}
await _log.WriteLineAsync(string.Format("net.tcp:\tTimesCalled:{0}\tTotalTime:{1}\tAverageTime:{2}\tErrors:{3}", methodCallInformation.TotalNumberOfTimesMethodCalled, methodCallInformation.TotalTimeTakenForAllMethodCalls, new TimeSpan(methodCallInformation.TotalTimeTakenForAllMethodCalls.Ticks / methodCallInformation.TotalNumberOfTimesMethodCalled), methodCallInformation.TimesErrored));
}
我对我得到的结果感到困惑。我在本地运行所有迭代,并让服务和客户端都在我的机器上本地运行。根据我的研究,netPipe 应该是最快的,其次是 netTcp,然后是 basicHttp。我的代码随机化了这些调用,而不是像上面的示例那样,每个循环只为所有迭代调用一个绑定。
----------------------------------------------------------------------------------------------
http: TimesCalled:24981 TotalTime:00:00:46.0452454 AverageTime:00:00:00.0018432 Errors:0
net.tcp: TimesCalled:25168 TotalTime:00:00:16.7776697 AverageTime:00:00:00.0006666 Errors:17593
net.pipe: TimesCalled:24786 TotalTime:00:00:50.5698790 AverageTime:00:00:00.0020402 Errors:0
我正试图弄清楚我做错了什么才能得到 net.tcp 的所有这些错误,以及为什么 net.pipe 的时间似乎如此缓慢。
这是我在服务上设置的绑定:
<bindings>
<basicHttpBinding>
<binding name="basicHttpDefaultBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" maxDepth="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
<netTcpBinding>
<binding name="netTcpDefaultBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" maxDepth="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" />
<message clientCredentialType="None" />
</security>
</binding>
</netTcpBinding>
<netNamedPipeBinding>
<binding name="netNamedPipeDefaultBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" maxDepth="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
</security>
</binding>
</netNamedPipeBinding>
</bindings>
任何帮助将不胜感激。
【问题讨论】:
-
请提供反馈。为什么投反对票?
-
你实际上并没有问过问题。
-
对不起,如果不是很明显,但我在帖子中确实有这个:我试图找出我做错了什么来获得所有这些 net.tcp 错误以及为什么net.pipe 的时间似乎很慢。补充一点。我没有正确地创建连接或处理它们吗?为什么我会看到这种行为?