Skip to content

Commit abf236f

Browse files
committed
Use exact number of requests when testing warmup
1 parent fec5b68 commit abf236f

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

lib/libkvm/backend.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,17 @@ void backend_warmup_pause_resume(MachineInstance& machine,
870870
if (!perform_warmup_request(machine, invoc, warmup.headers))
871871
break;
872872
}
873-
/* Check if this was an improvement */
874-
if (const auto* profiler = vm.profiling(); profiler != nullptr) {
873+
if (warmup.exact) {
874+
// Exact number of warmup requests, so just do that many
875+
if (i+1 >= warmup.num_requests) {
876+
if (machine.tenant().config.group.verbose) {
877+
printf("Warmup: Completed %d exact warmup requests\n", warmup.num_requests);
878+
}
879+
break;
880+
}
881+
}
882+
else if (const auto* profiler = vm.profiling(); profiler != nullptr) {
883+
/* Heuristic: Check if this was an improvement */
875884
const auto& samples = profiler->times[tinykvm::MachineProfiling::UserDefined];
876885
const bool is_improvement = (samples.back() < best_time);
877886
if (is_improvement) {

lib/libkvm/tenant.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ static void configure_group(const std::string& name, kvm::TenantGroup& group, co
527527
} else {
528528
group.warmup->num_requests = 20;
529529
}
530+
if (obj2.contains("exact")) {
531+
group.warmup->exact = obj2["exact"];
532+
}
530533
if (obj2.contains("url")) {
531534
group.warmup->url = obj2["url"];
532535
}

lib/libkvm/tenant.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct TenantGroup {
4848
/* Warmup the VM before starting 'real' request handling. */
4949
struct Warmup {
5050
uint16_t num_requests = 0;
51+
bool exact = false; /* Use exact number of requests, otherwise heuristic */
5152
std::string url = "/";
5253
std::string method = "GET";
5354
std::unordered_set<std::string> headers {

src/tinykvm/tests/warmup.vtc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ int main(int argc, char **argv)
1515
while (1) {
1616
wait_for_requests_paused(&req);
1717

18-
if (counter < 15) {
18+
if (IS_WARMUP_REQUEST(&req)) {
1919
assert(strcmp(req.url, "/warmup") == 0);
2020
} else {
2121
assert(strcmp(req.url, "/1") == 0);
@@ -56,6 +56,7 @@ vcl 4.1;
5656
"filename": "${tmpdir}/hello",
5757
"warmup": {
5858
"num_requests": 15,
59+
"exact": true,
5960
"url": "/warmup",
6061
"headers": [
6162
"Host: localhost",

0 commit comments

Comments
 (0)