Go high performance http server with Forker

Ja7ad
/
forker

Get high performance http requests with fork process

forker

Get high performance http requests with fork process (forker inspired prefork feature in…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Javad Rajabzadeh

GitHub logo Ja7ad / forker

Get high performance http requests with fork process

forker

Go Reference

Get high performance http requests with fork process (forker inspired prefork feature in web servers)

prefork is a solution which is also used by other webservers

A server instance is opened for each processor core and incoming requests are shared between these instances

In order to distribute the load more evenly and handle more requests per second, there is a master that starts by the user, which then starts child processes on the other processor cores based on configuration

memory between the different processes is not shared, beacuse goroutines are independent processes

alt text

how to install

go get -u github.com/Ja7ad/forker

forker benchmark

forker tested 500 concurrent with 200k http requests

alt text

oha -c 500 -n 200000 --latency-correction --disable-keepalive http://localhost:8080
Summary
  Success rate: 1.0000
  Total:    24.4907 secs
  Slowest:  0.5000 secs
  Fastest:  0.0004 secs
  Average:  0.0610 secs
  Requests/sec: 8166.3762

  Total data:   2.10 MiB
  Size/request: 11 B
  Size/sec: 87.72 KiB

Response time histogram:
  0.000
…

Get high performance http requests with fork process (forker inspired prefork feature in web servers)

prefork is a solution which is also used by other webservers

A server instance is opened for each processor core and incoming requests are shared between these instances

In order to distribute the load more evenly and handle more requests per second, there is a master that starts by the user, which then starts child processes on the other processor cores based on configuration

memory between the different processes is not shared, beacuse goroutines are independent processes

Image description

Benchmark With oha 200k request with 500 concurrent

Summary:
  Success rate: 1.0000
  Total:    24.4907 secs
  Slowest:  0.5000 secs
  Fastest:  0.0004 secs
  Average:  0.0610 secs
  Requests/sec: 8166.3762

  Total data:   2.10 MiB
  Size/request: 11 B
  Size/sec: 87.72 KiB

Response time histogram:
  0.000 [1]     |
  0.050 [82408] |â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– 
  0.100 [98705] |â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– â– 
  0.150 [16180] |â– â– â– â– â– 
  0.200 [2245]  |
  0.250 [361]   |
  0.300 [59]    |
  0.350 [33]    |
  0.400 [3]     |
  0.450 [1]     |
  0.500 [4]     |

Latency distribution:
  10% in 0.0291 secs
  25% in 0.0404 secs
  50% in 0.0557 secs
  75% in 0.0754 secs
  90% in 0.0989 secs
  95% in 0.1170 secs
  99% in 0.1581 secs

Details (average, fastest, slowest):
  DNS+dialup:   0.0259 secs, 0.0001 secs, 0.3010 secs
  DNS-lookup:   0.0000 secs, 0.0000 secs, 0.0239 secs

How to Install?

go get -u github.com/Ja7ad/forker

Example

package main

import (
    "github.com/Ja7ad/forker"
    "log"
    "net/http"
)

func main() {
    srv := &http.Server{
        Handler: GreetingHandler(),
    }

    f := forker.New(srv)

    log.Fatalln(f.ListenAndServe(":8080"))

}

func GreetingHandler() http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("greeting!!!"))
    }
}


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Javad Rajabzadeh


Print Share Comment Cite Upload Translate Updates
APA

Javad Rajabzadeh | Sciencx (2022-10-11T19:03:47+00:00) Go high performance http server with Forker. Retrieved from https://www.scien.cx/2022/10/11/go-high-performance-http-server-with-forker/

MLA
" » Go high performance http server with Forker." Javad Rajabzadeh | Sciencx - Tuesday October 11, 2022, https://www.scien.cx/2022/10/11/go-high-performance-http-server-with-forker/
HARVARD
Javad Rajabzadeh | Sciencx Tuesday October 11, 2022 » Go high performance http server with Forker., viewed ,<https://www.scien.cx/2022/10/11/go-high-performance-http-server-with-forker/>
VANCOUVER
Javad Rajabzadeh | Sciencx - » Go high performance http server with Forker. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/10/11/go-high-performance-http-server-with-forker/
CHICAGO
" » Go high performance http server with Forker." Javad Rajabzadeh | Sciencx - Accessed . https://www.scien.cx/2022/10/11/go-high-performance-http-server-with-forker/
IEEE
" » Go high performance http server with Forker." Javad Rajabzadeh | Sciencx [Online]. Available: https://www.scien.cx/2022/10/11/go-high-performance-http-server-with-forker/. [Accessed: ]
rf:citation
» Go high performance http server with Forker | Javad Rajabzadeh | Sciencx | https://www.scien.cx/2022/10/11/go-high-performance-http-server-with-forker/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.