<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          哪個更快?對 gRPC 的 Rust 和 Go 版本進(jìn)行基準(zhǔn)測試

          共 5324字,需瀏覽 11分鐘

           ·

          2020-07-27 19:50

          點(diǎn)擊上方藍(lán)色“Go語言中文網(wǎng)”關(guān)注我們,領(lǐng)全套Go資料,每天學(xué)習(xí)?Go?語言

          背景

          如果你計(jì)劃構(gòu)建可靠,內(nèi)存安全[1],高性能的應(yīng)用程序,那么 Rust&Go 無疑會是你的選擇。

          如果您希望從內(nèi)部應(yīng)用程序中獲得更高的性能,則可能還需要考慮使用 gRPC[2] 而不是普通的 REST[3] API。所有這些都是減少您的計(jì)算開銷的解決方案。

          我嘗試比較各種庫以了解它們的性能,并希望對你有所幫助。

          關(guān)注的庫

          • tower-grpc[4] (Rust)

            高性能 rust 庫,盡管已被 tonic 替代

          • grpc-go[5] (Golang)

            grpc 的官方 Go 模塊

          • grpc-rust[6] (Rust)

            仍在開發(fā)中,另一個 rust grpc 庫。看起來很不錯

          • tonic[7] (Rust)

            tower-grpc 庫的改進(jìn)更新,支持新的 await 語法

          • grpc-node[8] (NodeJs)

            包含有基準(zhǔn)基準(zhǔn)點(diǎn)

          • grpc-rs[9] (Rust — C bindings)

            使用 grpc[10] 的 rust 庫

          基準(zhǔn)測試工具

          對于基準(zhǔn)測試,我將在 gRPC 中使用與 Hey[11] 等效的 ghz[12]

          該測試將重點(diǎn)關(guān)注如果使用上述每個庫將 10,000 個并發(fā)請求的相同負(fù)載發(fā)送到服務(wù)器,將有多少開銷。我將為每個使用相同的 helloworld[13] greeter。不會為任何測試啟用 TLS,因此我們可以大致了解每種測試的原始性能。

          grpc-go

          Summary:
          ??Count:?10000
          ??Total:?229.40?ms
          ??Slowest:?6.26?ms
          ??Fastest:?0.11?ms
          ??Average:?1.04?ms
          ??Requests/sec:?43591.54Response?time?histogram:
          ??0.114?[1]????|
          ??0.728?[3355]?|?????????????????????????????
          ??1.343?[4580]?|????????????????????????????????????????
          ??1.957?[1519]?|?????????????
          ??2.572?[294]??|???
          ??3.187?[36]???|
          ??3.801?[11]???|
          ??4.416?[74]???|?
          ??5.030?[52]???|
          ??5.645?[45]???|
          ??6.259?[33]???|Latency?distribution:
          ??10?%?in?0.46?ms
          ??25?%?in?0.64?ms
          ??50?%?in?0.88?ms
          ??75?%?in?1.24?ms
          ??90?%?in?1.68?ms
          ??95?%?in?2.00?ms
          ??99?%?in?4.77?msStatus?code?distribution:
          ??[OK]???10000?responses

          tonic

          Summary:
          ??Count:?10000
          ??Total:?581.81?ms
          ??Slowest:?6.39?ms
          ??Fastest:?0.17?ms
          ??Average:?2.84?ms
          ??Requests/sec:?17187.66Response?time?histogram:
          ??0.174?[1]????|
          ??0.796?[5]????|
          ??1.418?[6]????|
          ??2.040?[167]??|?
          ??2.662?[3427]?|???????????????????????????
          ??3.284?[5074]?|????????????????????????????????????????
          ??3.906?[1048]?|????????
          ??4.528?[217]??|??
          ??5.150?[29]???|
          ??5.773?[21]???|
          ??6.395?[5]????|Latency?distribution:
          ??10?%?in?2.35?ms
          ??25?%?in?2.55?ms
          ??50?%?in?2.79?ms
          ??75?%?in?3.07?ms
          ??90?%?in?3.39?ms
          ??95?%?in?3.66?ms
          ??99?%?in?4.22?msStatus?code?distribution:
          ??[OK]???10000?responses

          grpc-node

          Summary:
          ??Count:?10000
          ??Total:?589.25?ms
          ??Slowest:?12.56?ms
          ??Fastest:?1.21?ms
          ??Average:?2.88?ms
          ??Requests/sec:?16970.81Response?time?histogram:
          ??1.206?[1]????|
          ??2.341?[2592]?|???????????????????
          ??3.476?[5516]?|????????????????????????????????????????
          ??4.612?[1588]?|????????????
          ??5.747?[180]??|?
          ??6.882?[42]???|
          ??8.017?[32]???|
          ??9.152?[5]????|
          ??10.288?[20]??|
          ??11.423?[6]???|
          ??12.558?[18]??|Latency?distribution:
          ??10?%?in?2.14?ms
          ??25?%?in?2.33?ms
          ??50?%?in?2.62?ms
          ??75?%?in?3.24?ms
          ??90?%?in?3.85?ms
          ??95?%?in?4.26?ms
          ??99?%?in?6.41?msStatus?code?distribution:
          ??[OK]???10000?responses

          tower-grpc

          Summary:
          ??Count:?10000
          ??Total:?571.88?ms
          ??Slowest:?10.59?ms
          ??Fastest:?0.25?ms
          ??Average:?2.76?ms
          ??Requests/sec:?17486.12Response?time?histogram:
          ??0.246?[1]????|
          ??1.280?[139]??|?
          ??2.314?[2927]?|???????????????????????
          ??3.348?[5198]?|????????????????????????????????????????
          ??4.382?[1390]?|???????????
          ??5.416?[114]??|?
          ??6.450?[61]???|
          ??7.484?[80]???|?
          ??8.518?[47]???|
          ??9.552?[31]???|
          ??10.586?[12]??|Latency?distribution:
          ??10?%?in?1.80?ms
          ??25?%?in?2.20?ms
          ??50?%?in?2.65?ms
          ??75?%?in?3.13?ms
          ??90?%?in?3.64?ms
          ??95?%?in?4.05?ms
          ??99?%?in?7.18?msStatus?code?distribution:
          ??[OK]???10000?responses

          grpc-rust

          Summary:
          ??Count:?10000
          ??Total:?479.30?ms
          ??Slowest:?8.15?ms
          ??Fastest:?0.90?ms
          ??Average:?2.34?ms
          ??Requests/sec:?20863.64Response?time?histogram:
          ??0.901?[1]????|
          ??1.626?[193]??|?
          ??2.351?[5587]?|????????????????????????????????????????
          ??3.076?[3562]?|??????????????????????????
          ??3.801?[506]??|????
          ??4.526?[119]??|?
          ??5.251?[16]???|
          ??5.976?[5]????|
          ??6.701?[2]????|
          ??7.426?[2]????|
          ??8.151?[7]????|Latency?distribution:
          ??10?%?in?1.87?ms
          ??25?%?in?2.03?ms
          ??50?%?in?2.25?ms
          ??75?%?in?2.57?ms
          ??90?%?in?2.90?ms
          ??95?%?in?3.23?ms
          ??99?%?in?4.11?msStatus?code?distribution:
          ??[OK]???10000?responses

          Grpc-rs

          Summary:
          ??Count:?10000
          ??Total:?289.82?ms
          ??Slowest:?4.22?ms
          ??Fastest:?0.22?ms
          ??Average:?1.36?ms
          ??Requests/sec:?34504.74Response?time?histogram:
          ??0.222?[1]????|
          ??0.621?[195]??|??
          ??1.021?[1829]?|??????????????????
          ??1.420?[4059]?|????????????????????????????????????????
          ??1.820?[2625]?|??????????????????????????
          ??2.219?[972]??|??????????
          ??2.618?[239]??|??
          ??3.018?[45]???|
          ??3.417?[18]???|
          ??3.817?[6]????|
          ??4.216?[11]???|Latency?distribution:
          ??10?%?in?0.87?ms
          ??25?%?in?1.07?ms
          ??50?%?in?1.30?ms
          ??75?%?in?1.62?ms
          ??90?%?in?1.90?ms
          ??95?%?in?2.07?ms
          ??99?%?in?2.56?msStatus?code?distribution:
          ??[OK]???10000?responses

          匯總概要

          總響應(yīng)時間(以毫秒為單位)。越低越好。


          吞吐量(請求/秒)。越高越好。

          總結(jié)

          結(jié)果表明,在性能方面,rust 與 node 相當(dāng),這是一個令人震驚的結(jié)果。

          Go 庫在并發(fā)性和最小開銷方面均表現(xiàn)出色。

          如果有人對 Go 庫表現(xiàn)優(yōu)異有些疑惑,請給留言給出你的看法!

          原文鏈接:https://medium.com/@Rustling_gopher/benchmarking-grpc-in-rust-go-184545e7688a

          作者:Rustler

          編譯:polaris

          參考資料

          [1]

          內(nèi)存安全: https://blog.gds-gov.tech/appreciating-rust-memory-safety-438301fee097

          [2]

          gRPC: https://grpc.io/docs/what-is-grpc/introduction/

          [3]

          REST: https://restfulapi.net/

          [4]

          tower-grpc: https://github.com/tower-rs/tower-grpc

          [5]

          grpc-go: https://github.com/grpc/grpc-go

          [6]

          grpc-rust: https://github.com/stepancheg/grpc-rust

          [7]

          tonic: https://github.com/hyperium/tonic

          [8]

          grpc-node: https://github.com/grpc/grpc-node

          [9]

          grpc-rs: https://github.com/tikv/grpc-rs

          [10]

          grpc: https://github.com/grpc/grpc

          [11]

          Hey: https://github.com/rakyll/hey

          [12]

          ghz: https://github.com/bojand/ghz

          [13]

          helloworld: https://github.com/grpc/grpc-go/blob/master/examples/helloworld/helloworld/helloworld.proto



          推薦閱讀


          學(xué)習(xí)交流 Go 語言,掃碼回復(fù)「進(jìn)群」即可


          站長 polarisxu

          自己的原創(chuàng)文章

          不限于 Go 技術(shù)

          職場和創(chuàng)業(yè)經(jīng)驗(yàn)


          Go語言中文網(wǎng)

          每天為你

          分享 Go 知識

          Go愛好者值得關(guān)注


          瀏覽 121
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  操逼视频免费看 | 女人18毛片黄 | 18禁激韩 | 日韩精品一区二区三区四虎影视 | 国产日产亚洲精品 |