服务接口,选择rpc还是http?

妙音 posted @ 2018年6月02日 23:32 in 架构 , 5377 阅读
系统如果组件比较多,在做技术选型时,组件通信该选择rpc还是http呢?
有人说rpc性能好,有人偏向http,对此有些疑惑,有必要细细思维一下。
 
  • 从通信内容/功能上看

内容 rpc       http     
字符串 支持 支持
文件 可以支持 支持
对象(序列化) 支持 可以支持
 
http应用于web环境,rpc应用于分布式调度
从功能上看没有太大区别,很多情况下rpc与消息中间件结合通信实现分布式调度
 
  • 从用法上看

两者都是c/s结构,无太大区别
 
  • 从实现上看

类型 底层协议
rpc tcp(zerorpc)/http2(gRPC)
http http1.x/http2
 
  • 从性能上看

1. 听说rpc是长链接,http是三次握手。
长链接虽然,可以减少tcp开销,相对的它会导入新的缺点,是否会对连接数数量有限制呢?
 
2. 假如rpc的性能比http高,无非就是socket多连接了三次。如果http结合非阻塞io服务器(例如tornado),这三次连接开销真没啥消耗。
当然网络也会有一点消耗. 非阻塞io服务器可以将rpc与http的性能差距拉平
 
从链接开销上,比较性能问题,本就是错误,两者是在解决不同问题,所有没有必要在这个问题上纠结。请继续看下面
 
  • 从概念上看

rpc远程调用
http超文本传输协议
 
  • 该如何选择呢?

1. 思考这个问题,应该用最简单的方式,相信协议设计者,会选择最好方式来解决它面临的问题(毕竟协议代表着公认),我们只用关注它解决什么问题。
rpc解决什么问题呢?远程调用。"调用"属于程序内部之间。调用总不可能只传简单参数,会涉及到对象序列化,
这个对象在开发是代码总不会用两套吧,server与client很可能是在一起的属于一个组件.
 
2. 连接数不该是"调用"考虑的事。在创建一个全局连接后,不会再频繁创建连接. 如果rpc作为服务,频繁连接的场景不适合它
 
  • 总结

1.c与s关系
rpc远程调用,属于程序内部之间,c与s关系密切。
http,适合不同组件,c与s关系独立。
 
2.连接数
rpc叫调用,频繁连接的场景不适合它
http的应用的web环境,本就是频繁连接的场景
 
《寿康宝鉴》有声书
寿康宝鉴百话有声书(mp3)
 
Avatar_small
Mumbai escorts 说:
2020年10月09日 14:53

Wonderful article. Attractive to read. I like reading such excellent article. Thank you! stay like that.

Avatar_small
hamza 说:
2020年10月10日 03:53

Konsultan pajak terbaik dan murah. Melayani pelaporan SPT Pajak, tax planning, restitusi pajak, bantuan sengketa pajak, TP Doc, dan pembukuan akuntansi juga payroll.

<a href="https://about.me/taxbandung">Konsultan Pajak</a>

Avatar_small
메리트카지노 说:
2020年10月10日 13:18

There are up to 7 players per table, and you get to choose your seat. It’s multiplayer baccarat with a jackpot side bet.
https://www.caz333.com
<a href="https://www.caz333.com"title="caz333.com">caz333.com</a>

Avatar_small
hassan 说:
2020年10月10日 15:30

I should assert barely that its astounding! The blog is informational also always fabricate amazing entitys. Konsultan pajak

Avatar_small
check this out 说:
2020年10月12日 07:31

wow, great, I was wondering how to cure acne naturally. and found your site by google, learned a lot, now i’m a bit clear. I’ve bookmark your site and also add rss. keep us updated.

Avatar_small
메리트카지노 说:
2020年10月12日 16:08

Todos sabemos lo atún que es que nos mimen y es por esto que en Casino King tratamos a todos nuestros jugadores como VIP.
https://casino.cassbet.com

Avatar_small
Paris Gestion Immobi 说:
2020年10月14日 01:47

Many thanks for the exciting blog posting! Simply put your blog post to my favorite blog list and will look forward for additional updates. Simply wanted to write down a word in order to say thanks to you for those wonderful tips.

Avatar_small
Mumbai escorts servi 说:
2020年10月15日 15:59

I enjoyed reading this great post. Please share more posts like this because I want more such posts.

Avatar_small
online cake delivery 说:
2020年10月16日 22:45

Your work here on this blog has been top notch from day 1. You've been continously providing amazing articles for us all to read and I just hope that you keep it going on in the future as well. Cheers!

Avatar_small
learn more here 说:
2020年10月19日 19:32

We keep up with the latest techniques of building and have qualified tradesmen to ensure that your job/project is carried out safely. We also make sure that we keep to the highest standards on projects and everyone who works for us is health & safety trained.

Avatar_small
Wordpress Entwicklun 说:
2020年10月22日 19:07

Wirklich schöner und interessanter Beitrag. Wordpress Entwicklung Innsbruck

Avatar_small
UFC 254 Live Stream 说:
2020年10月22日 20:20

https://usdirectv.com/ufc254

https://usnowtv.com/ufc254

https://uscbstv.com

https://usnbctv.com

https://usfoxtv.com

https://usnbctv.com/reddit/ufc-254-live

https://usnbctv.com/reddit/khabib-vs-gaethje-live

Avatar_small
Mobile Apps 说:
2020年10月23日 14:30

