• <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>

            網絡服務器軟件開發/中間件開發,關注ACE/ICE/boost

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

            #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;//記錄時間,多方便!
              
               for(int i = 0; i < 5000; ++i)//可靈活調整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;
            }

              我的測試結果如下:
            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

               最后簡單總結一下boost message queue:
              優點:速度還不錯,接口學習起來簡單,方便易用
              缺點:我在windows下測試,當一直在寫隊列時,用ctrl + c中斷,然后用另一進程讀讀隊列,讀操作時阻塞。單步跟蹤發現
              是阻塞在interprocess_mutex::lock加鎖的操作上,健壯程度遠不如msgsnd,msgrcv系列,及msmq,該缺點比較致命。目前沒有測試linux下的情況。
            posted on 2008-07-31 08:58 true 閱讀(7117) 評論(0)  編輯 收藏 引用 所屬分類: boost
            亚洲国产精品热久久| 久久久久AV综合网成人| 亚洲?V乱码久久精品蜜桃 | 久久亚洲精品中文字幕| 久久99国产精品久久| 久久婷婷五月综合色99啪ak| 久久AV无码精品人妻糸列| 日韩一区二区久久久久久 | 中文字幕久久久久人妻| 精品无码久久久久久午夜| 四虎久久影院| 99久久国产综合精品网成人影院 | 亚洲狠狠久久综合一区77777| 伊人热热久久原色播放www| 久久精品国产99国产电影网| 九九精品久久久久久噜噜| 久久成人18免费网站| 久久精品国内一区二区三区 | 久久无码精品一区二区三区| 国产精品毛片久久久久久久| 综合久久国产九一剧情麻豆| 日韩久久久久中文字幕人妻| 久久93精品国产91久久综合| 狠狠狠色丁香婷婷综合久久五月 | 三级韩国一区久久二区综合| 蜜桃麻豆www久久| 久久免费美女视频| 色成年激情久久综合| 久久最新精品国产| 99久久国产免费福利| 国产视频久久| 国产高清美女一级a毛片久久w| 久久香蕉国产线看观看99| 国产精品久久网| 国产999精品久久久久久| 久久最新精品国产| 久久涩综合| 色综合久久久久无码专区| 色综合久久无码中文字幕| 国产精品久久久福利| 国产成人精品久久亚洲高清不卡|