C Smith
C Smith

Reputation: 49

Jedis as message queue performance

I am using the Java library Jedis ontop of a Redis queue which I am using as a producer/consumer queue. It was easy to set up and is working nicely.

Consumer code below

List<String> messages = jedis.blpop(0, redisQueueName);
String message = messages.get(1);
//do some stuff

I'm looking to see if I can speed up performance as I have a large amount of items sitting in the Redis queue waiting to be picked up. I've timed my custom processing code and it does not take too long (20000 nano seconds).

Would best practice be to pull multiple items from Redis at once and process them in a batch? Or am I better looking at tuning the Redis server for better performance?

Upvotes: 0

Views: 1482

Answers (1)

Karthikeyan Gopall
Karthikeyan Gopall

Reputation: 5679

Yes pulling in batch is indeed the best practice. You will be avoiding network round trip.

One more thing is to trim the queue if it goes beyond certain range as the queue grows rapidly and you want to have the control over the queue size (memory size). Sometimes you may not need to perform each and every entry in the queue instead you may skip few as the queue size grows big.

If you want to retain first entered elements, ie., For retaining first 100 elements alone

Ltrim queue 0 100 

To retain last 100 elements you can do

Ltrim queue -1 100

Hope this helps

Upvotes: 1

Related Questions