Skip to content

Resourse check on event rebased - #137

Merged
perk11 merged 2 commits into
mainfrom
resourse-check-on-event-rebased
Aug 1, 2026
Merged

Resourse check on event rebased#137
perk11 merged 2 commits into
mainfrom
resourse-check-on-event-rebased

Conversation

@perk11

@perk11 perk11 commented Jul 5, 2026

Copy link
Copy Markdown
Owner

No description provided.

@perk11
perk11 force-pushed the resourse-check-on-event-rebased branch 3 times, most recently from 3d63372 to 599981d Compare July 28, 2026 01:50
@perk11
perk11 requested a review from Copilot July 28, 2026 02:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates large-model-proxy’s resource monitoring and management/status reporting to better represent asynchronous service lifecycle states (waiting/starting/running) and to make resource checks more event-driven, with corresponding UI and test updates.

Changes:

  • Revamps /status output to expose status, waiting_connections, proxied_connections, and richer per-resource metrics (free, in_use, reserved_by_starting_services, total).
  • Reworks CheckCommand-based resource monitoring to support immediate rechecks via events/unpause signals and broadcasts.
  • Updates management UI and expands/refactors tests to assert the new state machine and timing behavior more reliably (polling helpers instead of fixed sleeps in several places).

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
util_test.go Adds new test helpers for resource/service state assertions and polling.
README.md Documents CheckCommand behavior and new status/connection fields.
monitor_resources.go Adds event-driven resource check triggering and change broadcasting helpers.
monitor_resources_test.go Updates resource-check tests to use new status/resource fields and polling.
management-ui/index.html Updates UI to display new status/connection/resource fields and new sort option.
management_api.go Changes /status schema and populates new connection/resource fields.
management_api_test.go Updates tests to use the new /status response types and helpers.
main.go Implements waiting/proxied connection tracking, event-based resource rechecks, and new service state handling.
main_test.go Adds regression tests for shutdown deadlocks, waiting-connection leaks, and resource-check edge cases.
config.go Formatting-only adjustments for ResourceAvailable fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread management_api.go
Comment on lines +68 to +70
} else {
free = resourceManager.resourcesAvailable[resourceName]
}
Comment thread main.go Outdated
log.Printf("[%s] Failed to find a service to stop; will check every 100ms.", requestingService)
} else if iteration%logOutputIterationFrequency == 0 {
log.Printf("[%s] Failed to find a service to stop; continuing to check every 100ms.", requestingService)
resourceChangeServiceChannel := make(chan bool)
Comment thread main.go Outdated

resourceChangeByResourceMutex *sync.Mutex //Also covers checkCommandFirstChangeByResourceChans
checkCommandFirstChangeByResourceChans map[string]map[string]chan struct{}
resourceChangeByResourceChans map[string]map[string]chan bool //true if amount is already updated, false if CheckCommands needs to run
Comment thread monitor_resources.go
Comment on lines +100 to +106
func (rm ResourceManager) broadcastResourceChanges(resources iter.Seq[string], recheckNeeded bool) {
resourceManager.resourceChangeByResourceMutex.Lock()
for resource := range resources {
rm.broadcastResourceChangeWhenResourceChangeByResourceMutexIsLocked(resource, recheckNeeded)
}
resourceManager.resourceChangeByResourceMutex.Unlock()
}
Comment thread management-ui/index.html Outdated
Comment on lines 202 to 209
let sortOrder = localStorage.getItem("sortOrder");
if (sortOrder === null) {
sortOrder = "last_used";
} else if (sortOrder === "proxied_connections") {
// proxied_connections is no longer a valid sort option but may exist in localStorage; this migration code can be removed in the future.
localStorage.setItem("sortOrder", "connections");
sortOrder = "connections";
}
@perk11
perk11 force-pushed the resourse-check-on-event-rebased branch from 599981d to 3981c4a Compare July 28, 2026 02:44
@perk11 perk11 mentioned this pull request Jul 30, 2026
@perk11
perk11 force-pushed the resourse-check-on-event-rebased branch 10 times, most recently from 9d2f678 to a721bd5 Compare August 1, 2026 02:06
perk11 added 2 commits July 31, 2026 21:20
A service is no longer started or kept waiting for a client that has already
disconnected, and clients waiting on resources are unblocked the moment those
resources free up rather than on the next poll.

What changes in practice
- A client that disconnects during startup — queued behind another start,
  waiting on a healthcheck, or blocked on resources — is dropped right away.
- Contended resources (e.g. free VRAM reported by a check command) are
  monitored reactively: waiters wake the instant a service releases resources,
  and the check command only runs while something is actually waiting for it.
- /status describes each service more precisely: stopped /
  waiting_for_resources / starting / running, with separate waiting vs.
  proxied connection counts, and resources broken down into Total / Reserved /
  In-use / Free.

Implementation notes
- Cancellation: manageMutex is now a channelMutex (a buffered-channel lock
  supporting select-based cancellation), and the client-disconnect signal
  threads through startService -> reserveResources / performHealthCheck /
  connectToService.
- Monitoring: reserveResources no longer sleeps in a poll loop; service stops,
  the last connection closing, and monitor-measured changes broadcast on
  per-resource channels. The per-resource monitor runs its CheckCommand only
  while a waiter is registered and re-runs it on demand when a cached value
  may be stale; slow check commands run without holding the global
  serviceMutex.
- Concurrency: runningServices is map[string]*RunningService; monitorProcess
  signals exitWaitGroup before acquiring serviceMutex (avoids a shutdown
  deadlock); idleTimer access and the post-cleanup nil check are serialized
  under serviceMutex; resourcesAvailable gains its own mutex. The process-exit
  test hook is gated behind the "testhooks" build tag.
… dashboard

The dashboard now reports each service's lifecycle state and a per-resource
breakdown of reserved/in-use/free capacity, making it easy to see at a glance
what is running, what is still starting or starved for resources, and how much
headroom is left.

Dashboard
- Service rows are colored by status (stopped / waiting_for_resources /
  starting / running), with waiting vs. proxied connections in separate
  columns — making it obvious when requests are queued behind a startup
  instead of silently counted as "active".
- The resource section reports Reserved-by-starting / In-use / Free / Total
  instead of a single used/available pair; Total shows "N/A" for
  CheckCommand-backed resources whose capacity is only known dynamically.

README: document the status, waiting_connections, and proxied_connections
service fields and the resource fields (total, reserved_by_starting_services,
in_use, free, usage_by_service), including the Total / "N/A" semantics.
@perk11
perk11 force-pushed the resourse-check-on-event-rebased branch from a721bd5 to 35e65bb Compare August 1, 2026 02:22
@perk11
perk11 merged commit 432f466 into main Aug 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants