# Use of Keep-Alive header on the web?

**URL:** <https://discuss.httparchive.org/t/use-of-keep-alive-header-on-the-web/794>\
**Category:** Analysis\
**Created:** [July 25, 2016, 11:38am UTC](https://discuss.httparchive.org/t/use-of-keep-alive-header-on-the-web/794 "2016-07-25T11:38:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![igrigorik](https://yyz1.discourse-cdn.com/flex035/user_avatar/discuss.httparchive.org/igrigorik/32/925_2.png) [@igrigorik](https://discuss.httparchive.org/u/igrigorik)\
**Post date:** [July 25, 2016, 11:38am UTC](https://discuss.httparchive.org/t/use-of-keep-alive-header-on-the-web/794/1 "2016-07-25T11:38:36Z")

</div>

```sql
SELECT timeout, count(*) as cnt,
  RATIO_TO_REPORT(CNT) OVER ()
FROM (
  SELECT REGEXP_EXTRACT(headers, r'Keep-Alive","value":"timeout=(\d+)') as timeout
  FROM (
    SELECT 
    JSON_EXTRACT(payload, '$.response.headers') as headers
    FROM [httparchive:har.2016_07_01_chrome_requests]
  ) resp
)
GROUP BY timeout
ORDER BY cnt DESC

```

Data for 07/16 run (top 500K alexa):  
 ![](https://canada1.discourse-cdn.com/flex035/uploads/httparchive/original/1X/f44e9b5e43040488f9194687034b8fa8ae24cde5.png)

~17% requests specify [Keep-Alive header](https://tools.ietf.org/id/draft-thomson-hybi-http-timeout-01.html), with 5, 15, and 2 seconds (yikes) as most popular values.

---

<div class="post-metadata">

**Author:** ![raghuramakrishnan](https://yyz1.discourse-cdn.com/flex035/user_avatar/discuss.httparchive.org/raghuramakrishnan/32/924_2.png) [@raghuramakrishnan](https://discuss.httparchive.org/u/raghuramakrishnan)\
**Post date:** [November 2, 2017, 6:30pm UTC](https://discuss.httparchive.org/t/use-of-keep-alive-header-on-the-web/794/2 "2017-11-02T18:30:03Z")

</div>

Wanted to revisit the above in a different manner i.e. distribution of % of requests in a page having keep-alive in response header.

SELECT bucket, count(keepAliveRatio)  
FROM  
(  
SELECT  
keepAlive/reqTotal keepAliveRatio,  
ROUND(keepAlive/reqTotal \* 100, 0) bucket  
FROM  
(  
SELECT  
COUNT(\*) reqTotal,  
SUM(IF(resp\_connection = “keep-alive”,1,0)) keepAlive,  
FROM httparchive.runs.2017\_08\_01\_requests  
GROUP BY pageid  
)  
)  
GROUP BY bucket  
ORDER BY bucket ASC

![image](https://canada1.discourse-cdn.com/flex035/uploads/httparchive/original/1X/21b7a7d303d501061150f0612ad0306ec47e111b.png)

It appears a large number of web pages have less than 50% of their responses with keep-alive. It would be interesting to see if this is because of requests to third party sites.

To check the overall use of keep-alive, used the following query.

SELECT  
SUM(IF(resp\_connection = “keep-alive”,1,0)) keepAliveOn,  
SUM(IF(resp\_connection != “keep-alive”,1,0)) keepAliveOff  
FROM httparchive.runs.2017\_08\_01\_requests

![image](https://canada1.discourse-cdn.com/flex035/uploads/httparchive/original/1X/903d51f34f4fc00bb245d7a4cfe881a84f3fbf6d.png)  
T

---

<div class="post-metadata">

**Author:** ![patmeenan](https://yyz1.discourse-cdn.com/flex035/user_avatar/discuss.httparchive.org/patmeenan/32/605_2.png) [@patmeenan](https://discuss.httparchive.org/u/patmeenan)\
**Post date:** [November 2, 2017, 7:48pm UTC](https://discuss.httparchive.org/t/use-of-keep-alive-header-on-the-web/794/3 "2017-11-02T19:48:13Z")

</div>

Unless explicitly closed, HTTP 1.1 defaults to keep-alive so just having the header missing doesn’t mean it isn’t enabled. Also, for some beacon cases where you are only ever expecting a single request it might make sense to not enable.

The data should include a check from WebPageTest where it only dings pages for keep-alive if more than one request would have used the connection and if the connection is explicitly closed.

---

<div class="post-metadata">

**Author:** ![igrigorik](https://yyz1.discourse-cdn.com/flex035/user_avatar/discuss.httparchive.org/igrigorik/32/925_2.png) [@igrigorik](https://discuss.httparchive.org/u/igrigorik)\
**Post date:** [November 3, 2017, 3:44am UTC](https://discuss.httparchive.org/t/use-of-keep-alive-header-on-the-web/794/4 "2017-11-03T03:44:44Z")

</div>

+1 to Pat’s point on HTTP/1.1.

If you want to figure out adoption of long-lived connections, you should segment by http/1.0 and 1.1 and:

- (a) look for keep-alive header on http/1.0
- (b) use of `connection: close` on http/1.1

For more details, see: [https://hpbn.co/brief-history-of-http/#http11-internet-standard](https://hpbn.co/brief-history-of-http/#http11-internet-standard)
