Giter Club home page Giter Club logo

api-benchmark's Introduction

Go vs Node Experiment Benchmark

A comparative study of Go and Node.js performance under high-load conditions, focusing on a simple POST-based create-user endpoint inserting data into a PostgreSQL database.

Overview

This experiment benchmarks Go and Node.js APIs to understand their behavior under different load scenarios. It measures key performance metrics like latency, CPU and RAM usage, thread count, and file descriptor management.

Setup

  • Infrastructure: AWS EC2 instances, Postgres RDS.
  • Load Testing: Vegeta for HTTP load testing.
  • Languages: Go 1.21.4 and Node.js 21.4.0.
  • Monitoring: Custom scripts for capturing performance metrics.

Running the Experiment

On AWS

Prerequisites:

  • AWS account with CLI configured.
  • OpenTofu for infrastructure setup.
  • PostgreSQL RDS instance.

Steps:

  1. Infrastructure Setup:

    cd tofu
    tofu apply -auto-approve
    

    This creates the required AWS infrastructure including two Ubuntu servers.

  2. Running the API: SSH into the API server:

    ./ssh_connect_api.sh
    

    For Node API:

    cd node-api
    npm install
    npm start
    

    For Go API:

    cd go-api
    go build -o api
    ./api
    

    Note the process ID (PID) for monitoring.

  3. Performance Monitoring: Reconnect to the API server and run:

    ./monitor_process.sh [PID] [Request Rate]
    

    Replace [PID] with the actual process ID and [Request Rate] with the desired requests per second.

  4. Load Test: Connect to the gun server:

    ./ssh_connect_gun.sh
    

    Start the stress test:

    cd load-tester/vegeta
    ./metrics.sh 2000
    

Locally with Docker

  • Use docker-compose to start services:

    docker-compose up -d postgres node-api go-api
    

    Services Startup

  • Then, to run the gun server:

    docker-compose up gun
    

    After the test, you can see the core metrics on the terminal. Terminal Output

Considerations

  • This benchmark focuses on specific aspects of performance under load. It shouldn't be the sole basis for choosing a technology stack.
  • Factors like productivity, team expertise, and existing toolsets are also crucial in technology decisions.
  • In Docker Compose, prefer network_mode: host, as the docker internal networking adds considerable bottleneck
  • Adding Node.js Cluster can handle more requests/sec but also adds extra networking and coordination overhead

api-benchmark's People

Contributors

ocodista avatar akitaonrails avatar apolzek avatar

Stargazers

 avatar

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.