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

This commit is contained in:
cmdr2 2022-12-22 15:22:25 +05:30
parent 768fb2583a
commit 21394b7d45
2 changed files with 7 additions and 4 deletions

View File

@ -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 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 HEALTH_PING_INTERVAL = 5000 // ms
const IDLE_COOLDOWN = 2500 // 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. /** 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. * Allows closing the connection while the server buffers more data.
@ -839,6 +839,8 @@
* @memberof Task * @memberof Task
*/ */
async post(timeout=-1) { 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) let jsonResponse = await super.post('/render', timeout)
if (typeof jsonResponse?.task !== 'number') { if (typeof jsonResponse?.task !== 'number') {
console.warn('Endpoint error response: ', jsonResponse) console.warn('Endpoint error response: ', jsonResponse)
@ -1106,9 +1108,9 @@
idleEventPromise = makeQuerablePromise(eventSource.fireEvent(EVENT_IDLE, {capacity: serverCapacity, idle: true})) idleEventPromise = makeQuerablePromise(eventSource.fireEvent(EVENT_IDLE, {capacity: serverCapacity, idle: true}))
} }
// Calling idle could result in task being added to queue. // Calling idle could result in task being added to queue.
if (task_queue.size <= 0 && concurrent_generators.size <= 0) { // if (task_queue.size <= 0 && concurrent_generators.size <= 0) {
return asyncDelay(IDLE_COOLDOWN).then(() => idleEventPromise) // return asyncDelay(IDLE_COOLDOWN).then(() => idleEventPromise)
} // }
} }
if (task_queue.size < serverCapacity) { if (task_queue.size < serverCapacity) {
if (!idleEventPromise?.isPending) { if (!idleEventPromise?.isPending) {

View File

@ -429,6 +429,7 @@ function getUncompletedTaskEntries() {
} }
function makeImage() { function makeImage() {
performance.mark('click-makeImage')
if (!SD.isServerAvailable()) { if (!SD.isServerAvailable()) {
alert('The server is not available.') alert('The server is not available.')
return return