千金是什么生肖| 前列腺炎是什么症状| hvi是什么病| 脚心烧是什么原因| 什么油炒菜好吃又健康| 有福气是什么意思| 淋巴细胞计数偏低是什么原因| 什么药膏可以去黑头| 三点水开念什么意思| 验血能查出什么| hedgren是什么品牌| 扁桃体肥大有什么影响| 晚上喝蜂蜜水有什么好处和坏处| 耳石症眩晕吃什么药| 围绝经期是什么意思| 下午7点是什么时辰| 为什么第一次进不去| qr是什么意思| 手发胀是什么前兆| 女人吃葛根粉有什么好处| 压寨夫人是什么意思| 尘螨是什么| egg是什么意思| mews评分是什么意思| 眼开大财主是什么生肖| 壁虎的尾巴有什么作用| 扁平息肉属于什么性质| 左胸隐隐作痛是什么原因| 禾字五行属什么| 糯叽叽什么意思| 复杂性囊肿是什么意思| 牙松动了还疼用什么方法处理最好| 怪力乱神是什么意思| 深井冰什么意思| 味粉是什么调料| 吃什么对喉咙好| 痤疮用什么药膏最好| 九五年属什么| 视而不见的意思是什么| 利可君片是治什么病| 干燥综合征吃什么药| 什么是中药| 紫癜是什么引起的| 猫怕什么气味| 火烧火燎是什么意思| 猎德村为什么那么有钱| 姨妈期能吃什么水果| 慢性盆腔炎吃什么药| 早教是做什么的| 湿气重吃什么中药好| 吃什么食物补脾虚| 膝关节积液吃什么药| 王秋儿和王冬儿什么关系| 甲沟炎是什么样子的| 正月初七什么星座| 莆田系是什么意思啊| 头晕想吐是什么原因| 头疼发烧吃什么药| 鳌虾吃什么| 刷牙牙龈出血是什么原因| 口干口臭什么原因引起的| 什么是反物质| cpi下降意味着什么| 中午吃什么菜| 道歉送什么花| 阳痿是什么症状| 辣木籽是什么| 脚底干裂起硬皮是什么原因怎么治| 杭字五行属什么| 木耳属于什么类| 汾酒是什么香型| 感觉是什么意思| 佛历是什么意思| 型式检验是什么意思| 早退是什么意思| 鼻窦炎是什么样子的| 脚底板疼痛是什么原因| 为什么说金克木生财| 罗红霉素胶囊治什么病| 西兰花不能和什么一起吃| 紫菜是什么植物| 空调什么度数最省电| 口臭口苦什么原因引起的| 女生排卵期有什么症状| 狮子吃什么| 海马炖什么好小孩长高| 什么东西能吃能喝又能坐| 男生为什么喜欢女生| 为什么一喝阿胶睡眠就好了| 脂肪瘤长什么样| 头皮屑特别多是什么原因| 普通感冒吃什么药| 还行吧是什么意思| 芒果不能跟什么一起吃| 精工手表什么档次| 唱反调是什么意思| 心悸是什么意思| 猫舔人是什么意思| 双的反义词是什么| 幽门螺旋杆菌阳性是什么意思| 香水前调中调后调是什么意思| 亮晶晶的什么填空| 日斤念什么字| 吃什么东西养胃最有效| 百合花什么时候种植| 鱼水之欢是什么意思| 礼金是什么意思| 啤酒酵母是什么| 桑叶泡水喝有什么功效| 10.19什么星座| 夏天能干什么| 解说是什么意思| mia是什么意思| 鲜黄花菜含有什么毒素| 什么舌头| 灵芝孢子粉治什么病| 胸骨突出是什么原因| 女人脸肿是什么原因引起的| 脚冰冰凉是什么原因| 什么阳地名| 今年二十岁属什么生肖| 臭屁什么意思| 肿瘤是什么病严重吗| 身上有斑点是什么原因| 人活着有什么意思| bmi值是什么意思| 1972年是什么命| 420是什么意思| 急性阴道炎是什么引起的| 芦荟胶有什么作用| 褐色分泌物是什么原因| 喝什么茶叶减肥效果最好| 桦树茸的功效主治什么病| 部署是什么意思| 煲电话粥什么意思| 静脉曲张看什么科室| 感性是什么意思| 女的肾虚是什么症状| 2024年属龙的是什么命| 一什么田| 1907年属什么生肖| 碱和小苏打有什么区别| 等字五行属什么| 增值税是什么| 眼眶周围发黑什么原因| 金字是什么部首| 什么什么大什么| 为什么放屁多| 肱骨外上髁炎用什么药| 睾丸是什么| 风雨雷电代表什么生肖| 痛风是什么原因| 上升水瓶座为什么可怕| rm是什么币| 什么粉一沾就痒还看不出来| 心率过慢有什么危害| 腱鞘囊肿挂什么科| 王姓为什么出不了皇帝| 睡意是什么意思| 无中生有是什么生肖| 江诗丹顿属于什么档次| 繁衍的衍是什么意思| 2月19日是什么星座| 海龟汤什么意思| 什么叫高尿酸血症| 阴唇萎缩是什么原因| 牙齿打桩是什么意思| 眼睛老是流眼泪是什么原因| 九寨沟什么时候去最好| 伤口撒什么药粉好得快| 牙龈为什么会萎缩| 为什么会射精| 白细胞偏低是什么原因造成的| 明五行属什么| 牙疼吃什么止疼药| 心理卫生科看什么病的| 易经是什么| 体重突然下降是什么原因| 布洛芬什么时候起效| 取环后需要注意什么| 2009年出生属什么| 约会什么意思| jb是什么意思| 鸭蛋炒什么好吃| 龟苓膏有什么功效| 少了一个肾有什么影响| 六十岁叫什么之年| 晚上猫叫有什么预兆| v3是什么意思| 覆水难收是什么意思| 三月是什么生肖| 黑道日为什么还是吉日| 男人要的归属感是什么| 100元人民币什么时候发行的| 临床表现是什么意思| 致青春是什么意思| 吃什么容易流产| 小叶增生和乳腺增生有什么区别| 胃食管反流挂什么科| 什么是慈悲| 神什么气什么| 口干口苦是什么原因引起的| 为什么会长花斑癣| 吃什么最养胃修复胃| 右脸麻木是什么原因| 什么是化疗和放疗| 支气管炎是什么| 猪肝吃多了有什么坏处| 村里入党需要什么条件| 为什么隔夜茶不能喝| 公主病是什么意思| 汤姆猫是什么品种| 射精快吃什么药| 爱趴着睡觉是什么原因| 鳌是什么意思| 眼线是什么意思| 鱼子酱什么味道| 尿蛋白阳性是什么意思| 胎儿生物物理评分8分什么意思| 月指什么生肖| 女性得了性病有什么症状| 精神可嘉是什么意思| 前列腺按摩什么感觉| 贵州有什么| 慢性咽炎吃什么药| 赑屃是什么意思| 蛋白质是什么意思| 9月12号是什么星座| 什么是白肺| 妇科和妇产科有什么区别| ldh是什么| 女性解脲支原体阳性吃什么药| 什么是原发性高血压| 摩羯座跟什么星座最配| 发冷是什么原因| 85年属什么的生肖| 单脐动脉对胎儿有什么影响| 雌二醇测定是什么检查| 国家的实质是什么| 晨勃消失是什么原因| 一个火一个宣念什么| 几天不大便是什么原因| 龈颊沟在什么位置图片| meme什么意思| 腰椎生理曲度变直什么意思| 透骨草治什么病最有效| 便秘有什么症状| 全身痒是什么病的前兆| 虾与什么食物相克| 醒酒是什么意思| 手指头脱皮是什么原因| 西洋参不能和什么一起吃| 梦见虱子是什么意思| 食管反流吃什么药最好| 狡兔三窟是什么生肖| 天蝎什么象星座| 甲钴胺片是什么药| 纳财适合做什么| 脉细是什么意思| 经常想吐恶心是什么原因| 云为什么是白色的| 惊恐发作是什么病| 肝硬化吃什么食物好| 每天吃松子有什么好处| 百度

