[ZZ]Remoting技术:多线程中IpcChannel的性能太逊

原文出处:http://www.cnblogs.com/nevermad/archive/2009/11/16/1603752.html

网上都说Ipc通道的速度比Tcp、http通道快,也有相关的测试文章。但我在多线程测试中发现Ipc通道比Tcp慢了差不多20多倍,测试方法是在IIS6中创建Remoting通道,用WAS压力测试工具进行测试。IIS6中Web园设置为100个进程,核心请求队列设置为4000,然后打开WAS并设置1000个线程,每个线程2个连接。点击启动。

12.jpg

11.jpg

以下是WAS运行30s后的测试结果,WAS显示时间不准确是由于截图时间没有把握好

IPC通道

13.jpg

TCP通道:

14.jpg

对比可见,IPC通道在多线程状态下比TCP通道慢的太多了。

Tcp服务器端代码:

ContractedBlock.gif ExpandedBlockStart.gif Code
None.gif        private void Form1_Load(object sender, EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            BinaryServerFormatterSinkProvider sfsp 
= new BinaryServerFormatterSinkProvider();
InBlock.gif            sfsp.TypeFilterLevel 
= TypeFilterLevel.Full;
InBlock.gif            Hashtable props 
= new Hashtable();
InBlock.gif            props[
"port"= 8086;
InBlock.gif            TcpChannel channel 
= new TcpChannel(props, null, sfsp);
InBlock.gif            ChannelServices.RegisterChannel(channel, 
false);
InBlock.gif            
//SayHello sayHello = new SayHello();
InBlock.gif
            sayHello = new SayHello();
InBlock.gif            RemotingServices.Marshal(sayHello, 
"SayHello");
InBlock.gif            sayHello.ConnectedEvent 
+= new DataDelegate.Connected(sayHello_ConnectedEvent);
InBlock.gif            sayHello.DisConnectedEvent 
+= new DataDelegate.DisConnected(sayHello_DisConnectedEvent);
ExpandedBlockEnd.gif        }

IPC服务器端代码

ContractedBlock.gif ExpandedBlockStart.gif Code
None.gif       private void Form1_Load(object sender, EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            BinaryServerFormatterSinkProvider sfsp 
= new BinaryServerFormatterSinkProvider();
InBlock.gif            sfsp.TypeFilterLevel 
= TypeFilterLevel.Full;
InBlock.gif            Hashtable props 
= new Hashtable();
InBlock.gif            props[
"portName"= "Chater";
InBlock.gif            props[
"name"= "ipc";
InBlock.gif            props[
"authorizedGroup"= "Everyone";
InBlock.gif
InBlock.gif            IpcChannel channel 
= new IpcChannel(props, null, sfsp);
InBlock.gif            ChannelServices.RegisterChannel(channel, 
false);
InBlock.gif
InBlock.gif            sayHello 
= new SayHello();
InBlock.gif            RemotingServices.Marshal(sayHello, 
"SayHello");
InBlock.gif            sayHello.ConnectedEvent 
+= new DataDelegate.Connected(sayHello_ConnectedEvent);
InBlock.gif            sayHello.DisConnectedEvent 
+= new DataDelegate.DisConnected(sayHello_DisConnectedEvent);
ExpandedBlockEnd.gif        }

None.gif

远程代理类部分代码,

  

ContractedBlock.gif ExpandedBlockStart.gif Code
        //这个数组是为了降低多线程竞争资源
        private Hashtable[] reDict = new Hashtable[MaxHashTables];


        
public void AddEventReappear(string clientId, SayEventReappear re)
        {
            Random x 
= new Random();
            
int i = x.Next(MaxHashTables);

            
lock (reDict[i].SyncRoot)

            {
                
this.reDict[i][clientId] = re;

            }
            
        }

TCP客户端代码,运行与IIS中

ContractedBlock.gif ExpandedBlockStart.gif Code
        protected void Page_Load(object sender, EventArgs e)
        {

            
string testL=new string (' ',36*8);
            SayHello sh;
            TcpChannel channel 
= null;
            
string Identity=Request.QueryString["name"]??new Random().Next(10000000).ToString();
            
if (ChannelServices.RegisteredChannels.Length == 0)
            {
                BinaryServerFormatterSinkProvider sfsp 
= new BinaryServerFormatterSinkProvider();
                sfsp.TypeFilterLevel 
= TypeFilterLevel.Full;
                Hashtable props 
= new Hashtable();
                props[
"port"= 0;
                
// props["exclusiveAddressUse"] = "false";
                
//props["authorizedGroup"] = "Everyone";
                channel = new TcpChannel(props, null, sfsp);
                ChannelServices.RegisterChannel(channel, 
false);

            }
            sh 
= (SayHello)Activator.GetObject(typeof(SayHello), "tcp://localhost:8086/SayHello");
            SayEventReappear re 
= new SayEventReappear();
            re.OnSay 
+= new SayHandler(re_OnSay);
            sh.AddEventReappear(Identity, re);
            Response.Write(testL);

                System.Threading.Thread.Sleep(
120000);

            re.OnSay 
-= new SayHandler(re_OnSay);
            sh.SubEventReappear(Identity);

        }

IPC客户端代码,运行与IIS中

IpcChannel的

ContractedBlock.gif ExpandedBlockStart.gif Code
       protected void Page_Load(object sender, EventArgs e)
        {

            
string testL=new string (' ',36*8);
            SayHello sh;
            IpcChannel channel 
= null;
            
string Identity=Request.QueryString["name"]??new Random().Next(10000000).ToString();
            
if (ChannelServices.RegisteredChannels.Length == 0)
            {
                BinaryServerFormatterSinkProvider sfsp 
= new BinaryServerFormatterSinkProvider();
                sfsp.TypeFilterLevel 
= TypeFilterLevel.Full;
                Hashtable props 
= new Hashtable();
                props[
"portName"= "ChatClient";
               props[
"authorizedGroup"= "Everyone";
                channel 
= new IpcChannel (props, null, sfsp);
                ChannelServices.RegisterChannel(channel, 
false);

            }
            sh 
= (SayHello)Activator.GetObject(typeof(SayHello), "ipc://Chater/SayHello");
            SayEventReappear re 
= new SayEventReappear();
            re.OnSay 
+= new SayHandler(re_OnSay);
            sh.AddEventReappear(Identity, re);
            Response.Write(testL);

                System.Threading.Thread.Sleep(
120000);

            re.OnSay 
-= new SayHandler(re_OnSay);
            sh.SubEventReappear(Identity);

        }

转载于:https://www.cnblogs.com/wk23415/archive/2011/03/30/2000229.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值