Memcached not deleting expired items - memcached

I'm using the Memcached engine on the AWS Elasticache service, and I'm seeing some strange behavior.
The script below (I got it from Stack) lists all the keys with the size occupied + the time left to expire.
import traceback
import json
import sys
from pymemcache.client.base import Client
from six import ensure_str
if __name__ == "__main__":
try:
mc = Client('myElasticacheCluster:11211')
keys = {}
for key, val in mc.stats('items').items():
_, slab, field = ensure_str(key).split(':')
if field != 'number' or val == 0:
continue
item_request = mc.stats('cachedump', slab, str(val + 10))
for record, details in item_request.items():
keys[ensure_str(record)] = ensure_str(details)
print('\n'.join(f'{k}: {v}' for k, v in keys.items()))
except:
print(traceback.print_exc())
My problem is that apparently memcached is not purging expired items. Can anyone give me a light?
6623203617684c467b8-0c21-6a0-15c-158431be85f: [19090 b; 1662418410 s]
1662316736412d6e0fd4-73f6-4826-c723-47e6ce0db3: [19200 b; 1662415680 s]
16623107221132235451-e63-863-64f0-cee2b3ec757: [18971 b; 0 s]
1662296187289d0b754f-feb1-1a10-6c0d-d5ebf46004: [20720 b; 1662395851 s]
166223392005886e2062-ce8-7bb6-b24a-14a0586f8dc8: [18575 b; 0 s]
166222067863618ad42-b275-6ca4-271-86db011e5fa2: [19738 b; 0 s]
1662216187586254b1c-871-2db4-43-d4adeb1de1: [20292 b; 0 s]
1662214438346f83c2bb-178e-1ea3-26d6-27dd80c005fc: [18855 b; 1662312584 s]
16622153690636f5f0d-778c-da1-825a-21e178a0a: [18478 b; 0 s]
1662209171636eb50c-30a-54f-e3ab-63a08ee7cf1f: [20202 b; 0 s]
1662165662792d452d55-52e2-cb8e-6d1b-8a74ab510333: [21207 b; 0 s]
166214554259527d26ff-f704-fc36-1230-155264a741: [18242 b; 1662252637 s]
1662150706400cd11305-f3af-3775-04ed-038fdea07d3: [20255 b; 0 s]
1662147721636ee17726-4e1-b4c2-d463-f2f854cd6ac4: [18020 b; 1662247949 s]
16621439053752562c6a-1b6e-ae-1c0d-54bf735b7527: [18170 b; 0 s]
1662141405877cd727aa-8c1-773f-73bf-33a8d5f064fa: [19724 b; 1662238706 s]
166213586047685e634d-dbd7-735b-6fdd-865653ab0aee: [20206 b; 0 s]
1662125482326ed56c03-ab0c-f53e-07eb-d63cf370cc: [17886 b; 1662223366 s]
16621251828812b8ccb-a6af-7573-7f7a-28051a1f5f5: [20720 b; 1662222156 s]
1662122945157e854d7-6e8f-5e45-8048-6da47b1cc73: [18872 b; 1662221332 s]
166206172717075e00e-2f5b-f26a-d4bd-116f654e00e2: [21227 b; 0 s]
16620608120886ee7717-c508-42d4-81a3-af44dafddf32: [21280 b; 1662158103 s]
16620596251423cb1807-eb03-f21a-7a18-4d48f0051ed: [18734 b; 1662157342 s]
1662043945290d527d-747c-d78d-b8a-df8400f3d0: [19432 b; 1662141253 s]
16620497242408d6f4d-3ae-08cb-637e-6e4c85e5fba: [20452 b; 0 s]
166204949632962e58aa-4321-8b08-7668-2b2b770d386e: [20324 b; 0 s]
1662038797835e878d36-66d-828-cccb-d0fccad4211: [21325 b; 0 s]
16620329907221b0aff5-27c-1d-b53-6653638d748f: [20932 b; 0 s]
16619888128963273efa-a420-d40c-6273-075d262b77ab: [17562 b; 1662087379 s]
1661985522694c24f55-d73d-201c-66d7-facc385858c: [19098 b; 0 s]
16619836702192588575-8c4e-d533-5d81-e0ebb2fd3b: [18967 b; 1662081953 s]
1661975444359a75b38-71cf-b134-0672-120f204843d: [17866 b; 1662073872 s]
1661969634948e105d7-1a37-ba55-ed1e-424cafaeb0af: [18298 b; 1662066691 s]
1661964997054b018d45-fb56-2aa0-6425-506f6287c0: [18110 b; 0 s]
1661955619723ff2236-d01-6ea1-176c-8b5a623f151: [18958 b; 1662052527 s]
1661955525460153363-8c8-85dc-653-381a755ca03: [19796 b; 1662052612 s]
16618642764125cbff28-5574-4715-2485-6ef8615b4ca: [18436 b; 1662049137 s]
1661951831769c7d7484-53ff-762e-f082-8712786e8308: [17454 b; 0 s]
1661951133280dd2b87-a0cc-607-28b5-b5632e17ba00: [19926 b; 1662048325 s]
16619459178130d82323-ee42-5dde-386d-af18ec1ba8d: [18676 b; 0 s]
166190038012746eb217-8d5c-434e-c5ac-f4f74206ef51: [19212 b; 0 s]
166188747136572bd81-564a-2a8c-853a-6d1a247667b: [18097 b; 1661996458 s]
1661865840717daf8b8c-b8b7-ffec-c84a-86ec0eccb548: [17838 b; 0 s]
166187436814662e700-b1e4-4af6-8733-0e3c842e7c: [17386 b; 1661971519 s]
16618630620301377f1-173c-6487-5bf0-f1c2d1e35fbf: [19006 b; 0 s]
1661859693931ec263a-d4ca-0a08-ed2f-ca748dfca5d: [19911 b; 0 s]
16618199445844766005-470d-d145-ca73-060ebb74d656: [17646 b; 1661917593 s]
1661806035730512d31e-02e6-cf1-61f-6a32e488deb: [19292 b; 1661910731 s]
166181044983104d67e5-1428-755-b51-848a274376e: [18557 b; 1661908095 s]
1661804778094bf81feb-e471-da71-4a85-afaa15102c3a: [21308 b; 0 s]
16617989653936cd8d5b-577-d06-0eb6-530a36484f: [18450 b; 1661897901 s]
16617958157330023083-323d-b05-4fa-ceafcf8877a: [19503 b; 0 s]
16617967368695f11f3e-5374-eb36-81a8-7b4863a70e: [18145 b; 0 s]
166179439499317eada8-4135-aebb-240d-4c674fa4437: [17416 b; 0 s]
16617805893722258a-cefa-5ad-613-8d5c13cb2382: [18611 b; 0 s]
1661783924710ec0e0-a8d-bcc-e63b-ee6b511346fe: [18678 b; 0 s]
16617778789012b8f60-edad-2862-56b-13432f3f3006: [20568 b; 0 s]
166177660562687b1c1f-e6cd-6c1-b85f-88f0a1cdf8cc: [19504 b; 0 s]
1661694912637a27123-8ec0-06cf-c455-482b4827785: [17625 b; 0 s]
166164604103572f5f1e-2be-e3f-cbe-0b8ed860f6c: [18063 b; 0 s]
16616412917806c8c13-735d-6a-0fe3-0e6b5a6e757: [20211 b; 0 s]
1661607867132648c14-c81f-0d08-3bfc-b5f5085b22bf: [20815 b; 0 s]
16615334299968e2745d-28fa-02f4-d67c-e60aed303253: [20012 b; 1661636138 s]
1661521234900b022b5-8f30-5388-1e36-85a0ce82bf: [19969 b; 0 s]
166147240241488be808-d1be-6257-5fed-3ec0f86b50: [19364 b; 0 s]
1661462010741de8a53-8e3b-dda7-24a-ea265a047d75: [20021 b; 0 s]
166145798753622460c-cbfb-0cbb-7d20-2418bf4aa2: [17902 b; 1661555511 s]
1661451247573014735-053-d566-2b48-da0283c38b1f: [18096 b; 0 s]
1661438963023cc73032-b5c4-d4b2-7ab-b5f84e387c62: [21533 b; 1661538768 s]
1661385400263ab2653f-f26f-b56b-2184-187bc2afa4c6: [20783 b; 1661484856 s]
1661379543635b33a18-e83b-add8-df7-0ea2f543dfc1: [20711 b; 1661478300 s]
16613724005636faaff-0b3-dd73-b1ba-cff7ba5d38: [17463 b; 1661470333 s]
166136308150376e6aa-d1f3-52cb-017-6ec20f0c565e: [18015 b; 0 s]
1661357415182be572e6-6664-cd17-7b06-38ebcc1b5bec: [17322 b; 0 s]
166135527044704fc21-c826-a00f-0306-a7673b5ffd1: [20496 b; 1661455675 s]
16613533298094cebf5-67d-6daf-fedb-b0d7b885181: [19959 b; 1661450333 s]
16613451194501bf4cf-3b01-0-022-bbc65dde06: [21422 b; 0 s]
16613397789827c6fa45-424-6ca-d56c-d77a15160c7: [20690 b; 0 s]
166128027166837aeb7a-bb-0a22-1bdc-f1127b1bae77: [20683 b; 0 s]
16612807430558d31cc3-7b50-b402-770e-4db863adf8: [19836 b; 1661378749 s]
16612803353585f22db-4a0-ad82-f175-1d5e60dd1c42: [18528 b; 0 s]
166126819864648bde54-f5cf-5afa-ee7-d05e1e7827e: [19326 b; 0 s]
16612737532110c0141b-aec7-6cb1-53f-eb374da8bee0: [21540 b; 1661371536 s]
1661264884579317875-58d1-c168-c7e7-af37aded58f0: [17271 b; 0 s]
1661260177933c8f50e5-312f-3486-2e64-53bde82622e: [19718 b; 1661361237 s]
1661262852343cebba4e-b700-8a15-a783-627f5687547: [17588 b; 1661359960 s]
1661251640669cd5fe6d-b33-a2b3-140d-73223feec468: [20442 b; 0 s]
1661214893232af20adc-8a04-bc2f-d6a5-1f2b453cae5f: [17674 b; 0 s]
166117886844633bbe2-d4c8-322-0c58-dddeade746: [18266 b; 0 s]
166120045719270d004f-6a08-52ed-b144-cbbe7babdf1: [21429 b; 0 s]
1661170563985bad4011-e60f-c6f5-0e8c-7a5acc7c7650: [18332 b; 0 s]
1660949979481832a2f-4f45-7eda-0b1-f672b27b13: [19360 b; 0 s]
1661098312265f70a66-3f2f-4fc8-6d04-c76cbdc34e0: [17602 b; 0 s]
1661096392553515f8ea-f3bf-f20d-0b78-43233b6e5ef2: [19698 b; 1661193366 s]

