当前位置:网站首页>Problems and abuse of protocol buffers
Problems and abuse of protocol buffers
2022-07-23 21:12:00 【51CTO】
At present, the company has widely used Protocol buffers.
I found a lot in the process of using Protocol buffers The use and abuse of , It's also frustrating to use a good tool like this .
The following is a brief summary of the problems in use .
Protocol buffers Intention
Protocol buffers To speed up the network data transmission , Compress the transmitted data , By exposing interfaces, programs can communicate faster .
Take a chestnut , Service or program A Need to get user information , But the way to get user information is already in the service or program B It defines .
There are several solutions .
- A Rewrite again B Methods already defined in , This is obviously the most uneconomical , Why rewrite , And it also causes redundancy , Not easy to maintain .
- B Program provides interface , And then we passed HTTP Mode of access , Get the returned data and then serialize and deserialize .
- Use Protocol buffers,B The program is defined proto The way the file will be B The method in is exposed ,A The program can use this method directly in the program , If B The method of the program has changed or upgraded ,A The program doesn't need to be modified too much , Because in A This method is directly used in the program .
Let's focus on usage scenarios 3. In this usage scenario , Data exchange is still used HTTP, The defined data transmission format is in proto Defined in the file .
If B The method in the program has changed , But the transmission format has not changed , This will not affect the program A Method of .
adopt HTTP The data transmission is compressed , It is more efficient than ordinary uncompressed JSON Smaller data . For the network, smaller data means greater efficiency .
The simple explanation is to use Protocol buffers It is equal to in the scene 2 It gives you a new layer of encapsulation .
Protocol buffers Amount of data transmitted
Protobuf The maximum data transmission limit is 2GB.
By default it is 64MB.
Don't think it's used Protocol buffers You can transmit data of any size without restraint , It's not like that , If the amount of data returned by the method in the program is too large , Or object List Too complicated .
You will naturally encounter more than Protocol buffers The size of the transmission limit , Then throw an exception .
This also has a lot to do with program design , Our current system can't wait to transmit the whole table , I don't know how to say .
Protocol buffers Indiscriminate call
No one really cares about maintenance proto file , How do you want to use it .
The problem with the result is : A service needs to run , Need to start other 5 Services can be debugged locally .
And because the start of each service occupies ports , Therefore, it will lead to cross calls of various methods , Make the written program very difficult to debug locally .
The solution is to define the function of each service , Don't abuse too much Protocol buffers To call .
In fact, the above problems are man-made , Once the best thing is abused , It's all kinds of wonderful flowers .
边栏推荐
- 深入浅出边缘云 | 1. 概述
- The common interfaces of Alipay are uniformly encapsulated and can be used directly for payment parameters (applicable to H5, PC, APP)
- 1063 Set Similarity
- How to introduce your project experience in the interview
- jsp+ssm+mysql实现的租车车辆管理系统汽车租赁
- [attack and defense world web] difficulty four-star 12 point advanced question: confusion1
- Microservice architecture vs single service architecture [what can Huawei cloud service do in the microservice mode]
- 初识js(适合新手的编程)
- 最小生成树:Kruskal
- 当我们在谈论陈春花和华为时,我们到底在讨论什么?
猜你喜欢
随机推荐
Broadcast (broadcast)
【微信小程序】你了解小程序开发吗?
Car rental vehicle management system based on jsp+ssm+mysql car rental
Is it safe to open a mobile stock account?
[Yunxiang book club No. 13] Chapter IV packaging format and coding format of audio files
"Pulse" to the future! Huawei cloud Mrs helps smooth migration to the cloud
Failed to introspect Class FeignClientFactoryBean 异常排查
Identify some positions in the parenthesis sequence
高数下|二重积分的计算4|高数叔|手写笔记
Trial record of ModelBox end cloud collaborative AI development kit (rk3568) (II)
Network learning infrared module, 8-way emission independent control
Green-Tao 定理的证明 (2): Von Neumann 定理的推广
Install under win7-vs2012 Net framework work
【着色器实现RoundWave圆形波纹效果_Shader效果第六篇】
Chapter 2 Regression
[leetcode] day101 rotating image
VLAN综合实验
确定括号序列中的一些位置
一道golang中关于for range常见坑的面试题
Understanding of signals










