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

Good project,Thanks!!! Use low memory and very fast!!! #72

Closed
eric-zhangqi opened this issue Jul 30, 2021 · 5 comments
Closed

Comments

@eric-zhangqi
Copy link

No description provided.

@lesismal
Copy link
Owner

Thank you very much! 😄

@nicoroy2561
Copy link

@lesismal I want to chime in to thank you for "spamming" the gobwas/1mil repos with comments.
I was running into the issues you described with my production server, and wasn't able to figure it out.
Will proceed to study and swap in your solution instead.
Thanks a lot!

@lesismal
Copy link
Owner

lesismal commented Aug 4, 2021

@lesismal I want to chime in to thank you for "spamming" the gobwas/1mil repos with comments.
I was running into the issues you described with my production server, and wasn't able to figure it out.
Will proceed to study and swap in your solution instead.
Thanks a lot!

You are welcome and thank you for your feedback!

The problem of gobwas/ws+netpoll can't be solved until they implement async-streaming-parser for http and websocket.

My repo does not have that problem, and passes the Autobahn Test:
https://lesismal.github.io/nbio/websocket

You could try websocket with nbio like this:

package main

import (
	"context"
	"fmt"
	"net/http"
	"os"
	"os/signal"
	"time"

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

func newUpgrader() *websocket.Upgrader {
	u := websocket.NewUpgrader()
	u.OnMessage(func(c *websocket.Conn, messageType websocket.MessageType, data []byte) {
		// echo
		c.WriteMessage(messageType, data)
	})

	u.OnClose(func(c *websocket.Conn, err error) {
		fmt.Println("OnClose:", c.RemoteAddr().String(), err)
	})
	return u
}

func onWebsocket(w http.ResponseWriter, r *http.Request) {
	upgrader := newUpgrader()
	conn, err := upgrader.Upgrade(w, r, nil)
	if err != nil {
		panic(err)
	}
	wsConn := conn.(*websocket.Conn)
	wsConn.SetReadDeadline(time.Time{})
	fmt.Println("OnOpen:", wsConn.RemoteAddr().String())
}

func main() {
	mux := &http.ServeMux{}
	mux.HandleFunc("/ws", onWebsocket)

	svr := nbhttp.NewServer(nbhttp.Config{
		Network: "tcp",
		Addrs:   []string{"localhost:8080"},
	}, mux, nil)

	err := svr.Start()
	if err != nil {
		fmt.Printf("nbio.Start failed: %v\n", err)
		return
	}

	interrupt := make(chan os.Signal, 1)
	signal.Notify(interrupt, os.Interrupt)
	<-interrupt
	ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
	defer cancel()
	svr.Shutdown(ctx)
}

For more examples, refer to README and:
https://github.com/lesismal/nbio/tree/master/examples

@nicoroy2561
Copy link

@lesismal thanks a lot again, I will proceed to try that.
If you have any suggestions on the settings to pass your suite, I'm open to try different alternatives.

@lesismal
Copy link
Owner

lesismal commented Oct 16, 2021

Thank you for your feedback, I'll close this issue.
Welcome to leave a message about your projects that are using nbio here:
issues/128
issues/129

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

3 participants