日本a√视频在线,久久青青亚洲国产,亚洲一区欧美二区,免费g片在线观看网站

        <style id="k3y6c"><u id="k3y6c"></u></style>
        <s id="k3y6c"></s>
        <mark id="k3y6c"></mark>
          
          

          <mark id="k3y6c"></mark>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 如何在Dragonbaord 410c上實現(xiàn)高性能并發(fā)處理TCP服務(wù)器

          如何在Dragonbaord 410c上實現(xiàn)高性能并發(fā)處理TCP服務(wù)器

          作者: 時間:2017-10-11 來源:網(wǎng)絡(luò) 收藏

          在IOT設(shè)計中,通常我們需要構(gòu)建一個或者多個監(jiān)測和控制網(wǎng)絡(luò),來實現(xiàn)對各種傳感器及設(shè)備的數(shù)據(jù)采集和控制,這樣我們就需要在網(wǎng)絡(luò)中實現(xiàn)集中管理終端,以對區(qū)域的傳感器和設(shè)備進(jìn)行集中管理,在云端和底層控制節(jié)點之間維護(hù)一個智能化的管理終端,dragonboard 410c憑借其強大的處理性能和網(wǎng)絡(luò)連接能力,可以方便的實現(xiàn)這一管理終端功能,此時我們就需要在dragonbaord 410c上設(shè)計一個多任務(wù)的接入服務(wù),讓傳感器和相關(guān)的控制設(shè)備接入,為此,本期blog將向大家介紹如何使用gevent高性能的并發(fā)處理庫在draognbaord 410c上來實現(xiàn)一個高性能的TCP服務(wù)器。

          本文引用地址:http://yuyingmama.com.cn/article/201710/365545.htm

          gevent是基于協(xié)程的Python網(wǎng)絡(luò)庫。特點: 基于libev的快速事件循環(huán)(Linux上epoll,F(xiàn)reeBSD上kqueue)。 基于greenlet的輕量級執(zhí)行單元。 API的概念和Python標(biāo)準(zhǔn)庫一致(如事件,隊列)。 可以配合socket,ssl模塊使用。 能夠使用標(biāo)準(zhǔn)庫和第三方模塊創(chuàng)建標(biāo)準(zhǔn)的阻塞套接字(gevent.monkey)。

          使用gevent來提高我們的并發(fā)處理性能,首先需要在draongboard 410c上安裝gevent模塊,具體安裝方法如下:

          sudo apt-get install libevent-dev

          sudo apt-get install python-all-dev

          sudo apt-get install python-setuptools

          sudo easy_install greenlet

          sudo easy_install gevent

          完成安裝后,from gevent.server import StreamServer 就可以導(dǎo)入使用gevent來實現(xiàn)高效的并發(fā)處理,這里我們以構(gòu)建一個簡答的業(yè)務(wù)邏輯處理服務(wù)為例,具體代碼如下:

          from gevent.server import StreamServer

          import addressbook_pb2

          from testBusinessLogic import testBusinessLogic

          BUFSIZE=1024

          reportLenMin=10

          def handle(socket,address):

          while(1):

          try:

          report=socket.recv(BUFSIZE)

          print(report)

          if len(report)>reportLenMin:

          testLogic=testBusinessLogic(report,“192.168.1.156”)

          testLogic.startMainLogicProcess(socket)

          else:

          print(“recv report error”)

          socket.send(“your report is error”)

          except:

          print(“service error”)

          socket.send(“service error”)

          if __name__==“__main__”:

          testServer = StreamServer((‘192.168.41.156’,5000),handle)

          testServer.serve_forever()

          到這里我們就完成了整個測試服務(wù)器的搭建,該服務(wù)器能夠借助于gevent實現(xiàn)高并發(fā)的處理,并且支持異常處理,可以在dragonbaord 410c上穩(wěn)定運行,這里testBusinessLogic為測試邏輯處理類,大家需要實現(xiàn)的業(yè)務(wù)邏輯可以放到里面實現(xiàn),具體不詳細(xì)介紹。



          關(guān)鍵詞: DragonBoard410c

          評論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