• <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 閱讀(7109) 評論(0)  編輯 收藏 引用 所屬分類: boost
            久久99国内精品自在现线| 99久久精品免费看国产一区二区三区 | 狠狠色丁香久久综合婷婷| 99久久精品毛片免费播放| 国产精品成人99久久久久| 久久这里的只有是精品23| 国产精品99久久免费观看| 久久一区二区三区99| 久久久久无码精品国产不卡| 国产精品一区二区久久精品无码 | 漂亮人妻被中出中文字幕久久 | 伊人热人久久中文字幕| 久久午夜夜伦鲁鲁片免费无码影视| 亚洲欧美成人综合久久久| 国产激情久久久久影院| 狠狠色婷婷久久一区二区 | 精品水蜜桃久久久久久久| 中文字幕精品久久久久人妻| 91精品国产91久久久久久蜜臀| 无码任你躁久久久久久老妇App| 久久国产精品久久国产精品| 久久久久国产精品人妻| 日本加勒比久久精品| 久久91精品久久91综合| 久久精品毛片免费观看| 久久久亚洲AV波多野结衣| 人妻中文久久久久| 久久久青草青青国产亚洲免观| 亚洲一区二区三区日本久久九| 久久久免费精品re6| 欧美噜噜久久久XXX| 久久综合综合久久综合| 久久综合噜噜激激的五月天| 亚洲国产欧美国产综合久久| 久久久久久久久久久久久久 | 精品国产99久久久久久麻豆| 亚洲精品第一综合99久久| 色99久久久久高潮综合影院| 亚洲另类欧美综合久久图片区| 久久久久国产视频电影| 久久青青草原精品国产不卡|