{"id":22166327,"url":"https://github.com/alextanhongpin/node-performance","last_synced_at":"2026-04-22T21:32:38.670Z","repository":{"id":79115142,"uuid":"122714692","full_name":"alextanhongpin/node-performance","owner":"alextanhongpin","description":"Studying patterns of rate-limiting nodejs api in order to handle spike traffic","archived":false,"fork":false,"pushed_at":"2018-03-05T06:46:20.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T16:21:16.530Z","etag":null,"topics":["nginx"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alextanhongpin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-24T07:18:32.000Z","updated_at":"2018-03-03T12:30:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"bcaee1b6-9c04-443b-8fe4-a33a4dbe09a8","html_url":"https://github.com/alextanhongpin/node-performance","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alextanhongpin/node-performance","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alextanhongpin%2Fnode-performance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alextanhongpin%2Fnode-performance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alextanhongpin%2Fnode-performance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alextanhongpin%2Fnode-performance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alextanhongpin","download_url":"https://codeload.github.com/alextanhongpin/node-performance/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alextanhongpin%2Fnode-performance/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263421911,"owners_count":23464047,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nginx"],"created_at":"2024-12-02T05:19:05.965Z","updated_at":"2026-04-22T21:32:38.587Z","avatar_url":"https://github.com/alextanhongpin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Tips\n\n1. Set `NODE_ENV = production` \n2. use the `cluster` module\n\nab -n 1000 -c 1 http://localhost:3000/\n\nsiege -c 100 -t 30s http://localhost:3000/\n\nwrk -t4 -c100 -d30s --latency http://localhost:3000/\n\n\n## With ab, without cache\n\n```\nServer Software:\nServer Hostname:        localhost\nServer Port:            3000\n\nDocument Path:          /\nDocument Length:        21 bytes\n\nConcurrency Level:      1\nTime taken for tests:   4.110 seconds\nComplete requests:      1000\nFailed requests:        0\nTotal transferred:      228000 bytes\nHTML transferred:       21000 bytes\nRequests per second:    243.30 [#/sec] (mean)\nTime per request:       4.110 [ms] (mean)\nTime per request:       4.110 [ms] (mean, across all concurrent requests)\nTransfer rate:          54.17 [Kbytes/sec] received\n\nConnection Times (ms)\n              min  mean[+/-sd] median   max\nConnect:        0    0   0.2      0       4\nProcessing:     1    4  42.2      1     681\nWaiting:        0    4  42.2      1     681\nTotal:          1    4  42.2      1     681\n\nPercentage of the requests served within a certain time (ms)\n  50%      1\n  66%      1\n  75%      1\n  80%      1\n  90%      2\n  95%      3\n  98%      5\n  99%     13\n 100%    681 (longest request)\n ```\n\n## With nginx cache\n\n```\nServer Software:        nginx/1.13.9\nServer Hostname:        localhost\nServer Port:            4000\n\nDocument Path:          /\nDocument Length:        21 bytes\n\nConcurrency Level:      1\nTime taken for tests:   1.773 seconds\nComplete requests:      1000\nFailed requests:        0\nTotal transferred:      271000 bytes\nHTML transferred:       21000 bytes\nRequests per second:    564.17 [#/sec] (mean)\nTime per request:       1.773 [ms] (mean)\nTime per request:       1.773 [ms] (mean, across all concurrent requests)\nTransfer rate:          149.31 [Kbytes/sec] received\n\nConnection Times (ms)\n              min  mean[+/-sd] median   max\nConnect:        0    0   0.2      0       4\nProcessing:     1    2   0.8      1      10\nWaiting:        1    2   0.8      1      10\nTotal:          1    2   0.9      1      11\nWARNING: The median and mean for the processing time are not within a normal deviation\n        These results are probably not that reliable.\nWARNING: The median and mean for the waiting time are not within a normal deviation\n        These results are probably not that reliable.\nWARNING: The median and mean for the total time are not within a normal deviation\n        These results are probably not that reliable.\n\nPercentage of the requests served within a certain time (ms)\n  50%      1\n  66%      2\n  75%      2\n  80%      2\n  90%      2\n  95%      3\n  98%      5\n  99%      6\n 100%     11 (longest request)\n```\n\n## TODO\n\n```nginx.conf\n# This number should be, at maximum, the number of CPU cores on your system. \n# (since nginx doesn't benefit from more than one worker per CPU.)\nworker_processes 8;\n \n \n# Determines how many clients will be served by each worker process.\n# (Max clients = worker_connections * worker_processes)\n# \"Max clients\" is also limited by the number of socket connections available on the system (~64k)\n# run ss -s  and u'll see a timewait param\n# The reason for TIMED_WAIT is to handle the case of packets arriving after the socket is closed. \n# This can happen because packets are delayed or the other side just doesn't know that the socket has been closed.\n#\n# From the point of view of the client (nginx)\n#   sysctl net.ipv4.ip_local_port_range\n# \tsysctl net.ipv4.tcp_fin_timeout\n# \tResult:\n#\t\tnet.ipv4.ip_local_port_range = 32768 61000\n#\t\tnet.ipv4.tcp_fin_timeout = 60  (in other words it causes the TIMED_WAIT)\n# \t(61000 - 32768) / 60 = 470 sockets at any given time\n# \tYou can tune these values in order to get more sockets available at a time\n#\n# \tAnother option would be:\n#\t\tnet.ipv4.tcp_tw_recycle = 1\n#\t\tnet.ipv4.tcp_tw_reuse = 1 \n# \tIn order to allow used sockets in WAIT state, to be reused\n#\n# From the point of view of the server (node process)\n#\t\tsysctl net.core.somaxconn\n# \tIt limits the maximum number of requests queued to a listen socket. You can increase it.\n# \tThe value of somaxconn is the size of the listen queue.\n# \tOnce the connection is established it is no longer in the listen queue and this number doesn't matter. \n# \tIf the listen queue is filled up due to to many simultaneous connection requests then additional connections will be refused.\n# \tDefaults to 128. The value should be raised substantially to support bursts of request. \n# \tFor example, to support a burst of 1024 requests, set somaxconn to 1024.\n#\tnet.core.netdev_max_backlog and net.ipv4.tcp_max_syn_backlog\nworker_connections 4000;\n \n \n# essential for linux, optmized to serve many clients with each thread (efficient method used on Linux 2.6+.)\nuse epoll;\n \n \n# Accept as many connections as possible, after nginx gets notification about a new connection.\n# May flood worker_connections, if that option is set too low.\nmulti_accept on;\n\n\n\n\n# Open files\n# How to know how much open files u consume?\n#\tulimit -n   # open files limit per process\n#\tlsof | grep nginx | wc -l  # count how many open files an app is taking\n#\tcat /proc/sys/fs/file-max    # get max open files allowed\n\n# Number of file descriptors used for Nginx. This is set in the OS with 'ulimit -n 200000'\n# or using /etc/security/limits.conf\n# Edit /etc/security/limits.conf in order to increase hard and soft opened files allowed\n#\t* hard nproc 200000\n#\t* soft nproc 200000\nworker_rlimit_nofile 200000;\n\n\n# Caches information about open FDs, freqently accessed files.\n# Changing this setting, in my environment, brought performance up from 560k req/sec, to 904k req/sec.\n# I recommend using some varient of these options, though not the specific values listed below.\nopen_file_cache max=200000 inactive=5s; \nopen_file_cache_valid 15s; \nopen_file_cache_min_uses 1;\nopen_file_cache_errors off;\n \n \n# Buffer log writes to speed up IO, or disable them altogether\n#access_log /var/log/nginx/access.log main buffer=16k;\naccess_log off;\n \n \n# Sendfile copies data between one FD and other from within the kernel. \n# More efficient than read() + write(), since the requires transferring data to and from the user space.\nsendfile on; \n \n \n# Tcp_nopush causes nginx to attempt to send its HTTP response head in one packet, \n# instead of using partial frames. This is useful for prepending headers before calling sendfile, \n# or for throughput optimization.\ntcp_nopush on;\n \n \n# don't buffer data-sends (disable Nagle algorithm). Good for sending frequent small bursts of data in real time.\ntcp_nodelay on; \n \n \n# Timeout for keep-alive connections. Server will close connections after this time.\nkeepalive_timeout 3;\n \n \n# Number of requests a client can make over the keep-alive connection. This is set high for testing.\nkeepalive_requests 100;\n \n \n# allow the server to close the connection after a client stops responding. Frees up socket-associated memory.\nreset_timedout_connection on;\n \n \n# send the client a \"request timed out\" if the body is not loaded by this time. Default 60.\nclient_body_timeout 10;\n \n \n# If the client stops reading data, free up the stale client connection after this much time. Default 60.\nsend_timeout 2;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falextanhongpin%2Fnode-performance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falextanhongpin%2Fnode-performance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falextanhongpin%2Fnode-performance/lists"}