Giter VIP home page Giter VIP logo

Comments (12)

mcollina avatar mcollina commented on May 23, 2024 2

Nope. I was not able to create a deterministic environment locally. I will try again

No need, I tracked it down.


What is happening is that undici is establishing a new connection for every POST, and we are paying the TLS price. This behavior is correct but strict, as in certain cases, the connection can be kept open.

This was introduced by @ronag in #76, and it made things too strict.

@ronag wdyt?

from undici.

Gigioliva avatar Gigioliva commented on May 23, 2024 1

Hi @mcollina

Thank you for your time. After some investigation, we found the problem. The default value of keepAliveTimeout is 4 seconds. By scaling the number of pods in our application, requests were being distributed across too many pods causing some connections to remain idle for more than 4 seconds (and thus closed). Increasing that value to 60 seconds significantly improved the performance.

Sorry for the issue. I think we can close it 🙏🏼

from undici.

mcollina avatar mcollina commented on May 23, 2024

Have you got something to replicate this setup? How many http calls are you making?

from undici.

Gigioliva avatar Gigioliva commented on May 23, 2024

Have you got something to replicate this setup?

Nope. I was not able to create a deterministic environment locally. I will try again

How many http calls are you making?

We have 25/30 req/s (average)

from undici.

ronag avatar ronag commented on May 23, 2024

Yes, the implementation is too strict. Though it will require some thinking to make sure we don't introduce bugs by loosening it.

from undici.

ronag avatar ronag commented on May 23, 2024

I think the simplest way is to make pipelining equal to 1 a special case.

from undici.

Gigioliva avatar Gigioliva commented on May 23, 2024

I think the simplest way is to make pipelining equal to 1 a special case.

What about adding a new parameter to the pool configuration to let the user choose this behavior?

from undici.

ronag avatar ronag commented on May 23, 2024

@mcollina Actually I'm unsure if you are right. I don't see why it wouldn't re-use the connection, once the whole request/response cycle has completed.

from undici.

Gigioliva avatar Gigioliva commented on May 23, 2024

Application headers:

  "Content-Type": "application/x-thrift",
  "Accept": "application/x-thrift",
  "Authorization": internalAuthToken,
  "User-Agent": consumerKey,

from undici.

mcollina avatar mcollina commented on May 23, 2024

@ronag, you are right, the socket is correctly reused:

import { createServer } from 'node:http';
import { request } from './index.js';
import { setTimeout as sleep } from 'node:timers/promises';
import { strictEqual } from 'node:assert';

let lastSocket = null;
const server = createServer((req, res) => {
  console.log('request ', req.url, req.method);
  if (lastSocket)  {
    res.end(JSON.stringify({ same: lastSocket == req.socket }));
  } else {
    res.end(JSON.stringify({ noSocket: true }));
  }
  lastSocket = req.socket;
})

await new Promise((resolve) => server.listen(3000, resolve));

{
  const { body } = await request('http://localhost:3000', {
    method: 'POST',
    body: JSON.stringify({ hello: 'world' })
  });
  console.log(await body.json());
}

await sleep(1000);

{
  const { body } = await request('http://localhost:3000', {
    method: 'POST',
    body: JSON.stringify({ hello: 'world' })
  });
  const { same } = await body.json();
  strictEqual(same, true);
  console.log('same socket');
}

server.close();

So I guess that whatever combination of inputs you are using @Gigioliva is causing undici to create a new socket every time.

Can you create a small reproduction of what you are doing?

from undici.

ronag avatar ronag commented on May 23, 2024

So I guess that whatever combination of inputs

and server...

from undici.

Gigioliva avatar Gigioliva commented on May 23, 2024

Can you create a small reproduction of what you are doing?

I will try 😅 the system is quite complex to reproduce...I will start from a simple setup and add new steps until the problem also occurs locally

from undici.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.