Skip to content

Commit

Permalink
Merge pull request #397 from lesismal/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
lesismal committed Feb 17, 2024
2 parents 50b8c1f + e18162a commit ffef02e
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 6 deletions.
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
- [Websocket TLS Examples](#websocket-tls-examples)
- [Use With Other STD Based Frameworkds](#use-with-other-std-based-frameworkds)
- [More Examples](#more-examples)
- [1M Websocket Connections Benchmark](#1m-websocket-connections-benchmark)
- [Magics For HTTP and Websocket](#magics-for-http-and-websocket)
- [Different IOMod](#different-iomod)
- [Using Websocket With Std Server](#using-websocket-with-std-server)
Expand Down Expand Up @@ -156,6 +157,76 @@ func main() {
- [nbio-examples](https://github.com/lesismal/nbio-examples)



## 1M Websocket Connections Benchmark

For more details: [go-websocket-benchmark](https://github.com/lesismal/go-websocket-benchmark)

```sh
# lsb_release -a
LSB Version: core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal

# free
total used free shared buff/cache available
Mem: 24969564 15656352 3422212 1880 5891000 8899604
Swap: 0 0 0

# cat /proc/cpuinfo | grep processor
processor : 0
processor : 1
processor : 2
processor : 3
processor : 4
processor : 5
processor : 6
processor : 7
processor : 8
processor : 9
processor : 10
processor : 11
processor : 12
processor : 13
processor : 14
processor : 15


# taskset
run nbio_nonblocking server on cpu 0-3

--------------------------------------------------------------
BenchType : BenchEcho
Framework : nbio_nonblocking
TPS : 104713
EER : 280.33
Min : 56.90us
Avg : 95.36ms
Max : 2.29s
TP50 : 62.82ms
TP75 : 65.38ms
TP90 : 89.38ms
TP95 : 409.55ms
TP99 : 637.95ms
Used : 47.75s
Total : 5000000
Success : 5000000
Failed : 0
Conns : 1000000
Concurrency: 10000
Payload : 1024
CPU Min : 0.00%
CPU Avg : 373.53%
CPU Max : 602.33%
MEM Min : 978.70M
MEM Avg : 979.88M
MEM Max : 981.14M
--------------------------------------------------------------
```


## Magics For HTTP and Websocket

### Different IOMod
Expand Down
2 changes: 0 additions & 2 deletions conn_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ func (c *Conn) AsyncRead() {
if n > 0 {
g.onData(rc, buffer[:n])
}
g.payback(c, buffer)
if errors.Is(err, syscall.EINTR) {
continue
}
Expand Down Expand Up @@ -150,7 +149,6 @@ func (c *Conn) AsyncRead() {
if n > 0 {
g.onData(rc, buffer[:n])
}
g.payback(c, buffer)
if errors.Is(err, syscall.EINTR) {
continue
}
Expand Down
10 changes: 7 additions & 3 deletions engine_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package nbio

import (
"net"
"runtime"
"strings"

"github.com/lesismal/nbio/logging"
Expand Down Expand Up @@ -111,9 +112,9 @@ func (g *Engine) Start() error {
}

if len(g.Addrs) == 0 {
logging.Info("NBIO Engine[%v] start", g.Name)
logging.Info("NBIO Engine[%v] start with [%v eventloop]", g.Name, g.NPoller)
} else {
logging.Info("NBIO Engine[%v] start listen on: [\"%v@%v\"]", g.Name, g.Network, strings.Join(g.Addrs, `", "`))
logging.Info("NBIO Engine[%v] start with [%v eventloop], listen on: [\"%v@%v\"]", g.Name, g.NPoller, g.Network, strings.Join(g.Addrs, `", "`))
}

return nil
Expand All @@ -125,7 +126,10 @@ func NewEngine(conf Config) *Engine {
conf.Name = "NB"
}
if conf.NPoller <= 0 {
conf.NPoller = 1
conf.NPoller = runtime.NumCPU() / 4
if conf.NPoller == 0 {
conf.NPoller = 1
}
}
if conf.ReadBufferSize <= 0 {
conf.ReadBufferSize = DefaultReadBufferSize
Expand Down
5 changes: 4 additions & 1 deletion nbhttp/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,10 @@ func NewEngine(conf Config) *Engine {
conf.MaxLoad = DefaultMaxLoad
}
if conf.NPoller <= 0 {
conf.NPoller = 1
conf.NPoller = runtime.NumCPU() / 4
if conf.NPoller == 0 {
conf.NPoller = 1
}
}
if conf.ReadLimit <= 0 {
conf.ReadLimit = DefaultHTTPReadLimit
Expand Down

0 comments on commit ffef02e

Please sign in to comment.