From 21394b7d45e1d8a480ed709b17db2869280b1048 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Thu, 22 Dec 2022 15:22:25 +0530 Subject: [PATCH 1/3] Reduce the delay between clicking 'Make Image' and making the render call to the server. Was nearly 4-5 seconds, now it's about 250-300ms. This is a hacky workaround until a better solution is found --- ui/media/js/engine.js | 10 ++++++---- ui/media/js/main.js | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ui/media/js/engine.js b/ui/media/js/engine.js index 934ade4d..95725dfc 100644 --- a/ui/media/js/engine.js +++ b/ui/media/js/engine.js @@ -8,7 +8,7 @@ const SERVER_STATE_VALIDITY_DURATION = 90 * 1000 // ms - 90 seconds to allow ping to timeout more than once before killing tasks. const HEALTH_PING_INTERVAL = 5000 // ms const IDLE_COOLDOWN = 2500 // ms - const CONCURRENT_TASK_INTERVAL = 500 // ms + const CONCURRENT_TASK_INTERVAL = 100 // ms /** Connects to an endpoint and resumes connection after reaching end of stream until all data is received. * Allows closing the connection while the server buffers more data. @@ -839,6 +839,8 @@ * @memberof Task */ async post(timeout=-1) { + performance.mark('make-render-request') + console.log('delay between clicking and making the server request:', performance.measure('diff', 'click-makeImage', 'make-render-request').duration + ' ms') let jsonResponse = await super.post('/render', timeout) if (typeof jsonResponse?.task !== 'number') { console.warn('Endpoint error response: ', jsonResponse) @@ -1106,9 +1108,9 @@ idleEventPromise = makeQuerablePromise(eventSource.fireEvent(EVENT_IDLE, {capacity: serverCapacity, idle: true})) } // Calling idle could result in task being added to queue. - if (task_queue.size <= 0 && concurrent_generators.size <= 0) { - return asyncDelay(IDLE_COOLDOWN).then(() => idleEventPromise) - } + // if (task_queue.size <= 0 && concurrent_generators.size <= 0) { + // return asyncDelay(IDLE_COOLDOWN).then(() => idleEventPromise) + // } } if (task_queue.size < serverCapacity) { if (!idleEventPromise?.isPending) { diff --git a/ui/media/js/main.js b/ui/media/js/main.js index 95b93ce4..5fd34844 100644 --- a/ui/media/js/main.js +++ b/ui/media/js/main.js @@ -429,6 +429,7 @@ function getUncompletedTaskEntries() { } function makeImage() { + performance.mark('click-makeImage') if (!SD.isServerAvailable()) { alert('The server is not available.') return From 5cb24f992cb6bddbc79c7d795b6b4d7b7b80b86b Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Thu, 22 Dec 2022 15:23:07 +0530 Subject: [PATCH 2/3] Bump version --- ui/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/index.html b/ui/index.html index d9b469da..89ece0b6 100644 --- a/ui/index.html +++ b/ui/index.html @@ -25,7 +25,7 @@
From cf2408013e86c0369afc606456f7f2199e0dd58c Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Fri, 23 Dec 2022 10:54:40 +0530 Subject: [PATCH 3/3] Measure the click-to-render-request latency, only if the click button was used --- ui/media/js/engine.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/media/js/engine.js b/ui/media/js/engine.js index 95725dfc..467a45c5 100644 --- a/ui/media/js/engine.js +++ b/ui/media/js/engine.js @@ -840,7 +840,9 @@ */ async post(timeout=-1) { performance.mark('make-render-request') - console.log('delay between clicking and making the server request:', performance.measure('diff', 'click-makeImage', 'make-render-request').duration + ' ms') + if (performance.getEntriesByName('click-makeImage', 'mark').length > 0) { + console.log('delay between clicking and making the server request:', performance.measure('diff', 'click-makeImage', 'make-render-request').duration + ' ms') + } let jsonResponse = await super.post('/render', timeout) if (typeof jsonResponse?.task !== 'number') { console.warn('Endpoint error response: ', jsonResponse)