Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to cross-compile using go build #11

Closed
abacaj opened this issue Nov 30, 2015 · 4 comments
Closed

Unable to cross-compile using go build #11

abacaj opened this issue Nov 30, 2015 · 4 comments

Comments

@abacaj
Copy link

abacaj commented Nov 30, 2015

Trying to compile for linux $ env GOOS=linux GOARCH=arm go build -v github.com/abacaj/fasthttp

produces the following error:
# github.com/valyala/fasthttp
C:\Projects\Go\src\github.com\valyala\fasthttp\bytesconv.go:20: constant 18446744073709551615 overflows uint
C:\Projects\Go\src\github.com\valyala\fasthttp\bytesconv.go:33: constant 18446744073709551615 overflows uint

seems like a bug, but not sure - I'm on GO 1.5.1

@valyala
Copy link
Owner

valyala commented Nov 30, 2015

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 .

@abacaj
Copy link
Author

abacaj commented Nov 30, 2015

yep that fixed it, thanks!

@abacaj abacaj closed this as completed Nov 30, 2015
@abacaj
Copy link
Author

abacaj commented Nov 30, 2015

@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)
  }
}

@valyala
Copy link
Owner

valyala commented Nov 30, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants