golang websocket压测示例
Posted 杰哥的技术杂货铺
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了golang websocket压测示例相关的知识,希望对你有一定的参考价值。
package main
import (
"flag"
"fmt"
"log"
"net/url"
"time"
"github.com/gorilla/websocket"
)
//根据自身情况修改服务器ip地址
var addr = flag.String("addr", "localhost:12345", "http service address")
func main()
succCount := 0
failCount := 0
//建立1000个websocket连接请求某数据
for i := 1; i < 1000; i++
u := url.URLScheme: "wss", Host: *addr, Path: "/ws"
log.Println(u.String())
conn, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil
log.Println(err)
failCount++
fmt.Println("Number of dialing failures:", failCount)
fmt.Println("Number of dialing fail:", err)
time.Sleep(time.Second)
continue
defer conn.Close()
succCount++
fmt.Println("Number of successful connections:", succCount)
go Client(conn)
//Stop here to prevent the program from exiting
tick :=
以上是关于golang websocket压测示例的主要内容,如果未能解决你的问题,请参考以下文章