• <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
            日韩精品久久久久久久电影| 97超级碰碰碰久久久久| 美女写真久久影院| 久久久国产精品福利免费 | 国产精品久久国产精品99盘| 久久精品国产秦先生| 伊人久久大香线焦AV综合影院| 久久综合给合久久狠狠狠97色| 亚洲国产精品热久久| 无码超乳爆乳中文字幕久久 | 国产69精品久久久久观看软件 | 久久精品综合一区二区三区| 久久久久久国产精品美女| 久久噜噜电影你懂的| 蜜桃麻豆WWW久久囤产精品| 国产V综合V亚洲欧美久久| 思思久久好好热精品国产| 久久99精品久久久久久| 久久人人爽人人爽人人片AV高清| 久久国产一区二区| 亚洲综合伊人久久综合| 久久93精品国产91久久综合| 久久精品国产亚洲欧美| 久久无码专区国产精品发布| 久久国产影院| 久久国产精品-国产精品| 亚洲级αV无码毛片久久精品| 久久天天日天天操综合伊人av| 天天久久狠狠色综合| 久久亚洲欧美国产精品| 久久精品国产亚洲AV忘忧草18| 久久成人18免费网站| 久久99国产精品一区二区| 日韩精品久久久久久免费| 久久成人小视频| 久久婷婷五月综合色奶水99啪 | 国产精品亚洲美女久久久| 91精品国产综合久久香蕉| 国产精品禁18久久久夂久 | 无码任你躁久久久久久| 性高湖久久久久久久久AAAAA|