Comments (4)
I cannot reproduce this bug on the master branch:
$ GOOS=linux GOARCH=arm go build -v github.com/valyala/fasthttp
runtime
errors
sync/atomic
unicode
unicode/utf8
container/list
math
crypto/subtle
sync
sort
io
syscall
hash
crypto/cipher
bytes
strings
bufio
crypto/hmac
internal/singleflight
time
internal/syscall/unix
strconv
math/rand
crypto/aes
crypto
reflect
crypto/sha512
crypto/md5
crypto/rc4
crypto/sha1
crypto/sha256
encoding/base64
os
encoding/pem
path/filepath
net
encoding/binary
fmt
io/ioutil
crypto/des
math/big
encoding/hex
log
mime
mime/quotedprintable
runtime/debug
crypto/elliptic
encoding/asn1
crypto/rand
crypto/rsa
crypto/dsa
crypto/x509/pkix
crypto/ecdsa
crypto/x509
net/textproto
mime/multipart
crypto/tls
github.com/valyala/fasthttp
Try updating fasthttp. This bug seems to be fixed in the issue #7 .
from fasthttp.
yep that fixed it, thanks!
from fasthttp.
@valyala Side note: still getting fairly low results using both apache2 benchmark utils and siege for testing rps.
I'm on a 8core 16gb machine, the average is only 1800rps using your sample code from the techempower
example.
Full code for your reference:
const helloWorldStr = "hello world!"
func plainTextHandler(ctx *fasthttp.RequestCtx) {
helloWorldStr := fmt.Sprintf("num of cpu: %v", runtime.NumCPU())
helloWorldBytes := []byte(helloWorldStr)
ctx.Success("text/plain", helloWorldBytes)
}
func mainHandler(ctx *fasthttp.RequestCtx) {
path := ctx.Path()
switch {
case fasthttp.EqualBytesStr(path, "/"):
plainTextHandler(ctx)
default:
ctx.Error("unexpected path", fasthttp.StatusBadRequest)
}
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
var err error
var s fasthttp.Server
s.Handler = mainHandler
s.Name = "fasthttp"
ln, err := net.Listen("tcp", ":8002")
if err != nil {
log.Fatalf("error in net.Listen: %s", err)
}
if err = s.Serve(ln); err != nil {
log.Fatalf(("error when serving incoming connections: %s"), err)
}
}
from fasthttp.
The code above can be optimized. Substitute
helloWorldStr := fmt.Sprintf("num of cpu: %v", runtime.NumCPU())
helloWorldBytes := []byte(helloWorldStr)
ctx.Success("text/plain", helloWorldBytes)
with
fmt.Fprintf(ctx, "num of cpu: %d", runtime.NumCPU())
ctx.SetContentType("text/plain")
This way you avoid two memory allocations and two memory copies - one for the string returned from fmt.Sprintf
and another for the string
to []byte
conversion.
The program can be further optimized by calculating helloWorldBytes
contents only once in a global scope:
var helloWorldBytes = []byte(fmt.Sprintf("num of cpu: %v", runtime.NumCPU()))
As for low results I suspect there are problems with network settings on your OS. Read this article (the first article I found when googling for linux network tuning
).
Fasthttp achieves 1.4M rps in TechEmpower's plaintext benchmark on my laptop when using wrk with 16 connections and 256 pipelined requests.
from fasthttp.
Related Issues (20)
- Bug: fasthttp client connect to Vite dev server on localhost, tcp4 127.0.0.1:5173: connect: connection refused HOT 2
- Support for Prometheus HOT 1
- CloseOnShutdown dont work? HOT 3
- how can i use fasthttp bare minimum "net" library only without routing through the http overhead? just pure tcp rpc stuff will do HOT 1
- What is a correct way to create a proper fasthttp.RequestCtx in the unit tests? HOT 1
- Timeout stream response connection does not clear buffer data for re-use HOT 2
- Propagate request error to RetryIfFunc HOT 1
- Expose `timeout` field in Request HOT 1
- NewFastHTTPHandler does not set response status code. HOT 1
- NewFastHTTPHandler does not set response status code HOT 7
- Error when serving connection "x.x.x.x:443"<->"172.56.198.126:18271": EOF HOT 3
- http parsing of the request line - where does that happen? HOT 1
- gnet is going to have tls working on it very soon. was wondering if anyone has tried to port fasthttp to use gnet instead. HOT 1
- Feature request : update and show all examples for doing zero allocation when using fasthttp. 100% zero alloc for each req / resp. HOT 3
- It is not safe to read all stream body to memory without a max size limit. HOT 4
- serving a compress enabled public folder without +w permissions results in a 404 HOT 1
- no free connections available to host HOT 3
- when setting MaxConnsPerIP to value greater than zero, the TLSConnectionState( ) is null on a TLS connection returned from the worker pool. HOT 11
- invalid memory address or nil pointer dereference for firstByteReader'c HOT 2
- peeking nested query args HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fasthttp.