fix: libxml2 leak

This commit is contained in:
eson
2020-07-22 20:00:02 +08:00
parent b9f2f5cf22
commit 6d688b8450
8 changed files with 112 additions and 22 deletions

View File

@@ -16,7 +16,6 @@ import (
*/
func main() {
go func() {
http.ListenAndServe("0.0.0.0:8899", nil)
}()

View File

@@ -8,7 +8,6 @@ import (
"os"
"os/signal"
"regexp"
"runtime"
"strconv"
"strings"
"sync/atomic"
@@ -18,6 +17,9 @@ import (
"github.com/tidwall/gjson"
)
var estore = intimate.NewStoreExtractor()
var sstore = intimate.NewStoreSource(string(intimate.STOpenrec))
// OpenrecExtractor 提取方法
type OpenrecExtractor struct {
user *intimate.ExtractorSource
@@ -36,14 +38,27 @@ func (oe *OpenrecExtractor) Execute() {
atomic.StoreInt32(&loop, 0)
}()
estore := intimate.NewStoreExtractor()
sstore := intimate.NewStoreSource(string(intimate.STOpenrec))
var lasterr error = nil
execute := func() bool {
var err error
for atomic.LoadInt32(&loop) > 0 {
// if sstore.PopCount() >= 1000 {
// if err = estore.Close(); err != nil {
// log.Println(err)
// }
// if err = sstore.Close(); err != nil {
// log.Println(err)
// }
// estore = intimate.NewStoreExtractor()
// sstore = intimate.NewStoreSource(string(intimate.STOpenrec))
runtime.GC()
time.Sleep(time.Nanosecond)
// oe.supporters.Clear()
// oe.user.Clear()
// oe.userLive.Clear()
// runtime.GC() // 主动gc
// log.Println("1000次执行, gc 重新建立sql链接")
// }
source, err := sstore.Pop(string(intimate.TTOpenrecUser), 0)
if err != nil {
@@ -52,7 +67,7 @@ func (oe *OpenrecExtractor) Execute() {
lasterr = err
}
time.Sleep(time.Second * 2)
continue
return true
}
sdata := source.Ext.([]byte)
@@ -65,13 +80,16 @@ func (oe *OpenrecExtractor) Execute() {
streamer.UserId = userId
streamer.Platform = string(intimate.Popenrec)
oe.user = intimate.NewExtractorSource(datamap["html_user"])
htmlUser := datamap["html_user"]
oe.user = intimate.NewExtractorSource(&htmlUser)
oe.user.CreateExtractor()
oe.userLive = intimate.NewExtractorSource(datamap["html_live"])
htmlLive := datamap["html_live"]
oe.userLive = intimate.NewExtractorSource(&htmlLive)
oe.userLive.CreateExtractor()
oe.supporters = intimate.NewExtractorSource(datamap["json_supporters"])
jsonSupporters := datamap["json_supporters"]
oe.supporters = intimate.NewExtractorSource(&jsonSupporters)
clog := &intimate.CollectLog{}
// log.Println(anchorId)
@@ -101,6 +119,13 @@ func (oe *OpenrecExtractor) Execute() {
source.Operator = int32(intimate.OperatorExtractorOK)
sstore.UpdateOperator(source)
return true
}
for atomic.LoadInt32(&loop) > 0 {
if !execute() {
break
}
}
}
@@ -143,6 +168,7 @@ func (oe *OpenrecExtractor) extractViewsAndLiveStreaming(clog intimate.ISet) {
if err != nil {
log.Println(err)
}
if xp.NodeIter().Next() {
views := regexp.MustCompile(`[0-9,]+`).FindString(xp.String())
views = strings.ReplaceAll(views, ",", "")