56个项目入选“互联网+”、人工智能创新发展和数字经济试点重大工程

百度   《通知》专门强调,把打击黑恶势力犯罪和反腐败、基层“拍蝇”结合起来,把扫黑除恶和加强基层组织建设结合起来。

How Multiplexing Changes Your HTTP APIs

Sunday, 13 October 2019

HTTP

When I first learned about SPDY, I was excited about it for a number of reasons, but near the top of the list was its potential impact on APIs that use HTTP.

While HTTP is great for APIs for a number of reasons, one of the problems that many APIs come up against is one of granularity; it’s most useful to have fine-grained APIs, so that you’re only returning the information that the client needs, but that leads to clients needing to make lots of requests to get everything they need.

For example, if your API is about widgets, you probably want to expose a URL for each widget, so that clients can just access the widgets they’re interested in.

GET /widget/5382894223 HTTP/1.1
Accept: application/widget+json
Host: api.widgets.org
Accept-Encoding: gzip, deflate
User-Agent: BobsWidgetClient/1.5

However, in HTTP/1, requests are expensive, and an API designed like this quickly runs into practical problems; if a client needs to find out about forty specific widgets, 40 requests need to be made. Besides the overhead of transmitting all of those requests (at about 150 bytes each, as per above, that’s almost 6K), the client has an awkward decision about how to transmit them:

  1. It can use a single connection for all 40 requests. Practically speaking, this means that the minimum time to service all of the requests is 40 round trips between the client and server (plus a few more for connection setup). Even if can use HTTP pipelining (which is often problematic), any delay in producing one of the responses will block all of those behind it.

  2. It can use a single connection per request, so that none of them blocks the others. However, this means that the client will use 40 connections, which take time to open, consume resources, and will very often cause TCP congestion problems, which adds – not removes – significant delays and inefficiency, due to retransmission.

  3. It can use a smaller number of connections to spread out the load, reducing (but not removing) the risk of congestion issues without requiring the requests to be completely serialised. This is effectively the compromise position; it won’t necessarily take 40 round trips, but it’ll be at least 40 divided by the number of connections used. Also, delay on one response will still block the responses “behind” it on that same connection – meaning that performance will vary depending on a number of factors. And variance in performance is often worse than consistent delay.