memcached uses a lazy expiry mechanism where the explicit expiry time that has been set is compared with the current time when the object is requested. Only objects that have not expired are returned.
Reference: https://docs.oracle.com/cd/E17952_01/mysql-5.6-en/ha-memcached-using-expiry.html

Related

Why are there problems using map in an IF statement?

Why won't the following run?
if (map [ [a b c] -> a + b = c ] [1] [2] [3]) [show 100]
The following produces 'true' as an output:
show (map [ [a b c] -> a + b = c ] [1] [2] [3])
so I expected the first statement above to be the same as:
if true [show 100]
(P.S. in my full version the lists are longer but are collapsed into a single true/false using reduce.)
Thanks.
To elaborate on ThomasC's comment, map always produces a list, even if it only has one element. So
(map [ [a b c] -> a + b = c ] [1] [2] [3])
does produce [true]. Thus
(map [ [a b c] -> a + b = c ] [1 2] [2 3] [3 5])
will produce [true true]. reduce is helpful here,
reduce AND (map [ [a b c] -> a + b = c ] [1 2] [2 3] [3 5])
will produce a simple true by "anding" all the elements of the map output, and
reduce AND (map [ [a b c] -> a + b = c ] [1 2] [2 3] [3 6])
will produce a simple false.

Feasible solutions to inequations

