• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            網(wǎng)絡(luò)服務(wù)器軟件開發(fā)/中間件開發(fā),關(guān)注ACE/ICE/boost

            C++博客 首頁 新隨筆 聯(lián)系 聚合 管理
              152 Posts :: 3 Stories :: 172 Comments :: 0 Trackbacks
                 message queue亦即消息隊(duì)列,在linux 下有msgsnd,msgrcv系列,在windows下有msmq,關(guān)于他們的相似及區(qū)別,請查閱相關(guān)資料,本文主要是簡單介紹一下boost提供的解決方案,及其性能。
               boost提供的message queue發(fā)送接口有send,try_send,timed_send,接收接口有receive,try_receive,timed_receive,其它接口有g(shù)et_max_msg,get_max_msg_size,get_num_msg,remove。學(xué)習(xí)難度不高。下面測試一下send的發(fā)送速度:
                測試代碼:

            #define BOOST_ALL_DYN_LINK
            #include <boost/interprocess/ipc/message_queue.hpp>
            #include <boost/format.hpp>
            #include <boost/progress.hpp>
            #include <iostream>
            #include <string>
            #include <vector>

            using namespace boost;
            using namespace boost::interprocess;

            #define MAX_MSG_COUNT 50000
            #define MAX_MSG_SIZE 1024

            int main ()
            {
            try{
              //Erase previous message queue
              message_queue::remove("message_queue");

              //Create a message_queue.
              message_queue mq
               (create_only               //only create
               ,"message_queue"           //name
               ,MAX_MSG_COUNT                       //max message number
               ,MAX_MSG_SIZE               //max message size
               );
              
              
              {
               progress_timer pt;//記錄時(shí)間,多方便!
              
               for(int i = 0; i < 5000; ++i)//可靈活調(diào)整i的大小
               {    
                std::string msg = str(format("hello world %d") % i);
                bool bRet = mq.send(msg.c_str(),msg.size(),0);  
               }
              }
              
            }

            catch(interprocess_exception &ex)
            {
              message_queue::remove("message_queue");
              std::cout << ex.what() << std::endl;
              return 1;
            }
            //message_queue::remove("message_queue");
            return 0;
            }

              我的測試結(jié)果如下:
            500    0.16s
            1000   0.41/0.50  -->表示測了2次,第一次0.41s,第二次0.50s,下同
            5000條 5.88s/6.16
            10000  22.81s/22.34
            20000  87.92/91.22

               最后簡單總結(jié)一下boost message queue:
              優(yōu)點(diǎn):速度還不錯(cuò),接口學(xué)習(xí)起來簡單,方便易用
              缺點(diǎn):我在windows下測試,當(dāng)一直在寫隊(duì)列時(shí),用ctrl + c中斷,然后用另一進(jìn)程讀讀隊(duì)列,讀操作時(shí)阻塞。單步跟蹤發(fā)現(xiàn)
              是阻塞在interprocess_mutex::lock加鎖的操作上,健壯程度遠(yuǎn)不如msgsnd,msgrcv系列,及msmq,該缺點(diǎn)比較致命。目前沒有測試linux下的情況。
            posted on 2008-07-31 08:58 true 閱讀(7118) 評論(0)  編輯 收藏 引用 所屬分類: boost
            99久久超碰中文字幕伊人| 国内精品久久久久影院日本| 狠狠色伊人久久精品综合网| 久久久人妻精品无码一区| 久久99九九国产免费看小说| 影音先锋女人AV鲁色资源网久久| 久久精品九九亚洲精品| 久久久久99精品成人片| 久久夜色精品国产欧美乱| 91久久成人免费| 久久亚洲AV成人无码国产| 久久91精品综合国产首页| 久久夜色精品国产噜噜亚洲AV| 色综合合久久天天综合绕视看| 少妇高潮惨叫久久久久久| 久久久久人妻一区精品 | 亚洲国产成人精品久久久国产成人一区二区三区综 | 久久AAAA片一区二区| 亚洲中文字幕无码久久综合网| 久久高潮一级毛片免费| 少妇久久久久久久久久| 久久久国产精华液| A级毛片无码久久精品免费| 久久久噜噜噜久久熟女AA片| 亚洲精品WWW久久久久久| 国产精品99久久久久久董美香| 亚洲AV成人无码久久精品老人| 亚洲欧洲久久久精品| 国内精品伊人久久久久影院对白| .精品久久久麻豆国产精品| 人妻久久久一区二区三区| 狠狠色丁香久久婷婷综合| 免费一级做a爰片久久毛片潮| 91久久精品电影| 四虎国产精品免费久久5151| 亚洲国产成人久久综合碰碰动漫3d| 亚洲AV无码久久精品色欲| 欧美黑人又粗又大久久久| 97r久久精品国产99国产精| 久久99热国产这有精品| 青青草原综合久久大伊人精品|