初级会员
  • 第 14620 位会员
  • arterforyou
  • 2017-11-30 11:51:20
  • Offline
  • 20 2

最近发布的文章

    暂无

最近分享的资源

    暂无

最近发布的项目

    暂无

最近的评论

  • <pre><code>package main import ( "net" "log" "os" "fmt" ) type Data struct{ C string D *net.UDPAddr } const MAX_MTU int = 1024 * 64 var path string = "/data/flume-agent/log/go_xg_udp.log" func main() { // 创建监听 log.SetFlags(0) file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666) if err != nil { log.Fatalln("fail to create go_udp.log file!") } logger := log.New(file, "", log.LstdFlags|log.Llongfile) logger.Println("started udp server") socket, err := net.ListenUDP("udp4", &net.UDPAddr{ IP: net.IPv4(0, 0, 0, 0), Port: 5141, }) if err != nil { logger.Println("监听失败!", err) return } defer socket.Close() c := make(chan Data, 1024) // 带缓冲的通道 for { // 读取数据 data := make([]byte, MAX_MTU) read, remoteAddr, err := socket.ReadFromUDP(data) if err != nil { logger.Println("读取数据失败!", err) continue } go sets(string(data[:read]), remoteAddr, c) select { case k:=<-c: fmt.Println(k.D.IP,k.C) } } } func sets(k string, remoteAddr *net.UDPAddr, c chan Data){ c<-Data{k, remoteAddr} } </code></pre> 折腾这样吧,发现之前发的没有用markdown标注,不好意思 原来udp启动之后,后面的并发不并发自己随便写就可以了,还是可以走到的 [参考:](https://tonychyi.wetofu.top/2015/11/25/async-udp-server-using-go/)https://tonychyi.wetofu.top/2015/11/25/async-udp-server-using-go/
  • 折腾最后这样吧: package main import ( "net" "log" "os" "fmt" ) type Data struct{ C string D *net.UDPAddr } const MAX_MTU int = 1024 * 64 var path string = "/data/flume-agent/log/go_xg_udp.log" func main() { // 创建监听 log.SetFlags(0) file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666) if err != nil { log.Fatalln("fail to create go_udp.log file!") } logger := log.New(file, "", log.LstdFlags|log.Llongfile) logger.Println("started udp server") socket, err := net.ListenUDP("udp4", &net.UDPAddr{ IP: net.IPv4(0, 0, 0, 0), Port: 5141, }) if err != nil { logger.Println("监听失败!", err) return } defer socket.Close() c := make(chan Data, 1024) // 带缓冲的通道 for { // 读取数据 data := make([]byte, MAX_MTU) read, remoteAddr, err := socket.ReadFromUDP(data) if err != nil { logger.Println("读取数据失败!", err) continue } go sets(string(data[:read]), remoteAddr, c) select { case k:=<-c: fmt.Println(k.D.IP,k.C) } } } func sets(k string, remoteAddr *net.UDPAddr, c chan Data){ c<-Data{k, remoteAddr} } 原来udp启动之后,后面的并发不并发自己随便写就可以了,还是可以走到的 参考:https://tonychyi.wetofu.top/2015/11/25/async-udp-server-using-go/
  • wrk -c 100 -t 10 -d 1m http://127.0.0.1:1234/bin/search Running 1m test @ http://127.0.0.1:1234/bin/search 10 threads and 100 connections Thread Stats Avg Stdev Max +/- Stdev Latency 19.64ms 69.76ms 1.01s 97.32% Req/Sec 1.07k 310.33 1.78k 76.10% 625373 requests in 1.00m, 70.38MB read Requests/sec: 10405.80 Transfer/sec: 1.17MB
  • 搞个配置文件,server_name对应 url, 然后requests过来的话,抽取出http的host头部,匹配server_name对应的url不就行了?
  • 看自己是想用go来嘛了,搞算法,计算可以写数据分析,爬虫之类,搞web可以写博客,购物网站等学习一些框架beggo,gin等,把前后端理清楚,拼起来就是项目。