I have a Math problem where I have some true statements, and I want to know if there is a feasible solution to an equation. I would like to know how to do that in either Matlab or Mathematica.
The true statements are:
0 < a, b, c, d, e
a, b, c integers
a < b < c
d*b + e*b > e * c
I want to know that, if given those conditions, it is possible to find values for a, b, c, d, e, such that the following inequality holds:
d*a > d*b +e*b - e*c
I think the Reduce function in Mathematica is the appropriate tool for this.
Reduce[d*a > d*b + e*b + e*c && a > 0 && b > 0 && c > 0 && d > 0 && e > 0 && d*b + e*b > e*c && a < b < c, {a, b, c, d, e}, Integers]
this yields False meaning it cannot be satisfied as formulated. However, relaxing the a < b < c constraint does yield a (set of) solution.

Is this a bug in MuPAD?

I have u0 as step function (piecewise definition):
piecewise([0 < t, 1], [t < 0, 0])
Now I compute:
int(u0(t)|t=k, k=-infinity..t)
which gives
piecewise([0 < t, t], [t <= 0, 0])
In a textbook I found the answer:
piecewise([0 =< t, t], [t < 0, 0])
Is this a bug in MuPAD?
I does not matter if you use f(t)=t or f(t)=0 for t=0. In both cases the result is 0

