mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-08 19:40:24 +08:00
自动调整写入单次写入访问日志数量
This commit is contained in:
@@ -86,13 +86,24 @@ func init() {
|
|||||||
// 导出队列内容
|
// 导出队列内容
|
||||||
goman.New(func() {
|
goman.New(func() {
|
||||||
var ticker = time.NewTicker(1 * time.Second)
|
var ticker = time.NewTicker(1 * time.Second)
|
||||||
|
var accessLogPerLoop = accessLogPerTx
|
||||||
|
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
var countTxs = accessLogCountPerSecond / accessLogPerTx
|
var countTxs = accessLogCountPerSecond / accessLogPerLoop
|
||||||
if countTxs <= 0 {
|
if countTxs <= 0 {
|
||||||
countTxs = 1
|
countTxs = 1
|
||||||
}
|
}
|
||||||
for i := 0; i < countTxs; i++ {
|
for i := 0; i < countTxs; i++ {
|
||||||
hasMore, err := SharedHTTPAccessLogDAO.DumpAccessLogsFromQueue(accessLogPerTx)
|
var before = time.Now()
|
||||||
|
hasMore, err := SharedHTTPAccessLogDAO.DumpAccessLogsFromQueue(accessLogPerLoop)
|
||||||
|
|
||||||
|
// 如果用时过长,则调整每次写入次数
|
||||||
|
var costMs = time.Since(before).Milliseconds()
|
||||||
|
if costMs > 150 {
|
||||||
|
accessLogPerLoop = accessLogPerTx / 4
|
||||||
|
} else if costMs > 100 {
|
||||||
|
accessLogPerLoop = accessLogPerTx / 2
|
||||||
|
} // 这里不需要恢复成默认值,因为可能是写入数量比较小
|
||||||
if err != nil {
|
if err != nil {
|
||||||
remotelogs.Error("HTTP_ACCESS_LOG_QUEUE", "dump access logs failed: "+err.Error())
|
remotelogs.Error("HTTP_ACCESS_LOG_QUEUE", "dump access logs failed: "+err.Error())
|
||||||
} else if !hasMore {
|
} else if !hasMore {
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ func TestCreateHTTPAccessLog_Tx(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 200; i++ {
|
||||||
err = SharedHTTPAccessLogDAO.CreateHTTPAccessLog(tx, dao.DAO, accessLog)
|
err = SharedHTTPAccessLogDAO.CreateHTTPAccessLog(tx, dao.DAO, accessLog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user