- Notifications
You must be signed in to change notification settings - Fork927
Open
Labels
Description
Description
This issue tracks a possible future improvement to the way expired prebuilds are filtered in the system.
Currently, we usein-memory filtering to separate expired from running (non-expired) prebuilds when constructing thePresetSnapshot
:
coder/coderd/prebuilds/global_snapshot.go
Lines 95 to 113 in7b273b0
funcfilterExpiredWorkspaces(preset database.GetTemplatePresetsWithPrebuildsRow,runningWorkspaces []database.GetRunningPrebuiltWorkspacesRow) (nonExpired []database.GetRunningPrebuiltWorkspacesRow,expired []database.GetRunningPrebuiltWorkspacesRow) { | |
if!preset.Ttl.Valid { | |
returnrunningWorkspaces,expired | |
} | |
ttl:=time.Duration(preset.Ttl.Int32)*time.Second | |
ifttl<=0 { | |
returnrunningWorkspaces,expired | |
} | |
for_,prebuild:=rangerunningWorkspaces { | |
iftime.Since(prebuild.CreatedAt)>ttl { | |
expired=append(expired,prebuild) | |
}else { | |
nonExpired=append(nonExpired,prebuild) | |
} | |
} | |
returnnonExpired,expired | |
} |
This approach is simple and performs well at the current scale. However, if the number of running prebuilds increases significantly, it may become a performance concern.
Context
- Database query
GetRunningPrebuiltWorkspaces
returns all running workspaces (non-expired and expired workspaces). - A new slice
Expired
was added toPresetSnapshot
, populated via in-memory filtering. - We chose not to add a DB query yet to keep the implementation small and simple:feat: implement expiration policy logic for prebuilds #17996 (comment)
Potential Improvement:
- Introduce a dedicated database query to fetch expired workspaces.
- Update the current
GetRunningPrebuiltWorkspaces
database query to only return non-expired workspaces. - This would avoid loading all running prebuilds into memory and manually filtering them.
- Likely to be more efficient at larger scale.
While in-memory filtering is sufficient for now, introducing a DB query helps future-proof the system and ensures consistent performance in larger on-prem installations.
Action Items
- Monitor performance as prebuild usage increases.
- Revisit this issue if:
- Prebuild count grows significantly.
- Memory usage or latency becomes a concern in prebuild snapshot construction.