type Autoskip struct {
buf map[string]Autoskip_item
+ sync.Mutex
now uint
ticker *time.Ticker
sync.Mutex
<-autoskip.ticker.C
if len(autoskip.buf) == 0 {continue}
autoskip.now += 1
+ autoskip.Lock()
for k,v := range autoskip.buf{
if v.Exprie <= autoskip.now {
autoskip.Lock()
}
}
}
+ {//copy map
+ tmp := make(map[string]Autoskip_item)
+ for k,v := range autoskip.buf {tmp[k] = v}
+ autoskip.buf = tmp
+ }
+ autoskip.Unlock()
}
}()
}
return v.Num
}
}
+ autoskip.Lock()
+ defer autoskip.Unlock()
{//设置
autoskip.buf[s] = Autoskip_item{
Exprie:autoskip.now + 8,
}
//Msg-超级留言处理
-var sc_buf = make(map[string]bool)
+var sc_buf = make(map[string]struct{})
func (replyF) super_chat_message(s string){
id := p.Json().GetValFromS(s, "data.id");
if id != nil {
if _,ok := sc_buf[id.(string)];ok{return}
if len(sc_buf) >= 10 {
for k,_ := range sc_buf {delete(sc_buf, k);break}
+ {//copy map
+ tmp := make(map[string]struct{})
+ for k,v := range sc_buf {tmp[k] = v}
+ sc_buf = tmp
+ }
}
- sc_buf[id.(string)] = true
+ sc_buf[id.(string)] = struct{}{}
}
uname := p.Json().GetValFromS(s, "data.user_info.uname");
price := p.Json().GetValFromS(s, "data.price");
package main
import (
- // "time"
+ "time"
+ "runtime"
// "runtime/pprof"
- // "os"
+ "os"
// "log"
- // "net/http"
- // "fmt"
- // _ "net/http/pprof"
+ "net/http"
+ "fmt"
+ _ "net/http/pprof"
+ "runtime/debug"
// "github.com/skratchdot/open-golang/open"
q "github.com/qydysky/bili_danmu"
)
func main() {
- // go func() {
- // http.ListenAndServe("0.0.0.0:8899", nil)
- // }()
+ go func() {
+ http.ListenAndServe("0.0.0.0:8899", nil)
+ }()
// defer func(){
// open.Run("http://127.0.0.1:8899/debug/pprof/goroutine?debug=2")
// time.Sleep(time.Duration(3)*time.Second)
// }()
- // go func(){
- // // var memStats_old runtime.MemStats
- // for{
- // time.Sleep(time.Duration(10)*time.Second)
- // var memStats runtime.MemStats
- // runtime.ReadMemStats(&memStats)
- // fmt.Printf("=====\n")
- // // fmt.Printf("总内存:%v MB\n",memStats.Sys/1024e2/8)
- // fmt.Printf("GC次数:%v \n",memStats.NumGC)
-
- // fmt.Printf("堆 :%v %v MB\n",memStats.HeapInuse/1024e2/8,(memStats.HeapIdle - memStats.HeapReleased)/1024e2/8)
-
- // fmt.Printf("栈 :%v/%v MB\n",memStats.StackInuse/1024e2/8,memStats.StackSys/1024e2/8)
- // fmt.Printf("=====\n")
- // // memStats_old = memStats
- // }
- // }()
+ go func(){
+ for{
+ View()
+ time.Sleep(time.Duration(60)*time.Second)
+ {
+ debug.FreeOSMemory()
+ }
+ }
+ }()
// f, err := os.OpenFile("cpu.pprof", os.O_RDWR|os.O_CREATE, 0644)
// if err != nil {
// log.Fatal(err)
q.Demo()
// pprof.StopCPUProfile()
+}
+
+func View(){
+ var memStats runtime.MemStats
+ runtime.ReadMemStats(&memStats)
+ fmt.Printf("=====\n")
+ fmt.Printf("PID:%d\n",os.Getpid())
+ fmt.Printf("总内存:%v MB\n",memStats.Alloc/1024e2/8)
+ fmt.Printf("GC次数:%v \n",memStats.NumGC)
+ fmt.Printf("堆 :%v %v MB\n",memStats.HeapInuse/1024e2/8,(memStats.HeapIdle - memStats.HeapReleased)/1024e2/8)
+ fmt.Printf("=====\n")
}
\ No newline at end of file