Skip to content

Releases: lesismal/nbio

v1.3.5

30 Oct 14:39
49d4fd2
Compare
Choose a tag to compare

Support different IO Mod for http and websocket

IOMod Remarks
IOModNonBlocking There's no difference between this IOMod and the old version with no IOMod. All the connections will be handled by poller.
IOModBlocking All the connections will be handled by at least one goroutine, for websocket, we can set Upgrader.BlockingModAsyncWrite to handle writting with one more goroutine and then avoid Head-of-line blocking on broadcast scenarios.
IOModMixed We set the Engine.MaxBlockingOnline, if the online num is smaller than it, the new connection will be handled by single goroutine as IOModBlocking, else the new connection will be handled by poller.

The IOModBlocking aims to improve the performance for low online service, it runs faster than std.
The IOModMixed aims to keep a balance between performance and cpu/mem cost in different scenarios: when there are not too many online connections, it performs better than std, or else it can serve lots of online connections and keep healthy.

The websocket now also support std http server, and I got a better performance and lower mem/cpu cost than std in a simple load test. The example of using with std http server would be like this:

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/lesismal/nbio/nbhttp/websocket"
)

func echo(w http.ResponseWriter, r *http.Request) {
	u := websocket.NewUpgrader()
	u.OnMessage(func(c *websocket.Conn, mt websocket.MessageType, data []byte) {
		c.WriteMessage(mt, data)
	})
	_, err := u.Upgrade(w, r, nil)
	if err != nil {
		log.Print("upgrade:", err)
		return
	}
}

func main() {
	mux := &http.ServeMux{}
	mux.HandleFunc("/ws", echo)
	server := http.Server{
		Addr:    "localhost:8080",
		Handler: mux,
	}
	fmt.Println("server exit:", server.ListenAndServe())
}

v1.3.4

14 Oct 09:03
5c8940c
Compare
Choose a tag to compare
  1. fix websocket.Dialer concurrent issue: #225
  2. support unix addr config

v1.3.3

09 Oct 05:00
a21dc97
Compare
Choose a tag to compare

update llib version(fix half-packet parsing bug)

v1.3.2

27 Sep 11:12
e7c0515
Compare
Choose a tag to compare

Conn: fix beforeWrite deadlock.

v1.3.1

14 Sep 12:09
c2eceaf
Compare
Choose a tag to compare
  1. seperate timer package
  2. optimize nbhttp conns holder
  3. expose ReadAndGetConn(used for UDP OnRead)

v1.3.0

09 Sep 13:05
ad13cec
Compare
Choose a tag to compare

support udp.

v1.2.21

19 Aug 15:09
1f7055d
Compare
Choose a tag to compare
  1. expose the negotiated WebSocket subprotocol
  2. disable race warnings that are safe as known

v1.2.20

07 Jun 02:02
b47a0d3
Compare
Choose a tag to compare

websocket: call OnOpen handler after the server sends handshake message.

v1.2.19

31 May 15:05
6995997
Compare
Choose a tag to compare

websocket: add Upgrader.KeepaliveTime and handle deadline automatically

v1.2.18

22 Apr 12:32
a3507ca
Compare
Choose a tag to compare

uncomment SetKeepAlivePeriod