Some APIs try to dodge this choice by offering a URL that clients can GET or POST a “batch” request to, e.g.,

GET /widgets/5382894223,35223231,534232313,5231332435 HTTP/1.1
Accept: application/widgets+json
Host: api.widgets.org
Accept-Encoding: gzip, deflate
User-Agent: BobsWidgetClient/1.5

However, this approach has a number of downsides. Both the service and clients need to understand a new endpoint, and a new list-based format, bloating the API – especially if there are many different types of resources that need similar treatment. Furthermore, this approach seriously impacts cache efficiency, creating further server load and client-perceived latency.

This has also been one of the factors leading to query languages like GraphQL being developed; if you can describe precisely what you want to the server in an efficient format, it can reply with just what you want.

This awkward choice is also faced by Web browsers when using HTTP/1 to request all of the various assets on a Web page, and led to the design of SPDY, which served as input to HTTP/2. HTTP/2 is fundamentally different to HTTP/1 in several ways, but multiplexing – the ability to have multiple requests and responses in flight on one connection – is the biggest.

Multiplexing associates each request/response exchange with a stream ID, and uses that to make sure that the chunks of each aren’t mixed up when they’re transmitted, no matter how they’re interleaved. It means that you can use only one connection without sacrificing performance due to Head of Line Blocking.

The above is probably not news to most, but I suspect the implications for API design aren’t fully apparent. On the wire, HTTP/2 (and soon, HTTP/3) allows you to express a large number of requests in a very compact way.

To give a very simplistic example, consider this script, which makes 40 concurrent HTTP/2 requests with nghttp2:

#!/bin/bash

URLS=""
for i in {1..40}
do
    URLS+="http://localhost:8443/widgets/${i}/whatever "
done

nghttp -y --no-dep $URLS

If you watch that in Wireshark, you’ll see those 40 requests go by in one 1440 byte packet. Here’s the relevant bits of the text dump (with some details elided and lines folded):

No. 11  Time 0.002228  Source ::1  src port 56623  destination ::1
Protocol HTTP2  Length 1440   Information
Magic, SETTINGS[0],
HEADERS[1]: GET /widgets/1/whatever,
HEADERS[3]: GET /widgets/2/whatever,
HEADERS[5]: GET /widgets/3/whatever,
HEADERS[7]: GET /widgets/4/whatever,
...
HEADERS[75]: GET /widgets/38/whatever,
HEADERS[77]: GET /widgets/39/whatever,
HEADERS[79]: GET /widgets/40/whatever

