• <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亦即消息隊列,在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;//記錄時間,多方便!
              
               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)點:速度還不錯,接口學(xué)習(xí)起來簡單,方便易用
              缺點:我在windows下測試,當(dāng)一直在寫隊列時,用ctrl + c中斷,然后用另一進程讀讀隊列,讀操作時阻塞。單步跟蹤發(fā)現(xiàn)
              是阻塞在interprocess_mutex::lock加鎖的操作上,健壯程度遠不如msgsnd,msgrcv系列,及msmq,該缺點比較致命。目前沒有測試linux下的情況。
            posted on 2008-07-31 08:58 true 閱讀(7117) 評論(0)  編輯 收藏 引用 所屬分類: boost
            成人a毛片久久免费播放| 久久精品国产亚洲AV蜜臀色欲| 欧美伊人久久大香线蕉综合| 久久久久人妻精品一区三寸蜜桃 | 91精品国产91久久久久久| 狠狠综合久久综合中文88| 久久精品18| 久久精品中文字幕一区 | 久久国产精品久久国产精品| 夜夜亚洲天天久久| 中文字幕精品久久| 久久777国产线看观看精品| 三级片免费观看久久| 久久精品国产99久久久古代 | 久久精品无码一区二区三区免费| 久久无码专区国产精品发布| 国产欧美一区二区久久| 久久人人爽人人爽人人片AV高清| 66精品综合久久久久久久| 久久久www免费人成精品| 天天影视色香欲综合久久| 999久久久无码国产精品| 久久久久久久精品成人热色戒| 久久综合九色综合97_久久久| 亚洲精品乱码久久久久久按摩 | 伊人久久精品无码av一区| 91精品国产综合久久久久久| 久久丝袜精品中文字幕| 欧美亚洲日本久久精品| AV无码久久久久不卡蜜桃| 日本精品久久久久中文字幕8| 无码人妻久久一区二区三区免费| 久久狠狠一本精品综合网| 99久久精品免费观看国产| 国产美女久久精品香蕉69| 久久国产劲爆AV内射—百度| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 免费精品久久久久久中文字幕| 曰曰摸天天摸人人看久久久| 国产一级持黄大片99久久| 精品国产91久久久久久久|