-
Notifications
You must be signed in to change notification settings - Fork 37
Sleep mode #252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Sleep mode #252
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
91b6664
Sleep mode
irar2 aba9a61
lint
irar2 25ff57b
Disable the new sleep test to check if it causes the problem
irar2 8230a6a
Wait before sending request
irar2 1ac02d3
Review comments and test fix
irar2 874a5c7
Log levels and lint
irar2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| Copyright 2025 The llm-d-inference-sim Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package common | ||
|
|
||
| import ( | ||
| "github.com/onsi/gomega" | ||
| zmq "github.com/pebbe/zmq4" | ||
| ) | ||
|
|
||
| // CreateSub creates a ZMQ sub, subscribes to the provided topic, and returns the | ||
| // sub and the endpoint to publish events on | ||
| func CreateSub(topic string) (*zmq.Socket, string) { | ||
| wildcardEndpoint := "tcp://*:*" | ||
| zctx, err := zmq.NewContext() | ||
| gomega.Expect(err).NotTo(gomega.HaveOccurred()) | ||
| sub, err := zctx.NewSocket(zmq.SUB) | ||
| gomega.Expect(err).NotTo(gomega.HaveOccurred()) | ||
| err = sub.Bind(wildcardEndpoint) | ||
| gomega.Expect(err).NotTo(gomega.HaveOccurred()) | ||
| // get the actual port | ||
| endpoint, err := sub.GetLastEndpoint() | ||
| gomega.Expect(err).NotTo(gomega.HaveOccurred()) | ||
| err = sub.SetSubscribe(topic) | ||
| gomega.Expect(err).NotTo(gomega.HaveOccurred()) | ||
| return sub, endpoint | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ import ( | |
|
|
||
| "github.com/go-logr/logr" | ||
| "github.com/llm-d/llm-d-inference-sim/pkg/common" | ||
| "github.com/llm-d/llm-d-inference-sim/pkg/common/logging" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -42,6 +43,7 @@ type blockCache struct { | |
| eventChan chan EventData // channel for asynchronous event processing | ||
| usageChan chan float64 // channel for usage reporting | ||
| logger logr.Logger | ||
| disabled bool // indicated whether the cache is disabled | ||
| } | ||
|
|
||
| // newBlockCache creates a new blockCache with the specified maximum number of blocks | ||
|
|
@@ -58,31 +60,66 @@ func newBlockCache(config *common.Configuration, logger logr.Logger, usageChan c | |
| } | ||
| } | ||
|
|
||
| eventSender := NewKVEventSender(publisher, CreateKVEventsTopic(config.Port, config.Model), | ||
| eChan, config.EventBatchSize, delay, logger) | ||
|
|
||
| return &blockCache{ | ||
| requestToBlocks: make(map[string][]uint64), | ||
| usedBlocks: make(map[uint64]int), | ||
| unusedBlocks: make(map[uint64]time.Time), | ||
| maxBlocks: config.KVCacheSize, | ||
| eventChan: eChan, | ||
| usageChan: usageChan, | ||
| eventSender: NewKVEventSender(publisher, createTopic(config), eChan, config.EventBatchSize, delay, logger), | ||
| eventSender: eventSender, | ||
| logger: logger, | ||
| }, nil | ||
| } | ||
|
|
||
| func (bc *blockCache) start(ctx context.Context) { | ||
| bc.logger.V(logging.TRACE).Info("Starting KV cache") | ||
| err := bc.eventSender.Run(ctx) | ||
| if err != nil { | ||
| bc.logger.Error(err, "Sender stopped with error") | ||
| } | ||
| } | ||
|
|
||
| func (bc *blockCache) discard() { | ||
| bc.logger.V(logging.TRACE).Info("Discarding KV cache") | ||
|
||
|
|
||
| bc.mu.Lock() | ||
| defer bc.mu.Unlock() | ||
|
|
||
| bc.disabled = true | ||
|
|
||
| bc.requestToBlocks = make(map[string][]uint64) | ||
| bc.usedBlocks = make(map[uint64]int) | ||
| bc.unusedBlocks = make(map[uint64]time.Time) | ||
|
|
||
| common.WriteToChannel(bc.eventChan, | ||
| EventData{action: eventActionAllBlocksCleared}, | ||
| bc.logger, "block cache eventChan") | ||
| } | ||
|
|
||
| func (bc *blockCache) activate() { | ||
| bc.logger.V(logging.TRACE).Info("Activating KV cache") | ||
|
||
|
|
||
| bc.mu.Lock() | ||
| defer bc.mu.Unlock() | ||
|
|
||
| bc.disabled = false | ||
| } | ||
|
|
||
| // startRequest adds a request with its associated block hashes to the cache | ||
| // and returns the number of blocks that were already in the cache | ||
| func (bc *blockCache) startRequest(requestID string, blocks []uint64) (int, error) { | ||
| bc.mu.Lock() | ||
| defer bc.mu.Unlock() | ||
|
|
||
| if bc.disabled { | ||
| bc.logger.V(logging.TRACE).Info("KV cache is disabled, request is not added to the kv cache") | ||
| return 0, nil | ||
| } | ||
|
|
||
| if _, exists := bc.requestToBlocks[requestID]; exists { | ||
| // request with the same id already exists | ||
| return 0, fmt.Errorf("request already exists for id %s", requestID) | ||
|
|
@@ -167,6 +204,11 @@ func (bc *blockCache) finishRequest(requestID string) error { | |
| bc.mu.Lock() | ||
| defer bc.mu.Unlock() | ||
|
|
||
| if bc.disabled { | ||
| bc.logger.V(logging.TRACE).Info("KV cache is disabled, request completion is not processed by the kv cache") | ||
| return nil | ||
| } | ||
|
|
||
| // Get blocks associated with this request | ||
| blockHashes, exists := bc.requestToBlocks[requestID] | ||
| if !exists { | ||
|
|
@@ -239,6 +281,6 @@ func (bc *blockCache) getBlockInfo(blockHash uint64) (int, bool) { | |
| return 0, false | ||
| } | ||
|
|
||
| func createTopic(config *common.Configuration) string { | ||
| return fmt.Sprintf("kv@$localhost:%d@%s", config.Port, config.Model) | ||
| func CreateKVEventsTopic(port int, model string) string { | ||
| return fmt.Sprintf("kv@$localhost:%d@%s", port, model) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this log message is not supposed to be printed a lot, consider to report on INFO level