优化域名排行查询速度

This commit is contained in:
GoEdgeLab
2021-09-16 09:23:36 +08:00
parent 99649c3e90
commit 2f592990cd
3 changed files with 7 additions and 1 deletions

View File

@@ -184,6 +184,7 @@ func (this *ServerDomainHourlyStatDAO) FindTopDomainStatsWithClusterId(tx *dbs.T
Table(table). Table(table).
Attr("clusterId", clusterId). Attr("clusterId", clusterId).
Between("hour", hourFrom, hourTo). Between("hour", hourFrom, hourTo).
UseIndex("hour").
Result("domain, MIN(serverId) AS serverId, SUM(bytes) AS bytes, SUM(cachedBytes) AS cachedBytes, SUM(countRequests) AS countRequests, SUM(countCachedRequests) AS countCachedRequests, SUM(countAttackRequests) AS countAttackRequests, SUM(attackBytes) AS attackBytes"). Result("domain, MIN(serverId) AS serverId, SUM(bytes) AS bytes, SUM(cachedBytes) AS cachedBytes, SUM(countRequests) AS countRequests, SUM(countCachedRequests) AS countCachedRequests, SUM(countAttackRequests) AS countAttackRequests, SUM(attackBytes) AS attackBytes").
Group("domain"). Group("domain").
Desc("countRequests"). Desc("countRequests").
@@ -233,6 +234,7 @@ func (this *ServerDomainHourlyStatDAO) FindTopDomainStatsWithNodeId(tx *dbs.Tx,
Table(table). Table(table).
Attr("nodeId", nodeId). Attr("nodeId", nodeId).
Between("hour", hourFrom, hourTo). Between("hour", hourFrom, hourTo).
UseIndex("hour").
Result("domain, MIN(serverId) AS serverId, SUM(bytes) AS bytes, SUM(cachedBytes) AS cachedBytes, SUM(countRequests) AS countRequests, SUM(countCachedRequests) AS countCachedRequests, SUM(countAttackRequests) AS countAttackRequests, SUM(attackBytes) AS attackBytes"). Result("domain, MIN(serverId) AS serverId, SUM(bytes) AS bytes, SUM(cachedBytes) AS cachedBytes, SUM(countRequests) AS countRequests, SUM(countCachedRequests) AS countCachedRequests, SUM(countAttackRequests) AS countAttackRequests, SUM(attackBytes) AS attackBytes").
Group("domain"). Group("domain").
Desc("countRequests"). Desc("countRequests").
@@ -282,6 +284,7 @@ func (this *ServerDomainHourlyStatDAO) FindTopDomainStatsWithServerId(tx *dbs.Tx
Table(table). Table(table).
Attr("serverId", serverId). Attr("serverId", serverId).
Between("hour", hourFrom, hourTo). Between("hour", hourFrom, hourTo).
UseIndex("hour").
Result("domain, MIN(serverId) AS serverId, SUM(bytes) AS bytes, SUM(cachedBytes) AS cachedBytes, SUM(countRequests) AS countRequests, SUM(countCachedRequests) AS countCachedRequests, SUM(countAttackRequests) AS countAttackRequests, SUM(attackBytes) AS attackBytes"). Result("domain, MIN(serverId) AS serverId, SUM(bytes) AS bytes, SUM(cachedBytes) AS cachedBytes, SUM(countRequests) AS countRequests, SUM(countCachedRequests) AS countCachedRequests, SUM(countAttackRequests) AS countAttackRequests, SUM(attackBytes) AS attackBytes").
Group("domain"). Group("domain").
Desc("countRequests"). Desc("countRequests").

View File

@@ -38,6 +38,9 @@ func TestServerDomainHourlyStatDAO_IncreaseHourlyStat(t *testing.T) {
for i := 0; i < 1_000_000; i++ { for i := 0; i < 1_000_000; i++ {
var f = string([]rune{int32(rands.Int('0', '9'))}) var f = string([]rune{int32(rands.Int('0', '9'))})
if i % 30 > 0 {
f = string([]rune{int32(rands.Int('a', 'z'))})
}
err := NewServerDomainHourlyStatDAO().IncreaseHourlyStat(nil, 18, 48, 23, f+"rand"+types.String(i%500_000)+".com", timeutil.Format("Ymd")+fmt.Sprintf("%02d", rands.Int(0, 23)), 1, 1, 1, 1, 1, 1) err := NewServerDomainHourlyStatDAO().IncreaseHourlyStat(nil, 18, 48, 23, f+"rand"+types.String(i%500_000)+".com", timeutil.Format("Ymd")+fmt.Sprintf("%02d", rands.Int(0, 23)), 1, 1, 1, 1, 1, 1)
if err != nil { if err != nil {

File diff suppressed because one or more lines are too long