【发布时间】:2011-07-10 09:41:00
【问题描述】:
我有 WCF 服务。我已经用 basichttp 绑定和 tcp 绑定做了一些测试。
在控制台客户端中,我创建了数百个线程并使用 tcp 和 http 绑定访问服务。原来 TCP 比 http 快两倍。
然后我创建了一个在 IIS 上运行并访问服务的 Web 客户端。 原来http比TCP快。
这是怎么发生的? TCP不应该比basichttp快吗?代码如下所示。类似。
stopwatch start here
Thread[] ts = new Thread[100];
for(int i= 0; i< ts.lenght;i++){
ts[i] = new Thread(foo); // replace with bar for the second test.
ts[i].start();
}
for(int i 0;i< ts.lenght;i++){
ts[i].join();
}
stopwatch stop here.
public static void foo(){
MyServiceClient myclient = new MyServiceClient("netTcpBinding");
myclient.GetResult(1);
}
public static void bar(){
MyServiceClient myclient = new MyServiceClient("basicHttpBinding");
myclient.GetResult(1);
}
【问题讨论】:
-
这取决于你的测试代码。
-
您的第二个测试是否与服务在同一台机器上运行?
-
它们是相同的代码。我只是使用两种配置调用一种服务方法。唯一的区别是绑定。
-
是的,两者都在同一台机器上运行。唯一的区别是有约束力。例如:客户端 c = new Client("bindingTCPorHTTP"); c.invokeMethod();
-
你在 IIS 端有缓存吗?
标签: c# .net wcf performance iis