为什么我得到20%繁忙,机器上的IPC延迟 [英] Why do I get IPC delays on 20% busy machine

查看:131
本文介绍了为什么我得到20%繁忙,机器上的IPC延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有10个核心和运行我ClientApp 47实例它们都与MasterApp通信的单一机器上得到IPC的延迟。

我似乎得到一次严重的延迟。这是我的日志的一部分。左边的日期时间是日志的日期时间(高PERF记录仪)。内的[]的DateTime是否是邮件是MasterApp发送的时间。与@每个消息终止。

因此​​,第一个消息仅1ms的背后,但最后是71ms落后。

任何想法可能会导致这样和我可以做什么来摆脱延迟

  20141030T120401.015 [-------- * MD | USD / JPY 109.032 109.034 1000000.00 1000000.00 20141030T120401014 @]
20141030T120401.084 [-------- * MD |欧元/瑞士法郎1.20580 1.20588 3000000.00 2000000.00 20141030T120401019 @]
20141030T120401.163 [-------- * MD | USD / JPY 109.031 109.034 1000000.00 1000000.00 20141030T120401088 @ * MD |欧元/瑞士法郎1.20580 1.20588 3000000.00 1000000.00 20141030T120401092 @]

code节选:

 公共无效连接(INT端口)
    {        ip地址[] aryLocalAddr = NULL;
        串strHostName =;
        尝试
        {
            //注意:DNS查找很不错,所有,但相当费时。
            strHostName = Dns.GetHostName();
            IPHostEntry ipEntry = Dns.GetHostByName(strHostName);
            aryLocalAddr = ipEntry.AddressList;
        }
        赶上(异常前)
        {
            OutputWriteLine(错误试图让本地地址:+ ex.Message);
        }
        插座=新的Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
        socket.Blocking = FALSE;        IPEndPoint epServer =新IPEndPoint(aryLocalAddr [0],口);        socket.BeginConnect(epServer,新的AsyncCallback(ConnectCallBack),插座);    }        公共无效ConnectCallBack(IAsyncResult的AR)
        {
            Socket套接字=(插座)ar.AsyncState;
            NewConnection(插座);
        }
        公共无效NewConnection(Socket套接字)
        {
            连接MC =新的连接(插座);
            connections.Add(MC);
            // OutputWriteLine(客户+ mc.SessionID()+加入);            现在的DateTime = DateTime.Now;
            字符串intraMessage =* IDENT | + modelInitiatorApp.G.SLOTNAME;            modelInitiatorApp.SetConnected();            SendMessage函数(MC,intraMessage);            socket.BeginReceive(mc.stateObject.buffer,0,mc.stateObject.buffer.Length,SocketFlags.None,新的AsyncCallback(ReceivedCallBack),mc.stateObject);
        }        公共无效ReceivedCallBack(IAsyncResult的AR)
        {
//
            StateObject状态=(StateObject)ar.AsyncState;
            Socket套接字= state.socket;            尝试
            {
                INT读取动作= socket.EndReceive(AR);
                如果(读取动作大于0)
                {
                    state.sb.Append(Encoding.ASCII.GetString(state.buffer,0,读取动作));
                    OutputWriteLine([--------+ state.sb.ToString()+]);                    字符串[]内容= state.sb.ToString()斯普利特(@)。
                    。INT delimCount = state.sb.ToString()计数(X => X =='@');                    对于(INT D = 0; D< delimCount; d ++)
                    {
                        如果(内容并[d]!=)
                            的onMessage(州,内容[D]。);
                    }                    如果(!state.sb.ToString()的endsWith(@))
                    {
                        state.sb.Clear();
                        state.sb.Append(内容[contents.Count() - 1]);                    }
                    其他
                    {
                        state.sb.Clear();                    }                    socket.BeginReceive(state.buffer,0,state.buffer.Length,SocketFlags.None,新的AsyncCallback(ReceivedCallBack),状态);
                }
                其他
                {
                    //如果没有收到数据,那么连接可能是死
                    OutputWriteLine(客户+ state.SessionID()+断开连接);
                    socket.Shutdown(SocketShutdown.Both);
                    socket.Close();
                }
            }
            赶上(异常前)
            {
                MessageBox.Show(ex.Message,接收过程中不寻常的错误!);
            }
        }


解决方案

您不应使用日期时间进行基准测试性能,因为它是不准确的。

<一个href=\"http://blogs.msdn.com/b/ericlippert/archive/2010/04/08/$p$pcision-and-accuracy-of-datetime.aspx\" rel=\"nofollow\">http://blogs.msdn.com/b/ericlippert/archive/2010/04/08/$p$pcision-and-accuracy-of-datetime.aspx


  

