redis consuming way more memory than keys occupy - redis

Redis is taking way more space in memory than the keys itself:
$ top
> ... 74,2% memory (10gb) 2:17.61 redis-server
But the keys takes no more than 500MB total, I checked using "memory usage" on all keys and summed.
There is something I noticed while running "memory stats":
1) "peak.allocated"
2) (integer) 12556833800
3) "total.allocated"
4) (integer) 12141956128
5) "startup.allocated"
6) (integer) 803216
7) "replication.backlog"
8) (integer) 0
9) "clients.slaves"
10) (integer) 0
11) "clients.normal"
12) (integer) 11537845808
13) "aof.buffer"
14) (integer) 0
15) "lua.caches"
16) (integer) 180552
17) "db.0"
18) 1) "overhead.hashtable.main"
2) (integer) 474232
3) "overhead.hashtable.expires"
4) (integer) 115256
19) "overhead.total"
20) (integer) 11539419064
21) "keys.count"
22) (integer) 8579
23) "keys.bytes-per-key"
24) (integer) 1415217
25) "dataset.bytes"
26) (integer) 602537064
27) "dataset.percentage"
28) "4.9627666473388672"
29) "peak.percentage"
30) "96.695999145507812"
31) "allocator.allocated"
32) (integer) 12143577352
33) "allocator.active"
34) (integer) 12207005696
35) "allocator.resident"
36) (integer) 12250742784
37) "allocator-fragmentation.ratio"
38) "1.005223274230957"
39) "allocator-fragmentation.bytes"
40) (integer) 63428344
41) "allocator-rss.ratio"
42) "1.0035829544067383"
43) "allocator-rss.bytes"
44) (integer) 43737088
45) "rss-overhead.ratio"
46) "0.99665284156799316"
47) "rss-overhead.bytes"
48) (integer) -41005056
49) "fragmentation"
50) "1.0055875778198242"
51) "fragmentation.bytes"
52) (integer) 67843576
There is this clients.normal that is taking all that memory space. Any ideas on how to debug?
This keeps going until it crashes.

1) "peak.allocated"
2) (integer) 12556833800
Because the peak allocated memory is about 10GB. Although you removed many keys, the memory is not return to operation system. Check this for detail.
In order to decrease the memory consumption, you can restart Redis server.

Related

How do I read Intellij coverage report?

I am doing unit tests and I recently find out about the coverage test feature in IntelliJ.
Things are pretty clear except when generating the coverage report I don't understand why in the more detailed view of the report it shows the $$anonfun$x (where x is a number) suffix.
I'll show you an example:
Class Method, % Line, %
DataContent 100% (5/ 5) 94.7% (18/ 19)
DataContent$$anonfun$1 0% (0/ 1) 0% (0/ 1)
DataContent$$anonfun$10 100% (1/ 1) 100% (1/ 1)
DataContent$$anonfun$11 100% (1/ 1) 100% (1/ 1)
DataContent$$anonfun$12 100% (2/ 2) 100% (4/ 4)
DataContent$$anonfun$12$$anonfun$13 100% (1/ 1) 100% (1/ 1)
DataContent$$anonfun$14 100% (1/ 1) 100% (1/ 1)
DataContent$$anonfun$14$$anonfun$apply$5 100% (1/ 1) 100% (1/ 1)
DataContent$$anonfun$14$$anonfun$apply$6 100% (2/ 2) 100% (4/ 4)
DataContent$$anonfun$14$$anonfun$apply$6$$anonfun$15 100% (1/ 1) 100% (1/ 1)
DataContent$$anonfun$9 100% (1/ 1) 100% (1/ 1)
DataContent$$anonfun$extractUsersIDsVal$1 100% (1/ 1) 100% (1/ 1)
DataContent$$anonfun$extractUsersNameVal$1 0% (0/ 1) 0% (0/ 1)
total 89.5% (17/ 19) 91.9% (34/ 37)
Could anyone enlight me, please?

Why isn't this GEORADIUS call on redis working?

Add x to mytest
127.0.0.1:6379> geoadd mytest -78.45 38.13 x
(integer) 1
Try to find points within 50.000km of x:
127.0.0.1:6379> georadius mytest 72.8 19.13 50000 km
(empty list or set)
Add y to mytest:
127.0.0.1:6379> geoadd mytest 72.8 19.13 y
(integer) 1
Calculate distance between x and y:
127.0.0.1:6379> geodist mytest x y km
"12979.3623"
Why is (2) an empty set if (4) finds the distance between x and y to be of only 12979 km?
This looks like a defect - I recommend that you report it by opening an issue at http://github.com/antirez/redis/issues.
Interestingly, note that:
127.0.0.1:6379> GEORADIUS mytest -78.45 38.13 50000 km
1) "x"
2) "y"
And also:
127.0.0.1:6379> GEORADIUSBYMEMBER mytest y 50000 km
1) "y"
127.0.0.1:6379> GEORADIUSBYMEMBER mytest x 50000 km
1) "x"
2) "y"

How to multiply columns and add the results?

Assume that a table has two columns named "x" and "y" filled with numbers; for example, x contains the values (1, 2, 3), and y contains (5, 8, 20).
How can I calculate the sum of the products of the columns, i.e. (1 × 5) + (2 × 8) + (3 × 20) = 81?
As Siyual notes in the comments, this should do the trick:
SELECT SUM(x * y) FROM Table
Here's a live demo on SQLize, just to confirm that this does work.

Multi-Threading/Task making minimal difference, how to speed up process

I feel like I am doing something wrong here and not sure what, because I am not noticing a big difference with respect to multi-threading.
I have a 'Convert_Data' function that does a fair amount of processing of data. I tested it using 1 Task and saw that it was able to finish in 8 Seconds. When attempting to split the work into 4 task the overall reduction was just 2 seconds. I was expecting for it to atleast cut processing in half?
t1 = Task.Factory.StartNew(Sub() Convert_Data(Filter, 0, CInt(GridView1.RowCount / 4)))
t2 = Task.Factory.StartNew(Sub() Convert_Data(Filter, CInt(GridView1.RowCount / 4) + 1, CInt(GridView1.RowCount / 2)))
t3 = Task.Factory.StartNew(Sub() Convert_Data(Filter, CInt(GridView1.RowCount / 2) + 1, CInt(GridView1.RowCount / 3)))
t4 = Task.Factory.StartNew(Sub() Convert_Data(Filter, CInt(GridView1.RowCount / 3) + 1, GridView1.RowCount))
I break up the task based on the number of rows in my gridview. So each task gets a quarter of the files to process. I am very new to tasks and not sure if I am doing something wrong. Any comments/suggestions?
I noticed task 4 takes a fair amout longer to complete as opposed to the others.
The Conver_Data sub (Filter, StarRow, End Row)
So if there are 100 files;
Task 1 will go from 0 - 25
Task 2 will go from 26 - 50
Task 3 will go from 51 - 75 &
Task 4 will go from 76 - 100
Shouldn't the code read something like...
t1 = Task.Factory.StartNew(Sub() Convert_Data(Filter, 0, CInt (GridView1.RowCount / 4)))
t2 = Task.Factory.StartNew(Sub() Convert_Data(Filter, CInt(GridView1.RowCount / 4) + 1, CInt(GridView1.RowCount / 2)))
t3 = Task.Factory.StartNew(Sub() Convert_Data(Filter, CInt(GridView1.RowCount / 2) + 1, CInt(3 * GridView1.RowCount / 4)))
t4 = Task.Factory.StartNew(Sub() Convert_Data(Filter, CInt(3 * GridView1.RowCount / 4) + 1, GridView1.RowCount))
As things stand, your first task appears to do 1/4 of the work, the second another quarter, the third 1/6th of it, and the last 2/3rds of the job.

generating a random number between 1 and 20

The code I previously used was
Randomvariable = 1 + Int((20 - 1 + 1) * Rnd())
I'm a bit concerned it wasn't right because the format I'm seeing online in guides is
random_number = Int(20 * Rnd) + 1
Was my way equivalent to this?
Have a read about the Rnd() function
The general formula is
Int ((upperbound - lowerbound + 1) * Rnd + lowerbound)
Therefore if you want to generate random numbers between 1 and 20 use
Int((20 - 1 + 1 ) * Rnd + 1)