Mapping a range to another range

I have range from 0 to a which I have to proportionally map to a range from b to c. How to achieve this in NetLogo.
0 to a -> b to c
[0 a] -> [b c]
assuming your input is x, then:
b + (x / a) * (c - b)

How to Vectorize Dependent For-Loops

I'm working on a function that takes a 1xn vector x as input and returns a nxn matrix L.
I'd like to speed things up by vectorizing the loops, but there's a catch that puzzles me: loop index b depends on loop index a. Any help would be appreciated.
x = x(:);
n = length(x);
L = zeros(n, n);
for a = 1 : n,
for b = 1 : a-1,
c = b+1 : a-1;
if all(x(c)' < x(b) + (x(a) - x(b)) * ((b - c)/(b-a))),
L(a,b) = 1;
end
end
end
From a quick test, it looks like you are doing something with the lower triangle only. You might be able to vectorize using ugly tricks like ind2sub and arrayfun similar to this
tril_lin_idx = find(tril(ones(n), -1));
[A, B] = ind2sub([n,n], tril_lin_idx);
C = arrayfun(#(a,b) b+1 : a-1, A, B, 'uniformoutput', false); %cell array
f = #(a,b,c) all(x(c{:})' < x(b) + (x(a) - x(b)) * ((b - c{:})/(b-a)));
L = zeros(n, n);
L(tril_lin_idx) = arrayfun(f, A, B, C);
I cannot test it, since I do not have x and I don't know the expected result. I normally like vectorized solutions, but this is maybe pushing it a bit too much :). I would stick to your explicit for-loop, which might be much clearer and which Matlab's JIT should be able to speed up easily. You could replace the if with L(a,b) = all(...).
Edit1
Updated version, to prevent wasting ~ n^3 space on C:
tril_lin_idx = find(tril(ones(n), -1));
[A, B] = ind2sub([n,n], tril_lin_idx);
c = #(a,b) b+1 : a-1;
f = #(a,b) all(x(c(a, b))' < x(b) + (x(a) - x(b)) * ((b - c(a, b))/(b-a)));
L = zeros(n, n);
L(tril_lin_idx) = arrayfun(f, A, B);
Edit2
Slight variant, which does not use ind2sub and which should be more easy to modify in case b would depend in a more complex way on a. I inlined c for speed, it seems that especially calling the function handles is expensive.
[A,B] = ndgrid(1:n);
v = B<A; % which elements to evaluate
f = #(a,b) all(x(b+1:a-1)' < x(b) + (x(a) - x(b)) * ((b - (b+1:a-1))/(b-a)));
L = false(n);
L(v) = arrayfun(f, A(v), B(v));
If I understand your problem correctly, L(a, b) == 1 if for any c with a < c < b, (c, x(c)) is “below” the line connecting (a, x(a)) and (b, x(b)), right?
It is not a vectorization, but I found the other approach. Rather than comparing all c with a < c < b for each new b, I saved the maximum slope from a to c in (a, b), and used it for (a, b + 1). (I tried with only one direction, but I think that using both directions is also possible.)
x = x(:);
n = length(x);
L = zeros(n);
for a = 1:(n - 1)
L(a, a + 1) = 1;
maxSlope = x(a + 1) - x(a);
for b = (a + 2):n
currSlope = (x(b) - x(a)) / (b - a);
if currSlope > maxSlope
maxSlope = currSlope;
L(a, b) = 1;
end
end
end
I don't know your data, but with some random data, the result is the same with original code (with transpose).
An esoteric answer: You could do the calculations for every a,b,c from 1:n, exclude the don't cares, and then do the all along the c dimension.
[a, b, c] = ndgrid(1:n, 1:n, 1:n);
La = x(c)' < x(b) + (x(a) - x(b)) .* ((b - c)./(b-a));
La(b >= a | c <= b | c >= a) = true;
L = all(La, 3);
Though the jit would probably do just fine with the for loops since they do very little.
Edit: still uses all of the memory, but with less maths
[A, B, C] = ndgrid(1:n, 1:n, 1:n);
valid = B < A & C > B & C < A;
a = A(valid); b = B(valid); c = C(valid);
La = true(size(A));
La(valid) = x(c)' < x(b) + (x(a) - x(b)) .* ((b - c)./(b-a));
L = all(La, 3);
Edit2: alternate last line to add the clause that c of no elements is true
L = all(La,3) | ~any(valid,3);