replace zxq.co/ripple/hanayo
This commit is contained in:
1
vendor/github.com/valyala/fasthttp/examples/fileserver/.gitignore
generated
vendored
Normal file
1
vendor/github.com/valyala/fasthttp/examples/fileserver/.gitignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
fileserver
|
7
vendor/github.com/valyala/fasthttp/examples/fileserver/Makefile
generated
vendored
Normal file
7
vendor/github.com/valyala/fasthttp/examples/fileserver/Makefile
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
fileserver: clean
|
||||
go get -u github.com/valyala/fasthttp
|
||||
go get -u github.com/valyala/fasthttp/expvarhandler
|
||||
go build
|
||||
|
||||
clean:
|
||||
rm -f fileserver
|
84
vendor/github.com/valyala/fasthttp/examples/fileserver/README.md
generated
vendored
Normal file
84
vendor/github.com/valyala/fasthttp/examples/fileserver/README.md
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
# Static file server example
|
||||
|
||||
* Serves files from the given directory.
|
||||
* Supports transparent response compression.
|
||||
* Supports byte range responses.
|
||||
* Generates directory index pages.
|
||||
* Supports TLS (aka SSL or HTTPS).
|
||||
* Supports virtual hosts.
|
||||
* Exports various stats on /stats path.
|
||||
|
||||
# How to build
|
||||
|
||||
```
|
||||
make
|
||||
```
|
||||
|
||||
# How to run
|
||||
|
||||
```
|
||||
./fileserver -h
|
||||
./fileserver -addr=tcp.addr.to.listen:to -dir=/path/to/directory/to/serve
|
||||
```
|
||||
|
||||
# fileserver vs nginx performance comparison
|
||||
|
||||
Serving default nginx path (`/usr/share/nginx/html` on ubuntu).
|
||||
|
||||
* nginx
|
||||
|
||||
```
|
||||
$ ./wrk -t 4 -c 16 -d 10 http://localhost:80
|
||||
Running 10s test @ http://localhost:80
|
||||
4 threads and 16 connections
|
||||
Thread Stats Avg Stdev Max +/- Stdev
|
||||
Latency 397.76us 1.08ms 20.23ms 95.19%
|
||||
Req/Sec 21.20k 2.49k 31.34k 79.65%
|
||||
850220 requests in 10.10s, 695.65MB read
|
||||
Requests/sec: 84182.71
|
||||
Transfer/sec: 68.88MB
|
||||
```
|
||||
|
||||
* fileserver
|
||||
|
||||
```
|
||||
$ ./wrk -t 4 -c 16 -d 10 http://localhost:8080
|
||||
Running 10s test @ http://localhost:8080
|
||||
4 threads and 16 connections
|
||||
Thread Stats Avg Stdev Max +/- Stdev
|
||||
Latency 447.99us 1.59ms 27.20ms 94.79%
|
||||
Req/Sec 37.13k 3.99k 47.86k 76.00%
|
||||
1478457 requests in 10.02s, 1.03GB read
|
||||
Requests/sec: 147597.06
|
||||
Transfer/sec: 105.15MB
|
||||
```
|
||||
|
||||
8 pipelined requests
|
||||
|
||||
* nginx
|
||||
|
||||
```
|
||||
$ ./wrk -s pipeline.lua -t 4 -c 16 -d 10 http://localhost:80 -- 8
|
||||
Running 10s test @ http://localhost:80
|
||||
4 threads and 16 connections
|
||||
Thread Stats Avg Stdev Max +/- Stdev
|
||||
Latency 1.34ms 2.15ms 30.91ms 92.16%
|
||||
Req/Sec 33.54k 7.36k 108.12k 76.81%
|
||||
1339908 requests in 10.10s, 1.07GB read
|
||||
Requests/sec: 132705.81
|
||||
Transfer/sec: 108.58MB
|
||||
```
|
||||
|
||||
* fileserver
|
||||
|
||||
```
|
||||
$ ./wrk -s pipeline.lua -t 4 -c 16 -d 10 http://localhost:8080 -- 8
|
||||
Running 10s test @ http://localhost:8080
|
||||
4 threads and 16 connections
|
||||
Thread Stats Avg Stdev Max +/- Stdev
|
||||
Latency 2.08ms 6.33ms 88.26ms 92.83%
|
||||
Req/Sec 116.54k 14.66k 167.98k 69.00%
|
||||
4642226 requests in 10.03s, 3.23GB read
|
||||
Requests/sec: 462769.41
|
||||
Transfer/sec: 329.67MB
|
||||
```
|
120
vendor/github.com/valyala/fasthttp/examples/fileserver/fileserver.go
generated
vendored
Normal file
120
vendor/github.com/valyala/fasthttp/examples/fileserver/fileserver.go
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
// Example static file server.
|
||||
//
|
||||
// Serves static files from the given directory.
|
||||
// Exports various stats at /stats .
|
||||
package main
|
||||
|
||||
import (
|
||||
"expvar"
|
||||
"flag"
|
||||
"log"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
"github.com/valyala/fasthttp/expvarhandler"
|
||||
)
|
||||
|
||||
var (
|
||||
addr = flag.String("addr", "localhost:8080", "TCP address to listen to")
|
||||
addrTLS = flag.String("addrTLS", "", "TCP address to listen to TLS (aka SSL or HTTPS) requests. Leave empty for disabling TLS")
|
||||
byteRange = flag.Bool("byteRange", false, "Enables byte range requests if set to true")
|
||||
certFile = flag.String("certFile", "./ssl-cert-snakeoil.pem", "Path to TLS certificate file")
|
||||
compress = flag.Bool("compress", false, "Enables transparent response compression if set to true")
|
||||
dir = flag.String("dir", "/usr/share/nginx/html", "Directory to serve static files from")
|
||||
generateIndexPages = flag.Bool("generateIndexPages", true, "Whether to generate directory index pages")
|
||||
keyFile = flag.String("keyFile", "./ssl-cert-snakeoil.key", "Path to TLS key file")
|
||||
vhost = flag.Bool("vhost", false, "Enables virtual hosting by prepending the requested path with the requested hostname")
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Parse command-line flags.
|
||||
flag.Parse()
|
||||
|
||||
// Setup FS handler
|
||||
fs := &fasthttp.FS{
|
||||
Root: *dir,
|
||||
IndexNames: []string{"index.html"},
|
||||
GenerateIndexPages: *generateIndexPages,
|
||||
Compress: *compress,
|
||||
AcceptByteRange: *byteRange,
|
||||
}
|
||||
if *vhost {
|
||||
fs.PathRewrite = fasthttp.NewVHostPathRewriter(0)
|
||||
}
|
||||
fsHandler := fs.NewRequestHandler()
|
||||
|
||||
// Create RequestHandler serving server stats on /stats and files
|
||||
// on other requested paths.
|
||||
// /stats output may be filtered using regexps. For example:
|
||||
//
|
||||
// * /stats?r=fs will show only stats (expvars) containing 'fs'
|
||||
// in their names.
|
||||
requestHandler := func(ctx *fasthttp.RequestCtx) {
|
||||
switch string(ctx.Path()) {
|
||||
case "/stats":
|
||||
expvarhandler.ExpvarHandler(ctx)
|
||||
default:
|
||||
fsHandler(ctx)
|
||||
updateFSCounters(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
// Start HTTP server.
|
||||
if len(*addr) > 0 {
|
||||
log.Printf("Starting HTTP server on %q", *addr)
|
||||
go func() {
|
||||
if err := fasthttp.ListenAndServe(*addr, requestHandler); err != nil {
|
||||
log.Fatalf("error in ListenAndServe: %s", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// Start HTTPS server.
|
||||
if len(*addrTLS) > 0 {
|
||||
log.Printf("Starting HTTPS server on %q", *addrTLS)
|
||||
go func() {
|
||||
if err := fasthttp.ListenAndServeTLS(*addrTLS, *certFile, *keyFile, requestHandler); err != nil {
|
||||
log.Fatalf("error in ListenAndServeTLS: %s", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
log.Printf("Serving files from directory %q", *dir)
|
||||
log.Printf("See stats at http://%s/stats", *addr)
|
||||
|
||||
// Wait forever.
|
||||
select {}
|
||||
}
|
||||
|
||||
func updateFSCounters(ctx *fasthttp.RequestCtx) {
|
||||
// Increment the number of fsHandler calls.
|
||||
fsCalls.Add(1)
|
||||
|
||||
// Update other stats counters
|
||||
resp := &ctx.Response
|
||||
switch resp.StatusCode() {
|
||||
case fasthttp.StatusOK:
|
||||
fsOKResponses.Add(1)
|
||||
fsResponseBodyBytes.Add(int64(resp.Header.ContentLength()))
|
||||
case fasthttp.StatusNotModified:
|
||||
fsNotModifiedResponses.Add(1)
|
||||
case fasthttp.StatusNotFound:
|
||||
fsNotFoundResponses.Add(1)
|
||||
default:
|
||||
fsOtherResponses.Add(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Various counters - see https://golang.org/pkg/expvar/ for details.
|
||||
var (
|
||||
// Counter for total number of fs calls
|
||||
fsCalls = expvar.NewInt("fsCalls")
|
||||
|
||||
// Counters for various response status codes
|
||||
fsOKResponses = expvar.NewInt("fsOKResponses")
|
||||
fsNotModifiedResponses = expvar.NewInt("fsNotModifiedResponses")
|
||||
fsNotFoundResponses = expvar.NewInt("fsNotFoundResponses")
|
||||
fsOtherResponses = expvar.NewInt("fsOtherResponses")
|
||||
|
||||
// Total size in bytes for OK response bodies served.
|
||||
fsResponseBodyBytes = expvar.NewInt("fsResponseBodyBytes")
|
||||
)
|
28
vendor/github.com/valyala/fasthttp/examples/fileserver/ssl-cert-snakeoil.key
generated
vendored
Normal file
28
vendor/github.com/valyala/fasthttp/examples/fileserver/ssl-cert-snakeoil.key
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQD4IQusAs8PJdnG
|
||||
3mURt/AXtgC+ceqLOatJ49JJE1VPTkMAy+oE1f1XvkMrYsHqmDf6GWVzgVXryL4U
|
||||
wq2/nJSm56ddhN55nI8oSN3dtywUB8/ShelEN73nlN77PeD9tl6NksPwWaKrqxq0
|
||||
FlabRPZSQCfmgZbhDV8Sa8mfCkFU0G0lit6kLGceCKMvmW+9Bz7ebsYmVdmVMxmf
|
||||
IJStFD44lWFTdUc65WISKEdW2ELcUefb0zOLw+0PCbXFGJH5x5ktksW8+BBk2Hkg
|
||||
GeQRL/qPCccthbScO0VgNj3zJ3ZZL0ObSDAbvNDG85joeNjDNq5DT/BAZ0bOSbEF
|
||||
sh+f9BAzAgMBAAECggEBAJWv2cq7Jw6MVwSRxYca38xuD6TUNBopgBvjREixURW2
|
||||
sNUaLuMb9Omp7fuOaE2N5rcJ+xnjPGIxh/oeN5MQctz9gwn3zf6vY+15h97pUb4D
|
||||
uGvYPRDaT8YVGS+X9NMZ4ZCmqW2lpWzKnCFoGHcy8yZLbcaxBsRdvKzwOYGoPiFb
|
||||
K2QuhXZ/1UPmqK9i2DFKtj40X6vBszTNboFxOVpXrPu0FJwLVSDf2hSZ4fMM0DH3
|
||||
YqwKcYf5te+hxGKgrqRA3tn0NCWii0in6QIwXMC+kMw1ebg/tZKqyDL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p/examples/fileserver/ssl-cert-snakeoil.pem
generated
vendored
Normal file
17
vendor/github.com/valyala/fasthttp/examples/fileserver/ssl-cert-snakeoil.pem
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICujCCAaKgAwIBAgIJAMbXnKZ/cikUMA0GCSqGSIb3DQEBCwUAMBUxEzARBgNV
|
||||
BAMTCnVidW50dS5uYW4wHhcNMTUwMjA0MDgwMTM5WhcNMjUwMjAxMDgwMTM5WjAV
|
||||
MRMwEQYDVQQDEwp1YnVudHUubmFuMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
|
||||
CgKCAQEA+CELrALPDyXZxt5lEbfwF7YAvnHqizmrSePSSRNVT05DAMvqBNX9V75D
|
||||
K2LB6pg3+hllc4FV68i+FMKtv5yUpuenXYTeeZyPKEjd3bcsFAfP0oXpRDe955Te
|
||||
+z3g/bZejZLD8Fmiq6satBZWm0T2UkAn5oGW4Q1fEmvJnwpBVNBtJYrepCxnHgij
|
||||
L5lvvQc+3m7GJlXZlTMZnyCUrRQ+OJVhU3VHOuViEihHVthC3FHn29Mzi8PtDwm1
|
||||
xRiR+ceZLZLFvPgQZNh5IBnkES/6jwnHLYW0nDtFYDY98yd2WS9Dm0gwG7zQxvOY
|
||||
6HjYwzauQ0/wQGdGzkmxBbIfn/QQMwIDAQABow0wCzAJBgNVHRMEAjAAMA0GCSqG
|
||||
SIb3DQEBCwUAA4IBAQBQjKm/4KN/iTgXbLTL3i7zaxYXFLXsnT1tF+ay4VA8aj98
|
||||
L3JwRTciZ3A5iy/W4VSCt3eASwOaPWHKqDBB5RTtL73LoAqsWmO3APOGQAbixcQ2
|
||||
45GXi05OKeyiYRi1Nvq7Unv9jUkRDHUYVPZVSAjCpsXzPhFkmZoTRxmx5l0ZF7Li
|
||||
K91lI5h+eFq0dwZwrmlPambyh1vQUi70VHv8DNToVU29kel7YLbxGbuqETfhrcy6
|
||||
X+Mha6RYITkAn5FqsZcKMsc9eYGEF4l3XV+oS7q6xfTxktYJMFTI18J0lQ2Lv/CI
|
||||
whdMnYGntDQBE/iFCrJEGNsKGc38796GBOb5j+zd
|
||||
-----END CERTIFICATE-----
|
Reference in New Issue
Block a user