lucaswerkmeister / m3api

minimal modern MediaWiki API client

Home Page:https://www.npmjs.com/package/m3api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Keep connections alive in axios backend

lucaswerkmeister opened this issue · comments

Apparently axios doesn’t do HTTP Connection: keep-alive by default. There seem to be two options:

  • native http.Agent:
    axios.create( {
      httpAgent: new http.Agent( { keepAlive: true } ),
      httpsAgent: new https.Agent( { keepAlive: true } ),
    } );
  • agentkeepalive package

I should check what the advantages and drawbacks of each approach are (mainly, if the extra dependency is worth it or not).

Note that any kind of custom agent is not compatible with axios-cookiejar-support; if we want keepalive, we need to use the underlying http-cookie-agent directly. (Compare 3846masa/axios-cookiejar-support#426.)

I’m inclined to think that we don’t need the agentkeepalive package. The other major thing it seems to do that would be relevant for us is to disable Nagle’s algorithm, which Node does by default starting with version 18; I think it’s okay to keep the underlying Node default here. So we can probably use http-cookie-agent + keepAlive. (An upcoming Node release, see nodejs/node@4267b92, will enable keepalive for the default agent, but I haven’t seen any change that would make it the default for custom agents.)