proxy

package module
v0.0.0-...-7dcae95 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2019 License: MIT Imports: 4 Imported by: 0

README

fasthttp-reverse-proxy

Go Report Card GoReportCard

reverse http proxy hander based on fasthttp.

features:

  • proxy client has pool supported

  • faster than golang standard httputil.ReverseProxy

  • simple warpper of fasthttp.HostClient

usage

contrast

no proxy:

➜  examples git:(master) ✗ bombardier -c 125 -t 10s localhost:8080/foo
Bombarding http://localhost:8080/foo for 10s using 125 connection(s)

Done!
Statistics        Avg      Stdev        Max
  Reqs/sec     44720.43   10528.44   59074.06
  Latency        2.80ms     2.91ms   171.62ms
  HTTP codes:
    1xx - 0, 2xx - 446323, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:     8.77MB/s%

httputil.ReverseProxy:

➜  examples git:(master) ✗ bombardier -c 125 -t 10s localhost:8082/foo
Bombarding http://localhost:8082/foo for 10s using 125 connection(s)

Done!
Statistics        Avg      Stdev        Max
  Reqs/sec      5772.12    1370.75    9986.58
  Latency       21.66ms     9.32ms   173.96ms
  HTTP codes:
    1xx - 0, 2xx - 57731, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:     1.13MB/s%

yeqown.fasthttp.ReverseProxy:

➜  examples git:(master) ✗ bombardier -c 125 -t 10s localhost:8081/foo
Bombarding http://localhost:8081/foo for 10s using 125 connection(s)

Done!
Statistics        Avg      Stdev        Max
  Reqs/sec     29587.28    3392.08   37173.86
  Latency        4.22ms     2.45ms   149.31ms
  HTTP codes:
    1xx - 0, 2xx - 295646, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:     6.31MB/s%

yeqown.fasthttp.ReverseProxyWithPool:

➜  ~ bombardier -c 125 -t 10s localhost:8083/foo
Bombarding http://localhost:8083/foo for 10s using 125 connection(s)

Done!
Statistics        Avg      Stdev        Max
  Reqs/sec     11914.93    1935.58   16369.31
  Latency       10.48ms     2.23ms    72.94ms
  HTTP codes:
    1xx - 0, 2xx - 118995, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:     2.71MB/s%

Documentation

Overview

Package proxy of reverse handler based fasthttp this lib ref to: Issue: https://github.com/valyala/fasthttp/issues/64 Code: https://golang.org/src/net/http/httputil/reverseproxy.go Pool Ref: https://github.com/fatih/pool/blob/master/channel.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory func(string) (*ReverseProxy, error)

Factory the generator to creat ReverseProxy

type Pool

type Pool interface {
	// Get returns a new ReverseProxy from the pool.
	Get(string) (*ReverseProxy, error)

	// Put Reseting the ReverseProxy puts it back to the Pool.
	Put(*ReverseProxy) error

	// Close closes the pool and all its connections. After Close() the pool is
	// no longer usable.
	Close()

	// Len returns the current number of connections of the pool.
	Len() int
}

Pool interface ... this interface ref to: https://github.com/fatih/pool/blob/master/pool.go

func NewChanPool

func NewChanPool(initialCap, maxCap int, factory Factory) (Pool, error)

NewChanPool to new a pool with some params

type ReverseProxy

type ReverseProxy struct {
	// contains filtered or unexported fields
}

ReverseProxy reverse handler using fasthttp.HostClient

func NewReverseProxy

func NewReverseProxy(addr string) *ReverseProxy

NewReverseProxy ...

func (*ReverseProxy) Close

func (p *ReverseProxy) Close()

Close ...

func (*ReverseProxy) Reset

func (p *ReverseProxy) Reset()

Reset ...

func (*ReverseProxy) ServeHTTP

func (p *ReverseProxy) ServeHTTP(ctx *fasthttp.RequestCtx)

ServeHTTP ReverseProxy to serve ref to: https://golang.org/src/net/http/httputil/reverseproxy.go#L169

func (*ReverseProxy) SetClient

func (p *ReverseProxy) SetClient(addr string) *ReverseProxy

SetClient ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL