I'm writing a node app using typescript and the aws-sdk to call Athena. Occasionally, the call to Athena will timeout after a minute of waiting for the Athena response. The thing I don't understand is that if I go to the AWS console and look at the Athena History tab, it says my query took 4 seconds to succeed, yet in my code it runs for over a minute waiting for a response. I'm hoping there's something I'm doing wrong in my code.
myFunct... {
const athena = getAthena();
const startQueryExecutionResponse: StartQueryExecutionOutput = await athena.startQueryExecution(params).promise();
let status = "UNKNOWN";
do {
await sleep(1000);
status = await getQueryStatus(athena, startQueryExecutionResponse);
} while (status === "QUEUED" || status === "RUNNING");
return await athena.getQueryResults(startQueryExecutionResponse as GetQueryResultsInput).promise();
};
const sleep = (ms: number) => {
return new Promise(resolve => {
setTimeout(resolve, ms)
})
};
const getQueryStatus = async (athena: AWS.Athena, startQueryExecutionResponse: Athena.StartQueryExecutionOutput): Promise<QueryExecutionState> => {
const result: GetQueryExecutionOutput = await athena.getQueryExecution(startQueryExecutionResponse as GetQueryResultsInput).promise();
console.log(result);
return result!.QueryExecution!.Status!.State || "Unknown"
};
The code gets stuck in that while loop, and I can see from the console.log below, that the status is Status: { State: 'RUNNING', SubmissionDateTime: 2019-07-23T18:28:00.639Z },
over and over again.
If the AWS console says this query took 4 seconds to complete, why does the getQueryExecution response say it's still RUNNING for minutes?
The history in the Athena console shows execution time. In addition to execution time, there is time in queue, planning, and service processing. I've had queries stuck in queue for much longer than the execution time. I think this is likely in your case. Also, the Athena showed queued queries as "RUNNING" until recently.
More info here: AWS Athena concurrency limits: Number of submitted queries VS number of running queries
Example stats of a query stuck in queue:
"Statistics": {
"EngineExecutionTimeInMillis": 2689,
"DataScannedInBytes": 35347476,
"TotalExecutionTimeInMillis": 106676,
"QueryQueueTimeInMillis": 103971,
"QueryPlanningTimeInMillis": 600,
"ServiceProcessingTimeInMillis": 16
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With