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

[Question] <traffic from local machine to websocket server is high> #876

Open
1 task done
zhouziyan opened this issue Nov 28, 2023 · 3 comments
Open
1 task done
Labels

Comments

@zhouziyan
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I am using this repo to work with websocket thing. My case is very simple, just listening some data from a web server.
After I start my program, I use $ sudo nethogs command to see the network traffic.
I saw that SENT is 50k/s and RECEIVED is 500k/s.
I did't sent any traffic to websocket server. I'd like to ask what message is included in SENT and how to disable it?
Could anybody from community can help me?

Expected Behavior

No response

Steps To Reproduce

No response

Anything else?

No response

@Hayden-Chang
Copy link

I use Wireshark to capture tcp/udp traffic of server.go and find no data is received or sent by server except for heartbeat every 15 seconds.
Please share you code for deep investigation.

@zhouziyan
Copy link
Author

@Hayden-Chang try to connect to wss://stream.binance.com:9443/ws/btcusdt@bookTicker

@hulkingshtick
Copy link

I'd like to ask what message is included in SENT and how to disable it?

The websocket connection responds to pings by sending a pong. Otherwise, the connection only sends data written by the application.

It's doubtful that the pong traffic is substantial. Add this code to your application to observe the pong data:

c.SetPingHandler(func(message string) error {
	fmt.Printf("writing %d pong bytes\n", len(message))
	_ = c.WriteControl(websocket.PongMessage, []byte(message), time.Now().Add(time.Second))
	return nil
})

You can disable pongs using the following code. I don't recommend this because the server likely close the connection when the client does not respond to the ping.

c.SetPingHandler(func(message string) error {
	return nil
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

3 participants