Skip to content

Commit e3ce9a9

Browse files
committed
feat(nginx_log): adaptive optimization and worker count adjustment
1 parent 16a4f5c commit e3ce9a9

18 files changed

+1897
-239
lines changed

app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@fingerprintjs/fingerprintjs": "^4.6.2",
1919
"@formkit/auto-animate": "^0.8.4",
2020
"@simplewebauthn/browser": "^13.1.2",
21-
"@uozi-admin/curd": "^4.15.4",
21+
"@uozi-admin/curd": "^4.15.5",
2222
"@uozi-admin/request": "^2.8.4",
2323
"@vue/reactivity": "^3.5.21",
2424
"@vue/shared": "^3.5.21",

app/pnpm-lock.yaml

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/views/preference/tabs/ExternalNotify.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script setup lang="ts">
22
import type { ExternalNotify } from '@/api/external_notify'
33
import { StdCurd } from '@uozi-admin/curd'
4-
import { Button } from 'ant-design-vue'
54
import externalNotify, { testMessage } from '@/api/external_notify'
65
import columns from '../components/ExternalNotify/columns'
76
@@ -49,14 +48,14 @@ async function handleTestSingleMessage(record: ExternalNotify) {
4948
disable-search
5049
>
5150
<template #beforeActions="{ record }">
52-
<Button
51+
<AButton
5352
type="link"
5453
size="small"
5554
:loading="loadingStates[record.id] || false"
5655
@click="handleTestSingleMessage(record)"
5756
>
5857
{{ $gettext('Test') }}
59-
</Button>
58+
</AButton>
6059
</template>
6160
</StdCurd>
6261
</template>

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ require (
294294
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.34 // indirect
295295
github.com/selectel/domains-go v1.1.0 // indirect
296296
github.com/selectel/go-selvpcclient/v4 v4.1.0 // indirect
297+
github.com/shirou/gopsutil/v3 v3.24.5 // indirect
297298
github.com/shopspring/decimal v1.4.0 // indirect
298299
github.com/sirupsen/logrus v1.9.3 // indirect
299300
github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,8 @@ github.com/selectel/domains-go v1.1.0 h1:futG50J43ALLKQAnZk9H9yOtLGnSUh7c5hSvuC5
18741874
github.com/selectel/domains-go v1.1.0/go.mod h1:SugRKfq4sTpnOHquslCpzda72wV8u0cMBHx0C0l+bzA=
18751875
github.com/selectel/go-selvpcclient/v4 v4.1.0 h1:22lBp+rzg9g2MP4iiGhpVAcCt0kMv7I7uV1W3taLSvQ=
18761876
github.com/selectel/go-selvpcclient/v4 v4.1.0/go.mod h1:eFhL1KUW159KOJVeGO7k/Uxl0TYd/sBkWXjuF5WxmYk=
1877+
github.com/shirou/gopsutil/v3 v3.24.5 h1:i0t8kL+kQTvpAYToeuiVk3TgDeKOFioZO3Ztz/iZ9pI=
1878+
github.com/shirou/gopsutil/v3 v3.24.5/go.mod h1:bsoOS1aStSs9ErQ1WWfxllSeS1K5D+U30r2NfcubMVk=
18771879
github.com/shirou/gopsutil/v4 v4.25.7 h1:bNb2JuqKuAu3tRlPv5piSmBZyMfecwQ+t/ILq+1JqVM=
18781880
github.com/shirou/gopsutil/v4 v4.25.7/go.mod h1:XV/egmwJtd3ZQjBpJVY5kndsiOO4IRqy9TQnmm6VP7U=
18791881
github.com/shirou/gopsutil/v4 v4.25.8 h1:NnAsw9lN7587WHxjJA9ryDnqhJpFH6A+wagYWTOH970=

internal/cron/incremental_indexing.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ func performIncrementalIndexing() {
8383
// needsIncrementalIndexing checks if a log file needs incremental indexing
8484
func needsIncrementalIndexing(log *nginx_log.NginxLogWithIndex) bool {
8585
// Skip if already indexing or queued
86-
if log.IndexStatus == string(indexer.IndexStatusIndexing) ||
87-
log.IndexStatus == string(indexer.IndexStatusQueued) {
86+
if log.IndexStatus == string(indexer.IndexStatusIndexing) ||
87+
log.IndexStatus == string(indexer.IndexStatusQueued) {
8888
return false
8989
}
9090

@@ -106,14 +106,14 @@ func needsIncrementalIndexing(log *nginx_log.NginxLogWithIndex) bool {
106106

107107
// File was modified after last index and size increased
108108
if fileModTime.After(lastModified) && fileSize > log.LastSize {
109-
logger.Debugf("File %s needs incremental indexing: mod_time=%s, size=%d",
109+
logger.Debugf("File %s needs incremental indexing: mod_time=%s, size=%d",
110110
log.Path, fileModTime.Format("2006-01-02 15:04:05"), fileSize)
111111
return true
112112
}
113113

114114
// File size decreased - might be file rotation
115115
if fileSize < log.LastSize {
116-
logger.Debugf("File %s needs full re-indexing due to size decrease: old_size=%d, new_size=%d",
116+
logger.Debugf("File %s needs full re-indexing due to size decrease: old_size=%d, new_size=%d",
117117
log.Path, log.LastSize, fileSize)
118118
return true
119119
}
@@ -131,7 +131,7 @@ func queueIncrementalIndexing(logPath string, modernIndexer interface{}, logFile
131131
// Queue the indexing job asynchronously
132132
go func() {
133133
logger.Infof("Starting incremental indexing for file: %s", logPath)
134-
134+
135135
// Set status to indexing
136136
if err := setFileIndexStatus(logPath, string(indexer.IndexStatusIndexing), logFileManager); err != nil {
137137
logger.Errorf("Failed to set indexing status for %s: %v", logPath, err)
@@ -140,8 +140,8 @@ func queueIncrementalIndexing(logPath string, modernIndexer interface{}, logFile
140140

141141
// Perform incremental indexing
142142
startTime := time.Now()
143-
docsCountMap, minTime, maxTime, err := modernIndexer.(*indexer.ParallelIndexer).IndexLogGroupWithProgress(logPath, nil)
144-
143+
docsCountMap, minTime, maxTime, err := modernIndexer.(*indexer.ParallelIndexer).IndexSingleFileIncrementally(logPath, nil)
144+
145145
if err != nil {
146146
logger.Errorf("Failed incremental indexing for %s: %v", logPath, err)
147147
// Set error status
@@ -184,25 +184,25 @@ func setFileIndexStatus(logPath, status string, logFileManager interface{}) erro
184184
if logFileManager == nil {
185185
return fmt.Errorf("log file manager not available")
186186
}
187-
187+
188188
// Get persistence manager
189189
lfm, ok := logFileManager.(*indexer.LogFileManager)
190190
if !ok {
191191
return fmt.Errorf("invalid log file manager type")
192192
}
193-
193+
194194
persistence := lfm.GetPersistence()
195195
if persistence == nil {
196196
return fmt.Errorf("persistence manager not available")
197197
}
198-
198+
199199
// Use enhanced SetIndexStatus method with queue position for queued status
200200
queuePosition := 0
201201
if status == string(indexer.IndexStatusQueued) {
202202
// For incremental indexing, we don't need specific queue positions
203203
// They will be processed as they come
204204
queuePosition = int(time.Now().Unix() % 1000) // Simple ordering by time
205205
}
206-
206+
207207
return persistence.SetIndexStatus(logPath, status, queuePosition, "")
208-
}
208+
}

internal/nginx_log/indexer/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,13 @@ Based on comprehensive benchmarking on Apple M2 Pro:
367367
1. **Worker Count Configuration**
368368
```go
369369
// CPU-bound workloads
370-
config.WorkerCount = runtime.NumCPU()
370+
config.WorkerCount = runtime.GOMAXPROCS(0)
371371

372372
// I/O-bound workloads
373-
config.WorkerCount = runtime.NumCPU() * 2
373+
config.WorkerCount = runtime.GOMAXPROCS(0) * 2
374374

375375
// Memory-constrained environments
376-
config.WorkerCount = max(2, runtime.NumCPU()/2)
376+
config.WorkerCount = max(2, runtime.GOMAXPROCS(0)/2)
377377
```
378378

379379
2. **Shard Count Optimization**

0 commit comments

Comments
 (0)