Skip to content

Commit

Permalink
Merge branch 'master' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mredencom committed Aug 24, 2021
2 parents a770ee8 + d6360cd commit 7dac674
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 27 deletions.
23 changes: 1 addition & 22 deletions internal/socket/messages.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
package socket

import (
"github.com/php2go/netpollmux/internal/buffer"
"io"
"strings"
"sync"
"sync/atomic"

"github.com/php2go/netpollmux/internal/buffer"
"github.com/php2go/netpollmux/internal/writer"
)

const bufferSize = 65526

var (
buffers = sync.Map{}
assign int32
)

//func assignPool(size int) *sync.Pool {
// for {
// if p, ok := buffers.Load(size); ok {
// return p.(*sync.Pool)
// }
// if atomic.CompareAndSwapInt32(&assign, 0, 1) {
// var pool = &sync.Pool{New: func() interface{} {
// return make([]byte, size)
// }}
// buffers.Store(size, pool)
// atomic.StoreInt32(&assign, 0)
// return pool
// }
// }
//}

// Batch interface is used to write batch messages.
type Batch interface {
// SetConcurrency sets a callback function concurrency to enable auto batch writer for improving throughput.
Expand Down
3 changes: 0 additions & 3 deletions internal/socket/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import (
"errors"
"fmt"
"net"
"runtime"
"strings"

"github.com/php2go/netpollmux/netpoll"
)

var numCPU = runtime.NumCPU()

// ErrHandler is the error when the handler is nil
var ErrHandler = errors.New("handler is nil")

Expand Down
3 changes: 2 additions & 1 deletion internal/socket/socket_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"crypto/tls"
"errors"
"fmt"
"github.com/php2go/netpollmux/netpoll"
"io"
"net"
"net/http"
"time"

"github.com/php2go/netpollmux/netpoll"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion internal/socket/socket_inproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package socket

import (
"crypto/tls"
"net"

"github.com/php2go/netpollmux/internal/inproc"
"github.com/php2go/netpollmux/netpoll"
"net"
)

// INPROC implements the Socket interface.
Expand Down
37 changes: 37 additions & 0 deletions test/netpoll_benchmark/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package netpoll_benchmark

import (
"flag"
"time"

"github.com/php2go/netpollmux/netpoll"
)

var addr string
var async bool
var sleep int

func init() {
flag.StringVar(&addr, "addr", ":9999", "-addr=:9999")
flag.BoolVar(&async, "async", false, "-async=false")
flag.IntVar(&sleep, "sleep", 0, "-sleep=0")
flag.Parse()
}

func main() {
var handler = &netpoll.DataHandler{
NoShared: true,
NoCopy: true,
BufferSize: 1024,
HandlerFunc: func(req []byte) (res []byte) {
if sleep > 0 {
time.Sleep(time.Millisecond * time.Duration(sleep))
}
res = req
return
},
}
if err := netpoll.ListenAndServe("tcp", addr, handler); err != nil {
panic(err)
}
}

0 comments on commit 7dac674

Please sign in to comment.