如果你要问的问题是一些经营了多长时间,
  和你想要一个高precision,高精度的答案,然后使用
  秒表类。它确实有纳秒precision和准确性
  这是接近其precision。


  
  

记住,你不需要知道它是什么时候知道多少时间
  已过。这些可以完全两回事。


I am getting delays on IPC on a single machine that has 10 cores and is running 47 instances of my ClientApp which are all communicating with the MasterApp.

I appear to get severe latency on occasion. Here is part of my log. The DateTime on the left is the log DateTime(a high perf logger). The DateTimes within the [] are the times the message was sent from the MasterApp. Each message terminates with an @.

So the first message is only 1ms behind, but the last is 71ms behind.

Any ideas what might cause this and what I might do to get rid of the latency

20141030T120401.015 [--------*MD|USD/JPY 109.032 109.034 1000000.00 1000000.00 20141030T120401014@]
20141030T120401.084 [--------*MD|EUR/CHF 1.20580 1.20588 3000000.00 2000000.00 20141030T120401019@]
20141030T120401.163 [--------*MD|USD/JPY 109.031 109.034 1000000.00 1000000.00 20141030T120401088@*MD|EUR/CHF 1.20580 1.20588 3000000.00 1000000.00 20141030T120401092@]

Code excerpt:

    public void Connect(int port)
    {

        IPAddress[] aryLocalAddr = null;
        String strHostName = "";
        try
        {
            // NOTE: DNS lookups are nice and all but quite time consuming.
            strHostName = Dns.GetHostName();
            IPHostEntry ipEntry = Dns.GetHostByName(strHostName);
            aryLocalAddr = ipEntry.AddressList;
        }
        catch (Exception ex)
        {
            OutputWriteLine("Error trying to get local address: " + ex.Message);
        }


        socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        socket.Blocking = false;

        IPEndPoint epServer = new IPEndPoint(aryLocalAddr[0], port);

        socket.BeginConnect(epServer, new AsyncCallback(ConnectCallBack), socket);

    }

        public void ConnectCallBack(IAsyncResult ar)
        {
            Socket socket = (Socket)ar.AsyncState;            
            NewConnection(socket);            
        }


        public void NewConnection(Socket socket)
        {
            Connection mc = new Connection(socket);
            connections.Add(mc);
            //OutputWriteLine("Client " + mc.SessionID() + " joined");

            DateTime now = DateTime.Now;
            String intraMessage = "*IDENT|" + modelInitiatorApp.G.SLOTNAME;

            modelInitiatorApp.SetConnected();

            SendMessage(mc, intraMessage);

            socket.BeginReceive(mc.stateObject.buffer, 0, mc.stateObject.buffer.Length, SocketFlags.None, new AsyncCallback(ReceivedCallBack), mc.stateObject);
        }

        public void ReceivedCallBack(IAsyncResult ar)
        {
//
            StateObject state = (StateObject)ar.AsyncState;
            Socket socket = state.socket;

            try
            {
                int bytesRead = socket.EndReceive(ar);
                if (bytesRead > 0)
                {
                    state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));
                    OutputWriteLine("[--------"+state.sb.ToString()+"]");

                    string[] contents = state.sb.ToString().Split('@');
                    int delimCount = state.sb.ToString().Count(x => x == '@');

                    for (int d = 0; d < delimCount; d++)
                    {
                        if (contents[d] != "")
                            OnMessage(state, contents[d]);
                    }

                    if (!state.sb.ToString().EndsWith("@"))
                    {
                        state.sb.Clear();
                        state.sb.Append(contents[contents.Count() - 1]);

                    }
                    else
                    {
                        state.sb.Clear();

                    }

                    socket.BeginReceive(state.buffer, 0, state.buffer.Length, SocketFlags.None, new AsyncCallback(ReceivedCallBack), state);
                }
                else
                {
                    // If no data was received then the connection is probably dead
                    OutputWriteLine("Client " + state.SessionID() + " disconnected");
                    socket.Shutdown(SocketShutdown.Both);
                    socket.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Unusual error during Receive!");
            }
        }

解决方案

You should not use DateTime for benchmarking performance because it is not accurate.

http://blogs.msdn.com/b/ericlippert/archive/2010/04/08/precision-and-accuracy-of-datetime.aspx

If the question you want to ask is about how long some operation took, and you want a high-precision, high-accuracy answer, then use the StopWatch class. It really does have nanosecond precision and accuracy that is close to its precision.

Remember, you don’t need to know what time it is to know how much time has elapsed. Those can be two different things entirely.

这篇关于为什么我得到20%繁忙,机器上的IPC延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