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

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

 

 

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

IPC通道

 

TCP通道:

 

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

 

Tcp服务器端代码:

 

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

 

IPC服务器端代码

 

 

 

ContractedBlock.gif ExpandedBlockStart.gif Code
       private void Form1_Load(object sender, EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
{
            BinaryServerFormatterSinkProvider sfsp 
= new BinaryServerFormatterSinkProvider();
            sfsp.TypeFilterLevel 
= TypeFilterLevel.Full;
            Hashtable props 
= new Hashtable();
            props[
"portName"= "Chater";
            props[
"name"= "ipc";
            props[
"authorizedGroup"= "Everyone";

            IpcChannel channel 
= new IpcChannel(props, null, sfsp);
            ChannelServices.RegisterChannel(channel, 
false);

            sayHello 
= new SayHello();
            RemotingServices.Marshal(sayHello, 
"SayHello");
            sayHello.ConnectedEvent 
+= new DataDelegate.Connected(sayHello_ConnectedEvent);
            sayHello.DisConnectedEvent 
+= new DataDelegate.DisConnected(sayHello_DisConnectedEvent);
        }

远程代理类部分代码,

  

 

 

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/nevermad/archive/2009/11/16/1603752.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值