Frame 11: 1440 bytes on wire (11520 bits),
    1440 bytes captured (11520 bits) on interface 0
Null/Loopback
Internet Protocol Version 6, Src: ::1, Dst: ::1
Transmission Control Protocol
    Source Port: 56623
    Destination Port: 8443
    [Stream index: 0]
    [TCP Segment Len: 1364]
    TCP payload (1364 bytes)

Most of the individual requests are 23 or so bytes, so you should be able to fit about 400 requests like this in the first 10 packets (the most common initial CWND) of a connection before any further requests need to wait for an ACK. No worries about Head of Line blocking, congestion events due to multiple connections, or bloat.

The responses come back efficiently too; as soon as the server has part of a response available, it can send it, constrained only by available bandwidth. In particular, if a cache is between the server and client, it can fill the available bandwidth while the server answers uncached requests – making the most of the resources available.

This is pretty powerful. Without too much exaggeration, another way to think of HTTP/2 is as a new query language – one that lets you encode a very complex set of requests into a small amount of data that is heavily optimised for transmission, while still allowing standard HTTP components – especially caches – to work with the individual requests.

You might say that the URLs in my example are very similar, which isn’t realistic for many use cases. That’s true, but because of the way that HPACK header compression works, that doesn’t matter too much; forty requests for any URL paths of about that length would encode to be about the same size.

There are, of course, other reasons to use batch endpoints or specialised query languages; in particular, if some of your requests have side effects that are visible in others that you’re making, so that their processing order is important.

It’s also early days for HTTP/2 clients; while it’s well established in browsers, it’s just starting to be available and usable as a library in many languages (hint: try libcurl). Your server implementation will also need to be carefully considered to exploit this kind of request pattern; many will need rethinking before they can handle 40 or 400 concurrent requests on one connection efficiently (but it is possible; caching can help tremendously, as can consider outstanding requests as a pool, rather than in isolation).

With all of those caveats noted, HTTP/2 should put to rest any notion of the need to minimise the number of requests for APIs; the protocol makes them cheap enough to not practically matter. Go ahead and design a highly granular HTTP API to meet the needs of your clients.


枕芯是什么 美女什么都没有穿 钨砂是什么东西 补办港澳通行证需要什么材料 anti是什么意思
胃疼喝什么能缓解疼痛 ecg医学上什么意思 老打嗝是什么原因 眼结石是什么原因引起的 刻章需要什么材料
膝盖酸是什么原因 黑鱼又叫什么鱼 lam是什么意思 你代表什么意思 突然流鼻血是什么原因
米诺地尔搽剂和米诺地尔酊有什么区别 女左上眼皮跳是什么预兆 柱镜度数是什么意思 tea什么意思 立夏什么时候
daily是什么意思jasonfriends.com 1988是什么年hcv8jop3ns1r.cn 绝经后吃什么能来月经hcv7jop7ns2r.cn 绝对零度是什么意思hcv9jop0ns0r.cn 做梦梦见火是什么意思hcv8jop6ns5r.cn
肚子一按就痛什么原因hcv9jop4ns0r.cn 丸美属于什么档次hcv8jop6ns4r.cn 青绿色是什么颜色hcv8jop6ns7r.cn 金牛座跟什么星座最配ff14chat.com 嘴角发麻是什么病前兆hcv8jop6ns3r.cn
结婚唱什么歌送给新人hcv8jop5ns1r.cn 血细胞分析是查什么的hcv9jop6ns6r.cn 电轴左偏是什么意思hcv9jop6ns8r.cn 梦到掉牙齿是什么意思hcv8jop5ns9r.cn 心肌缺血吃什么中药hcv7jop6ns3r.cn
为什么不能近亲结婚hcv8jop2ns6r.cn 12580是什么号码hcv8jop4ns4r.cn 淡墨是什么意思hlguo.com 女生取什么名字好听hcv9jop4ns6r.cn 黑枸杞和什么一起泡水喝比较好hcv9jop1ns1r.cn
百度