Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

599
Visualizações
Profiling my NodeJS server shows it's hanging... But how to figure out why?

I have a NodeJS server running with NestJS and deployed on AKS.
I've created an Interceptor so that if I send a HTTP header 'profile', it will run the usual code but instead of sending the response, it will replace the body with the profile output.

Here's the code:

import {
  CallHandler, ExecutionContext, Injectable, NestInterceptor,
} from '@nestjs/common';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { Session } from 'inspector';

/**
 * This interceptor will replace the body of the response with the result of the profiling
 * if the request as a header 'profile'
 *
 * To use on a controller or a method, simply decorate it with @UseInterceptors(Profiler)
 */
@Injectable()
export class Profiler implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler): Observable<any> | Promise<Observable<any>> {
    const profile = context.switchToHttp().getRequest().get('profile');
    // if the request doesn't have a 'profile' header, we deal with the request as usual
    if (!profile) return next.handle();

    // start a profiling session
    const session = new Session();
    session.connect();

    return new Promise((resolve) => {
      session.post('Profiler.enable', () => {
        session.post('Profiler.start', () => {
          resolve(next.handle().pipe(map(() => new Promise((resolve) => {
            session.post('Profiler.stop', (_, { profile }) => {
              resolve(profile);
            });
          }))));
        });
      });
    });
  }
}

Doing so, I'm able to get a JSON which I can then open with Chrome dev tool:

Profile

You can see that all the individual functions are only taking a few ms to run but in between, there are looooong breaks.

Here's an extract of my deployment.yaml file which shows that my pod should have 2GB of memory, which I believe should be enough.

spec:
      serviceAccount: {{ include "api.fullname" . }}-service-account
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          resources:
            limits:
              memory: "2000Mi"
            requests:
              memory: "2000Mi"
          ports:
            - name: http
              containerPort: {{ .Values.port }}
              protocol: TCP

So how can we explain these long breaks and how to prevent this?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

By adding more logs around the database requests, we realised that the first few requests were taking around 2-3 seconds while the following ones were only ~10ms or less.

The solution was to use PgBouncer to maintain a connection pool with the database.
More info here: https://techcommunity.microsoft.com/t5/azure-database-for-postgresql/steps-to-install-and-setup-pgbouncer-connection-pooling-proxy/ba-p/730555

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda