Skip to content

Commit 1626c61

Browse files
committed
perf: optimize indexer config for multi-core systems
1 parent 29ff77a commit 1626c61

File tree

90 files changed

+16153
-7695
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+16153
-7695
lines changed

api/nginx_log/analytics.go

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ func GetDashboardAnalytics(c *gin.Context) {
554554
c.JSON(http.StatusBadRequest, ErrorResponse{Error: "Invalid start_date format, expected YYYY-MM-DD: " + err.Error()})
555555
return
556556
}
557+
// Convert to UTC for consistent processing
558+
startTime = startTime.UTC()
557559
}
558560

559561
if req.EndDate != "" {
@@ -562,8 +564,8 @@ func GetDashboardAnalytics(c *gin.Context) {
562564
c.JSON(http.StatusBadRequest, ErrorResponse{Error: "Invalid end_date format, expected YYYY-MM-DD: " + err.Error()})
563565
return
564566
}
565-
// Set end time to end of day
566-
endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
567+
// Set end time to end of day and convert to UTC
568+
endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second).UTC()
567569
}
568570

569571
// Set default time range if not provided (last 30 days)
@@ -578,17 +580,14 @@ func GetDashboardAnalytics(c *gin.Context) {
578580

579581
logger.Debugf("Dashboard request for log_path: %s, parsed start_time: %v, end_time: %v", req.LogPath, startTime, endTime)
580582

581-
// For Dashboard queries, only query the specific file requested, not the entire log group
582-
// This ensures that when user clicks on a specific file, they see data only from that file
583-
logPaths := []string{req.LogPath}
584-
585-
// Debug: Log the paths being queried
586-
logger.Debugf("Dashboard querying specific log path: %s", req.LogPath)
583+
// Use main_log_path field for efficient log group queries instead of expanding file paths
584+
// This provides much better performance by using indexed field filtering
585+
logger.Debugf("Dashboard querying log group with main_log_path: %s", req.LogPath)
587586

588587
// Build dashboard query request
589588
dashboardReq := &analytics.DashboardQueryRequest{
590589
LogPath: req.LogPath,
591-
LogPaths: logPaths,
590+
LogPaths: []string{req.LogPath}, // Use single main log path
592591
StartTime: startTime.Unix(),
593592
EndTime: endTime.Unix(),
594593
}
@@ -652,24 +651,20 @@ func GetWorldMapData(c *gin.Context) {
652651
}
653652
}
654653

655-
// Expand log path for filtering
656-
logPaths, err := nginx_log.ExpandLogGroupPath(req.Path)
657-
if err != nil {
658-
logger.Warnf("Could not expand log group path for world map %s: %v", req.Path, err)
659-
logPaths = []string{req.Path} // Fallback
660-
}
661-
logger.Debugf("WorldMapData - Expanded log paths: %v", logPaths)
654+
// Use main_log_path field for efficient log group queries instead of expanding file paths
655+
logger.Debugf("WorldMapData - Using main_log_path field for log group: %s", req.Path)
662656

663657
// Get world map data with timeout
664658
ctx, cancel := context.WithTimeout(c.Request.Context(), 30*time.Second)
665659
defer cancel()
666660

667661
geoReq := &analytics.GeoQueryRequest{
668-
StartTime: req.StartTime,
669-
EndTime: req.EndTime,
670-
LogPath: req.Path,
671-
LogPaths: logPaths,
672-
Limit: req.Limit,
662+
StartTime: req.StartTime,
663+
EndTime: req.EndTime,
664+
LogPath: req.Path,
665+
LogPaths: []string{req.Path}, // Use single main log path
666+
UseMainLogPath: true, // Use main_log_path field for efficient queries
667+
Limit: req.Limit,
673668
}
674669
logger.Debugf("WorldMapData - GeoQueryRequest: %+v", geoReq)
675670

@@ -757,24 +752,20 @@ func GetChinaMapData(c *gin.Context) {
757752
}
758753
}
759754

760-
// Expand log path for filtering
761-
logPaths, err := nginx_log.ExpandLogGroupPath(req.Path)
762-
if err != nil {
763-
logger.Warnf("Could not expand log group path for China map %s: %v", req.Path, err)
764-
logPaths = []string{req.Path} // Fallback
765-
}
766-
logger.Debugf("ChinaMapData - Expanded log paths: %v", logPaths)
755+
// Use main_log_path field for efficient log group queries instead of expanding file paths
756+
logger.Debugf("ChinaMapData - Using main_log_path field for log group: %s", req.Path)
767757

768758
// Get China map data with timeout
769759
ctx, cancel := context.WithTimeout(c.Request.Context(), 30*time.Second)
770760
defer cancel()
771761

772762
geoReq := &analytics.GeoQueryRequest{
773-
StartTime: req.StartTime,
774-
EndTime: req.EndTime,
775-
LogPath: req.Path,
776-
LogPaths: logPaths,
777-
Limit: req.Limit,
763+
StartTime: req.StartTime,
764+
EndTime: req.EndTime,
765+
LogPath: req.Path,
766+
LogPaths: []string{req.Path}, // Use single main log path
767+
UseMainLogPath: true, // Use main_log_path field for efficient queries
768+
Limit: req.Limit,
778769
}
779770
logger.Debugf("ChinaMapData - GeoQueryRequest: %+v", geoReq)
780771

@@ -855,12 +846,8 @@ func GetGeoStats(c *gin.Context) {
855846
}
856847
}
857848

858-
// Expand log path for filtering
859-
logPaths, err := nginx_log.ExpandLogGroupPath(req.Path)
860-
if err != nil {
861-
logger.Warnf("Could not expand log group path for geo stats %s: %v", req.Path, err)
862-
logPaths = []string{req.Path} // Fallback
863-
}
849+
// Use main_log_path field for efficient log group queries instead of expanding file paths
850+
logger.Debugf("GeoStats - Using main_log_path field for log group: %s", req.Path)
864851

865852
// Set default limit if not provided
866853
if req.Limit == 0 {
@@ -872,11 +859,12 @@ func GetGeoStats(c *gin.Context) {
872859
defer cancel()
873860

874861
geoReq := &analytics.GeoQueryRequest{
875-
StartTime: req.StartTime,
876-
EndTime: req.EndTime,
877-
LogPath: req.Path,
878-
LogPaths: logPaths,
879-
Limit: req.Limit,
862+
StartTime: req.StartTime,
863+
EndTime: req.EndTime,
864+
LogPath: req.Path,
865+
LogPaths: []string{req.Path}, // Use single main log path
866+
UseMainLogPath: true, // Use main_log_path field for efficient queries
867+
Limit: req.Limit,
880868
}
881869

882870
stats, err := analyticsService.GetTopCountries(ctx, geoReq)
@@ -902,10 +890,11 @@ func getCardinalityCount(ctx context.Context, field string, searchReq *searcher.
902890

903891
// Create a CardinalityRequest from the SearchRequest
904892
cardReq := &searcher.CardinalityRequest{
905-
Field: field,
906-
StartTime: searchReq.StartTime,
907-
EndTime: searchReq.EndTime,
908-
LogPaths: searchReq.LogPaths,
893+
Field: field,
894+
StartTime: searchReq.StartTime,
895+
EndTime: searchReq.EndTime,
896+
LogPaths: searchReq.LogPaths,
897+
UseMainLogPath: searchReq.UseMainLogPath, // Use main_log_path field if enabled
909898
}
910899
logger.Debugf("🔍 CardinalityRequest: Field=%s, StartTime=%v, EndTime=%v, LogPaths=%v",
911900
cardReq.Field, cardReq.StartTime, cardReq.EndTime, cardReq.LogPaths)

api/nginx_log/index_management.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ func RebuildIndex(c *gin.Context) {
108108
}
109109

110110
// performAsyncRebuild performs the actual rebuild logic asynchronously
111+
// For incremental indexing of a specific log group, it preserves existing metadata
112+
// For full rebuilds (path == ""), it clears all metadata first
111113
func performAsyncRebuild(modernIndexer interface{}, path string) {
112114
processingManager := event.GetProcessingStatusManager()
113115

@@ -278,12 +280,9 @@ func rebuildSingleFile(modernIndexer interface{}, path string, logFileManager in
278280
} else {
279281
logger.Infof("Starting modern index rebuild for file: %s", path)
280282

281-
// Clear existing database records for this log group before rebuilding
282-
if logFileManager != nil {
283-
if err := logFileManager.(indexer.MetadataManager).DeleteIndexMetadataByGroup(path); err != nil {
284-
logger.Warnf("Could not clean up existing DB records for log group %s: %v", path, err)
285-
}
286-
}
283+
// NOTE: We intentionally do NOT delete existing index metadata here
284+
// This allows incremental indexing to work properly with rotated logs
285+
// The IndexLogGroupWithProgress method will handle updating existing records
287286

288287
startTime := time.Now()
289288

@@ -340,6 +339,8 @@ func rebuildAllFiles(modernIndexer interface{}, logFileManager interface{}, prog
340339
releaseRebuildLock(globalLockKey)
341340
}()
342341

342+
// For full rebuild, we clear ALL existing metadata to start fresh
343+
// This is different from single file/group rebuild which preserves metadata for incremental indexing
343344
if logFileManager != nil {
344345
if err := logFileManager.(indexer.MetadataManager).DeleteAllIndexMetadata(); err != nil {
345346
logger.Errorf("Could not clean up all old DB records before full rebuild: %v", err)

app/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ declare module 'vue' {
8686
CodeEditorCodeEditor: typeof import('./src/components/CodeEditor/CodeEditor.vue')['default']
8787
ConfigHistoryConfigHistory: typeof import('./src/components/ConfigHistory/ConfigHistory.vue')['default']
8888
ConfigHistoryDiffViewer: typeof import('./src/components/ConfigHistory/DiffViewer.vue')['default']
89+
DevDebugPanelDevDebugPanel: typeof import('./src/components/DevDebugPanel/DevDebugPanel.vue')['default']
8990
FooterToolbarFooterToolBar: typeof import('./src/components/FooterToolbar/FooterToolBar.vue')['default']
9091
ICPICP: typeof import('./src/components/ICP/ICP.vue')['default']
9192
LLMChatMessage: typeof import('./src/components/LLM/ChatMessage.vue')['default']

app/src/api/system.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { http } from '@uozi-admin/request'
2+
3+
export interface ProcessStats {
4+
pid: number
5+
}
6+
7+
export interface RestartResponse {
8+
message: string
9+
}
10+
11+
const system = {
12+
getProcessStats(): Promise<ProcessStats> {
13+
return http.get('/system/stats')
14+
},
15+
16+
restart(): Promise<RestartResponse> {
17+
return http.post('/system/restart')
18+
},
19+
}
20+
21+
export default system

0 commit comments

Comments
 (0)