Fastify와 Springboot: Hello World 성능 비교

Apr 07 2023
Node의 네이티브 HTTP 서버를 Spring과 비교한 이전 기사에서 비교가 공정하지 않다는 의견을 받았습니다. Spring은 프레임워크이므로 Node 측의 프레임워크인 Express, Fastify, Nest와 비교해야 합니다.

Node의 기본 HTTP 서버를 Spring과 비교한 이전 기사 중 하나에서 비교가 공정하지 않다는 의견을 받았습니다. Spring은 프레임워크이므로 Express, Fastify, Nest.js 등과 같은 노드 측 프레임워크와 비교해야 합니다. 매우 유효한 포인트입니다.

최근에 익스프레스와 스프링을 비교 했는데 예상대로 스프링이 승자로 떠올랐다.

이 기사에서는 널리 사용되는 다른 프레임워크인 fastify를 spring과 비교합니다. fastify가 express보다 훨씬 빠르다는 것은 잘 알려져 있습니다. 나는 그것이 봄보다 더 나은 성능을 기대합니다. 테스트 설정은 16G RAM이 장착된 MacBook M1과 동일합니다. Node.js v19.7.0은 Java 17을 통해 Spring 3.0.2와 비교됩니다.

코드는 다음과 같습니다.

Node.js

import Fastify from "fastify";
const fastify = Fastify({ logger: false });

fastify.get("/", () => {
  return "Hello world!";
});

fastify.listen({ port: 3000 });

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemoApplication {

  public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
  }

  @GetMapping("/")
  public String handleRequest() {
    return "Hello World!";
  }
}

결과로 바로 이동하겠습니다.

Spring에 비해 상당히 느렸던 express와 달리 fastify는 상당히 빠른 것으로 나타났습니다. Fastify는 낮은 CPU 및 메모리 사용량으로 더 많은 RPS를 제공합니다.

우승자 : Fastify

익스프레스와의 비교는 여기에서 볼 수 있습니다 .