Reputation: 305
I've been testing the amount of time it takes to send a message and receive it from an SQS queue. It takes an average of 800-1200 ms, which seems like a ridiculously long time. Here is my code for testing, please tell me if I'm doing something wrong.
var t0;
sendMessage('hello');
function sendMessage(message){
var params = {
MessageBody: message,
QueueUrl: queueUrl
};
t0 = now();
sqs.sendMessage(params, function(err,data){
if(err){
throw err;
} else {
console.log("Message Send Confirmation");
}
});
unbatch();
}
async function unbatch(){
var params = {
QueueUrl: queueUrl,
MaxNumberOfMessages: 10
};
var go = true;
while(go){
console.log("Polling...");
sqs.receiveMessage(params, function(err, data){
if(data.Messages){
console.log("Message Received");
console.log("Total Time: " + ((now() - t0)/1000));
go = false;
var deleteParams = {
QueueUrl: queueUrl,
ReceiptHandle: data.Messages[0].ReceiptHandle
};
sqs.deleteMessage(deleteParams, function(err, data) {
if (err) {
console.log("Delete Error", err);
} else {
console.log("Message Deleted");
}
});
}
});
await sleep(1);
}
}
function sleep(ms){
return new Promise(resolve => setTimeout(resolve, ms));
}
It sends the message and immediately begins trying to recieve a message every millisecond. Once received, it calculates the time. Shouldn't this be taking significantly less time?
Upvotes: 5
Views: 10350
Reputation: 12420
The reason you would use any queue is not for performance but rather for resilience.
Queues solve many problems, they provide async communications between disconnected systems, they allow you to scale systems really well, and provide enhanced resilience ensuring that messages do not get "lost" in the event of a system failure.
When working with queues you should rather consider designing your system around the concept of eventual consistency
which means your message will eventually get there and processed but maybe not when or even in the order you expect.
Capabilities such speed, ordering, retrying etc. will vary between queue implementations (SQS, Kafka, RabbitMq etc.)
If you are looking for super high IOPS then perhaps queues aren't what you want.
Upvotes: 5