mirror of
https://github.com/esphome/esphome.git
synced 2025-09-06 05:12:21 +01:00
improve pool hit rate
This commit is contained in:
@@ -58,19 +58,19 @@ script:
|
|||||||
ESP_LOGI("test", "Phase 1: Simulating normal component lifecycle");
|
ESP_LOGI("test", "Phase 1: Simulating normal component lifecycle");
|
||||||
|
|
||||||
// Sensor update timeouts (common pattern)
|
// Sensor update timeouts (common pattern)
|
||||||
App.scheduler.set_timeout(component, "sensor_init", 100, []() {
|
App.scheduler.set_timeout(component, "sensor_init", 10, []() {
|
||||||
ESP_LOGD("test", "Sensor initialized");
|
ESP_LOGD("test", "Sensor initialized");
|
||||||
id(create_count)++;
|
id(create_count)++;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Retry timeout (gets cancelled if successful)
|
// Retry timeout (gets cancelled if successful)
|
||||||
App.scheduler.set_timeout(component, "retry_timeout", 500, []() {
|
App.scheduler.set_timeout(component, "retry_timeout", 50, []() {
|
||||||
ESP_LOGD("test", "Retry timeout executed");
|
ESP_LOGD("test", "Retry timeout executed");
|
||||||
id(create_count)++;
|
id(create_count)++;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Simulate successful operation - cancel retry
|
// Simulate successful operation - cancel retry
|
||||||
App.scheduler.set_timeout(component, "success_sim", 200, []() {
|
App.scheduler.set_timeout(component, "success_sim", 20, []() {
|
||||||
ESP_LOGD("test", "Operation succeeded, cancelling retry");
|
ESP_LOGD("test", "Operation succeeded, cancelling retry");
|
||||||
App.scheduler.cancel_timeout(id(test_sensor), "retry_timeout");
|
App.scheduler.cancel_timeout(id(test_sensor), "retry_timeout");
|
||||||
id(cancel_count)++;
|
id(cancel_count)++;
|
||||||
@@ -87,7 +87,7 @@ script:
|
|||||||
auto *component = id(test_sensor);
|
auto *component = id(test_sensor);
|
||||||
|
|
||||||
// Multiple sensors with different update intervals
|
// Multiple sensors with different update intervals
|
||||||
App.scheduler.set_interval(component, "temp_sensor", 1000, []() {
|
App.scheduler.set_interval(component, "temp_sensor", 100, []() {
|
||||||
ESP_LOGD("test", "Temperature sensor update");
|
ESP_LOGD("test", "Temperature sensor update");
|
||||||
id(interval_counter)++;
|
id(interval_counter)++;
|
||||||
if (id(interval_counter) >= 3) {
|
if (id(interval_counter) >= 3) {
|
||||||
@@ -96,7 +96,7 @@ script:
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
App.scheduler.set_interval(component, "humidity_sensor", 1500, []() {
|
App.scheduler.set_interval(component, "humidity_sensor", 150, []() {
|
||||||
ESP_LOGD("test", "Humidity sensor update");
|
ESP_LOGD("test", "Humidity sensor update");
|
||||||
id(interval_counter)++;
|
id(interval_counter)++;
|
||||||
if (id(interval_counter) >= 5) {
|
if (id(interval_counter) >= 5) {
|
||||||
@@ -116,19 +116,19 @@ script:
|
|||||||
auto *component = id(test_sensor);
|
auto *component = id(test_sensor);
|
||||||
|
|
||||||
// Connection timeout pattern
|
// Connection timeout pattern
|
||||||
App.scheduler.set_timeout(component, "connect_timeout", 2000, []() {
|
App.scheduler.set_timeout(component, "connect_timeout", 200, []() {
|
||||||
ESP_LOGD("test", "Connection timeout - would retry");
|
ESP_LOGD("test", "Connection timeout - would retry");
|
||||||
id(create_count)++;
|
id(create_count)++;
|
||||||
|
|
||||||
// Schedule retry
|
// Schedule retry
|
||||||
App.scheduler.set_timeout(id(test_sensor), "connect_retry", 1000, []() {
|
App.scheduler.set_timeout(id(test_sensor), "connect_retry", 100, []() {
|
||||||
ESP_LOGD("test", "Retrying connection");
|
ESP_LOGD("test", "Retrying connection");
|
||||||
id(create_count)++;
|
id(create_count)++;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Heartbeat pattern
|
// Heartbeat pattern
|
||||||
App.scheduler.set_interval(component, "heartbeat", 500, []() {
|
App.scheduler.set_interval(component, "heartbeat", 50, []() {
|
||||||
ESP_LOGD("test", "Heartbeat");
|
ESP_LOGD("test", "Heartbeat");
|
||||||
id(interval_counter)++;
|
id(interval_counter)++;
|
||||||
if (id(interval_counter) >= 10) {
|
if (id(interval_counter) >= 10) {
|
||||||
@@ -203,7 +203,7 @@ script:
|
|||||||
|
|
||||||
for (int i = 0; i < reuse_test_count; i++) {
|
for (int i = 0; i < reuse_test_count; i++) {
|
||||||
std::string name = "reuse_test_" + std::to_string(i);
|
std::string name = "reuse_test_" + std::to_string(i);
|
||||||
App.scheduler.set_timeout(component, name, 50 + i * 10, [i]() {
|
App.scheduler.set_timeout(component, name, 10 + i * 5, [i]() {
|
||||||
ESP_LOGD("test", "Reuse test %d completed", i);
|
ESP_LOGD("test", "Reuse test %d completed", i);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -226,7 +226,7 @@ script:
|
|||||||
|
|
||||||
for (int i = 0; i < full_reuse_count; i++) {
|
for (int i = 0; i < full_reuse_count; i++) {
|
||||||
std::string name = "full_reuse_" + std::to_string(i);
|
std::string name = "full_reuse_" + std::to_string(i);
|
||||||
App.scheduler.set_timeout(component, name, 50 + i * 10, [i]() {
|
App.scheduler.set_timeout(component, name, 10 + i * 5, [i]() {
|
||||||
ESP_LOGD("test", "Full reuse test %d completed", i);
|
ESP_LOGD("test", "Full reuse test %d completed", i);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -118,33 +118,33 @@ async def test_scheduler_pool(
|
|||||||
try:
|
try:
|
||||||
# Phase 1: Component lifecycle
|
# Phase 1: Component lifecycle
|
||||||
client.execute_service(phase_services[1], {})
|
client.execute_service(phase_services[1], {})
|
||||||
await asyncio.wait_for(phase_futures[1], timeout=3.0)
|
await asyncio.wait_for(phase_futures[1], timeout=1.0)
|
||||||
await asyncio.sleep(0.5) # Let timeouts complete
|
await asyncio.sleep(0.05) # Let timeouts complete
|
||||||
|
|
||||||
# Phase 2: Sensor polling
|
# Phase 2: Sensor polling
|
||||||
client.execute_service(phase_services[2], {})
|
client.execute_service(phase_services[2], {})
|
||||||
await asyncio.wait_for(phase_futures[2], timeout=3.0)
|
await asyncio.wait_for(phase_futures[2], timeout=1.0)
|
||||||
await asyncio.sleep(1.0) # Let intervals run a bit
|
await asyncio.sleep(0.1) # Let intervals run a bit
|
||||||
|
|
||||||
# Phase 3: Communication patterns
|
# Phase 3: Communication patterns
|
||||||
client.execute_service(phase_services[3], {})
|
client.execute_service(phase_services[3], {})
|
||||||
await asyncio.wait_for(phase_futures[3], timeout=3.0)
|
await asyncio.wait_for(phase_futures[3], timeout=1.0)
|
||||||
await asyncio.sleep(1.0) # Let heartbeat run
|
await asyncio.sleep(0.1) # Let heartbeat run
|
||||||
|
|
||||||
# Phase 4: Defer patterns
|
# Phase 4: Defer patterns
|
||||||
client.execute_service(phase_services[4], {})
|
client.execute_service(phase_services[4], {})
|
||||||
await asyncio.wait_for(phase_futures[4], timeout=3.0)
|
await asyncio.wait_for(phase_futures[4], timeout=1.0)
|
||||||
await asyncio.sleep(2.0) # Let everything settle and recycle
|
await asyncio.sleep(0.2) # Let everything settle and recycle
|
||||||
|
|
||||||
# Phase 5: Pool reuse verification
|
# Phase 5: Pool reuse verification
|
||||||
client.execute_service(phase_services[5], {})
|
client.execute_service(phase_services[5], {})
|
||||||
await asyncio.wait_for(phase_futures[5], timeout=3.0)
|
await asyncio.wait_for(phase_futures[5], timeout=1.0)
|
||||||
await asyncio.sleep(1.0) # Let Phase 5 timeouts complete and recycle
|
await asyncio.sleep(0.1) # Let Phase 5 timeouts complete and recycle
|
||||||
|
|
||||||
# Phase 6: Full pool reuse verification
|
# Phase 6: Full pool reuse verification
|
||||||
client.execute_service(phase_services[6], {})
|
client.execute_service(phase_services[6], {})
|
||||||
await asyncio.wait_for(phase_futures[6], timeout=3.0)
|
await asyncio.wait_for(phase_futures[6], timeout=1.0)
|
||||||
await asyncio.sleep(1.0) # Let Phase 6 timeouts complete
|
await asyncio.sleep(0.1) # Let Phase 6 timeouts complete
|
||||||
|
|
||||||
# Complete test
|
# Complete test
|
||||||
client.execute_service(complete_service, {})
|
client.execute_service(complete_service, {})
|
||||||
|
Reference in New Issue
Block a user