node中请求超时的一些坑

背景 近期在做一个dns服务器切换的演练中出现了如下场景: op重启主dns服务器,期望服务访问经由另外一台从dns服务器进行解析,对线上服务无影响。但实际情况是nodejs服务耗时增加,且出现了部分502。nodejs作为站点渲染层收到请求后会利用axios库向下游服务发起http请求。我们正常情况下计算了进出nodejs的耗时大概在80毫秒以下,但是在重启主dns服务器的时间段内,nodejs耗时超过了1~3分钟。下游服务(java)耗时没有明显增加。 node版本10.16.3,axios使用版本0.19.2,请求下游服务有设置timeout: 3000,但是并未生效。所以本篇借着axios的实现说明一下在node中http模块的timeout有什么需要注意的地方。我们期待的是经过axios传递了timeout参数不论是dns查询还是tcp链接超时都能命中,但目前看并非这样。 准备工作 步骤1: 需要一个resolver.js提供dns解析能力,用来模拟慢dns查询的情况,这段代码主要来自于网络,连域名都没有改。我加了一个sleep函数是为了模拟3秒慢查询。代码如下 // The regular expression keyword in domain name. const domain = /hursing/; // When keyword matched, resolve to this IP. const targetIp = <span...

» [Read More]

Unicode

Preface Reprinted from betterexplained, I think it’s necessary to retain the original article in case it’s been removed or encounter a 404 response (swoops~). Also, some other references can be found, I recommend utf8 tool for verifying what said in this article and javascript encoding for...

» [Read More]

What am I talking about when I say TTI optimization

Unfortunately, though, the workmanlike application of those sound engineering principles isn’t always thrilling — until the software is completed on time and works without surprise. — Jon Bentley Preface Standing on date Aug 1st 2016, we talk about TTI optimization. Keep in mind that we...

» [Read More]

Issues with packaging

Release Engineering is the part of the software engineering process that is most akin to herding cats. — Chuck Rossi Preface As YUI Blog 34 golden rules had mentioned that, make minimum requests can improve Front-end performance, we often bundle javascript files into less...

» [Read More]

Holidays in Mauritius

期待毛里求斯已经有段时间了,马克吐温说这里是人间天堂。 从北京出发到香港转机,由香港飞往毛里求斯,来回总共花了9天时间,其中6天5晚在毛求度过,不过我已经决定下次要去至少住10天,原因很简单:太美了。 毛里求斯属于温带海洋性气候,夏季多雨,冬季温暖差不多是每年的5-11月,我们选择4月底5月初出行也正因为此。 第一天-第二天 迎着毛毛细雨我们乘坐的毛里求斯航空抵达了机场,入境后乘车前往提前定好的玛尔贝尔酒店。 毛里求斯航空一水的蓝色主题。 这是一家坐落在东岸,离鹿岛(ile cerf)只有10分钟车程的5星酒店,内部环境很好,接待也很有礼貌,其中有至少3名是中国接待。刚进入酒店休息区就被外面宜人的景色吸引住,此时天空已放晴。 拿到接待的欢迎函,喝了杯饮料后等待房间ready,此时会有中文接待过来讲解酒店的娱乐项目,餐厅以及毛里求斯的文化风情。不一会儿我们就拿到房卡,接待领着进入房间做了简单的电器使用介绍后便离去了,我们收拾一下后迫不及待的来到酒店海岸线,踩在细软的沙滩上,享受正午的阳光。 <img src="/assets/images/20160508/DSC_0974.JPG" alt="" style="width:100%;...

» [Read More]

Event loop in JavaScript

There are only two kinds of languages: the ones people complain about and the ones nobody uses. — Bjarne Stroustrup Preface This can be a long article, even tedious. It’s caused by a topic of process.nextTick. Javascript developer may face to setTimeout,...

» [Read More]

Cache efficiency exercise

preface This article was reprinted from post of Facebook engineering team. I have to say that Facebook web team have an excellent opinion in a perfect environment to help them improve their web performance. Their solutions in web architecture inspire me from time to time. I strongly recommend...

» [Read More]

Collapse margins in CSS

CSS2.1 Specification Snapshot from W3C 8.3.1 Collapsing margins In CSS, the adjoining margins of two or more boxes (which might or might not be siblings) can combine to form a single margin. Margins that combine this way are said to collapse, and the resulting combined margin is called a...

» [Read More]