Lachim / redis

Automatically exported from code.google.com/p/redis
2 stars 0 forks source link

INCRBY does not increment correct count if used in multiple threads #563

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What version of Redis you are using, in what kind of Operating System?
Redis version - 2.2.7
OPerating system - Open Suse

What is the problem you are experiencing?
I am using jedis client API and using jedis pool to create a key-value and 
increment value with a count of 100 in 50 threads for 1000 requests.
I am calling INCRBY command from 50 threads. I have 1000 requests which get 
executed in 50 threads and each request calls INCRBY to increment value by 100.

The total count I can see in redis memory for my key is 99000 or 98500 instead 
of 100000. The problem is reproducible.

What steps will reproduce the problem?
Run INCRBY command from multiple threads to increment a value by 100.
Also you can try the same by running the program from 2 different machines 
simultaneously.

Do you have an INFO output? Please past it here.
Output seen via redis client
redis> get 3333_2752011_TotalPublished
"97500"

If it is a crash, can you please paste the stack trace that you can find in
the log file or on standard output? This is really useful for us!
-

Please provide any additional information below.

Original issue reported on code.google.com by sonal...@gmail.com on 27 May 2011 at 12:00

GoogleCodeExporter commented 8 years ago
Hello, it is very unlikely that there is such a problem in Redis. Probably it 
is something related to the client library or the application level code 
itself. Please use 'redis-cli monitor' to check the number of increments 
actually received by the server. Taking this open for now, even if the 
probability of this being Redis related is very small.

Original comment by anti...@gmail.com on 27 May 2011 at 1:20

GoogleCodeExporter commented 8 years ago
Thanks for the reply. I will monitor as per your suggestion and report you back 
in case I see the issue again. I have seen the problem a couple of times but as 
it does not come always, I will keep you updated whenever I see it again. 
Thanks.

Original comment by sonal...@gmail.com on 31 May 2011 at 6:00

GoogleCodeExporter commented 8 years ago
I am able to reproduce the problem.

I have used LPUSH command using jedis client to push 1000 items on redis server 
with payload size of 1599 bytes each. Each item contains a count as 10.

I have another java program which is running from 2 machines with 50 threads in 
it to pop those 1000 items and increment value of a key 
"1111_3152011_TotalPublished" using INCRBY command of jedis client by 10 for 
each poped item.

Ideally the program should pop 1000 items from list and 
"1111_3152011_TotalPublished" should have 10000 but actually it showed 9820.

I ran redis-cli monitor to check how many items were pushed and a value of 
"1111_3152011_TotalPublished" key. I can see 1000 items pushed by LPUSH but the 
count of INCRBY for "1111_3152011_TotalPublished" is only 982.

I have attached the monitor log to this comment.

Results from redis monitor:
cat reddismon31may7.txt | grep LPUSH | grep netcoreq1 | wc
   1000    4294 3590227

cat reddismon31may7.txt | grep INCRBY | grep TotalPublished | wc
    982    3928   60884

From redis-cli command line 
redis> get 1111_3152011_TotalPublished
"9820"

Any ideas where it is getting wrong?

Original comment by sonal...@gmail.com on 31 May 2011 at 11:14

GoogleCodeExporter commented 8 years ago

Original comment by sonal...@gmail.com on 31 May 2011 at 11:19

Attachments:

GoogleCodeExporter commented 8 years ago
Since the number of INCRBY calls is consistent with the counter value (982 and 
9280) this is clearly not a Redis problem. Are you sure that you perform an 
INCRBY for *every* element you pop, and that there are no race conditions? 
Closing this issue.

Original comment by pcnoordh...@gmail.com on 31 May 2011 at 3:09