• <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
            亚洲va中文字幕无码久久不卡| 久久噜噜久久久精品66| 伊人情人综合成人久久网小说| 中文字幕久久欲求不满| 狠狠人妻久久久久久综合| 99久久无码一区人妻a黑| 久久se精品一区精品二区国产| 久久九色综合九色99伊人| 7国产欧美日韩综合天堂中文久久久久| 人妻无码精品久久亚瑟影视 | 亚洲AV乱码久久精品蜜桃| 国产精品一区二区久久| 久久久久久国产精品美女| 久久久久国色AV免费看图片| av午夜福利一片免费看久久| 久久久久人妻一区精品| 久久精品国产亚洲AV不卡| 久久久久女教师免费一区| 99久久综合国产精品免费| 亚洲国产一成人久久精品| 久久本道久久综合伊人| 久久人人爽人人爽人人AV | 国产亚洲美女精品久久久| 性做久久久久久久久浪潮| 久久99精品国产自在现线小黄鸭 | 久久久久久精品无码人妻| 99久久99这里只有免费费精品| 青青热久久国产久精品 | 天天综合久久久网| 狠狠色婷婷久久一区二区| 久久精品国产福利国产琪琪| 久久亚洲欧美日本精品| 影音先锋女人AV鲁色资源网久久| 久久久久香蕉视频| 亚洲国产二区三区久久| 精品一区二区久久| 成人综合伊人五月婷久久| 97久久精品午夜一区二区| 久久中文骚妇内射| 久久婷婷激情综合色综合俺也去| 99精品久久久久久久婷婷|