So ein sehr nützlicher Artikel. Sehr interessant, diesen Artikel zu lesen.

Avatar_small
hassan 说:
2020年10月26日 17:30

There is so much in this article that I would never have thought of on my own. Your content gives readers things to think about in an interesting way. buy youtube views and likes

Avatar_small
In Stream Advertisem 说:
2020年10月29日 05:58

<a href="https://instreamadvertisement.com/">In Stream Advertisement</a>

Amazing knowledge and I like to share this kind of information with my friends and hope they like it they why I do.

Avatar_small
learn more here 说:
2020年11月01日 18:46

A good blog always comes-up with new and exciting information and while reading I have feel that this blog is really have all those quality that qualify a blog to be a one.I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts.

Avatar_small
Suchmaschinenoptimie 说:
2020年11月04日 14:54

Ich sehe die besten Inhalte in Ihrem Blog und ich liebe es sehr, sie zu lesen. Danke fürs Teilen…

Avatar_small
Buy Poker Backlinks 说:
2020年11月06日 05:28

Your work here on this blog has been top notch from day 1. You've been continously providing amazing articles for us all to read and I just hope that you keep it going on in the future as well. Cheers!

Avatar_small
hassan 说:
2020年11月06日 12:29

You bear through a awesome vacancy. I sanity definitely quarry it moreover personally suggest to my buddys. I am self-possessed they determination be benefited from this scene. where can I buy Cialis

Avatar_small
Anosha 说:
2020年11月08日 20:57

I think I have never observed such web journals ever that has finish things with all points of interest which I need. So sympathetically refresh this ever for us. on the site

Avatar_small
indian visa applicat 说:
2020年11月12日 16:50

First You got a great blog .I will be interested in more similar topics. i see you got really very useful topics , i will be always checking your blog thanks.

Avatar_small
sagame66 说:
2020年11月13日 22:46

First You got a great blog .I will be interested in more similar topics. i see you got really very useful topics , i will be always checking your blog thanks.

Avatar_small
hassan 说:
2020年11月26日 21:48

A debt of gratitude is in order for the instructive and accommodating post, clearly in your blog everything is great.. research paper writing service

Avatar_small
SaaS Security Postur 说:
2020年12月14日 15:05

I high appreciate this post. It’s hard to find the good from the bad sometimes, but I think you’ve nailed it! would you mind updating your blog with more information

Avatar_small
online cake order in 说:
2020年12月15日 00:30

Thanks for a wonderful share. Your article has proved your hard work and experience you have got in this field. Brilliant .i love it reading.

Avatar_small
online cake and flow 说:
2020年12月18日 20:49

Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.

Avatar_small
ac service in Delhi 说:
2020年12月22日 19:57

For that reason it is preferable you will want to similar analyze ahead of generating. You are able to release more effective post like this.

Avatar_small
check more info here 说:
2020年12月23日 20:40

I regularly visit this site to check out the events and functions and sometimes for resources. However, it has been a while that you have shared some news about latest or upcoming events.

Avatar_small
canvas cotton bags 说:
2021年1月03日 23:23

I would also motivate just about every person to save this web page for any favorite assistance to assist posted the appearance.

Avatar_small
check cake pricing 说:
2021年1月05日 20:37

Wonderful blog post. This is absolute magic from you! I have never seen a more wonderful post than this one. You've really made my day today with this. I hope you keep this up!

Avatar_small
is good site 说:
2021年1月06日 20:45

I’m excited to uncover this page. I need to to thank you for ones time for this particularly fantastic read!! I definitely really liked every part of it and i also have you saved to fav to look at new information in your site

Avatar_small
fsfs ge A 说:
2021年1月08日 03:30

https://www.facebook.com/events/416889626159770
https://www.reddit.com/r/MayweathervPaulBoxing

https://www.reddit.com/r/MayweathervPaulStream

https://www.facebook.com/events/416889626159770

https://www.facebook.com/MayweathervsPaulFight

https://twitter.com/FloydvsPaulPPV

https://www.facebook.com/groups/mayweathervspaulfight

Avatar_small
hassan 说:
2021年1月09日 21:54

Here at this site extremely the critical material accumulation so everyone can appreciate a great deal. winter foods in India

Avatar_small
can a notary notariz 说:
2021年1月11日 22:15

I’ve been surfing online more than three hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. In my opinion, if all webmasters and bloggers made good content as you did, the web will be a lot more useful than ever before.

Avatar_small
Imamia Quran Academy 说:
2023年7月23日 05:52

Hi everyone, I really love your story. You have very useful information; I am from Imamia Quran Academy.

Shia Online Quran Academy is an institute for Quran Education. They have trained teaching staff along with renowned Islamic Scholars for a better understanding of the Quran.

Avatar_small
gamer 说:
2023年11月25日 11:10

Excellent read, Positive site, where did u come up with the information on this posting? I have read a few of the articles on your website now and are very impotent of the blog that you will know many here
https://gamerphilippines.blogspot.com/

Avatar_small
gaming 说:
2023年11月25日 11:10

nice article.thanks for share this.i like your blog commenting this site. what do you want to know is here so what are you waiting for your visitor to my site
https://gamerphilippines.blogspot.com/

Avatar_small
game 说:
2023年11月25日 11:10

the importance of human beings is something we care about and especially for young people today they can affect those who are in the world so we should value every child
<A HREF="https://gamerphilippines.blogspot.com/" TARGET='_blank'>game</A>


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter