gamenet / redis-memory-analyzer

Redis memory profiler to find the RAM bottlenecks throw scaning key space in real time and aggregate RAM usage statistic by patterns.
MIT License
772 stars 80 forks source link

KeyString.py, line 57, in analyze ValueError: min() arg is an empty sequence #23

Closed fenelon closed 8 years ago

fenelon commented 8 years ago
Match *: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊| 4995001/5000000 [01:27<00:00, 53299.06it/s]INFO:root:
Limit 5000000 reached

Aggregating keys by pattern and type

Apply rules
Processing keys:   0%|                                                                                                                                                      | 0/355 [00:00<?, ?it/s]Traceback (most recent call last):
  File "/usr/local/bin/rma", line 9, in <module>
    load_entry_point('rma==0.1.13', 'console_scripts', 'rma')()
  File "/usr/local/lib/python3.5/site-packages/rma-0.1.13-py3.5.egg/rma/cli/rma_cli.py", line 92, in main
  File "/usr/local/lib/python3.5/site-packages/rma-0.1.13-py3.5.egg/rma/application.py", line 118, in run
  File "/usr/local/lib/python3.5/site-packages/rma-0.1.13-py3.5.egg/rma/application.py", line 153, in do_ram
  File "/usr/local/lib/python3.5/site-packages/rma-0.1.13-py3.5.egg/rma/rule/KeyString.py", line 57, in analyze
ValueError: min() arg is an empty sequence

After trying @misterion's fix:

    total_elements = len(data)
    if total_elements == 0:
        continue

the problem looks like

Traceback (most recent call last):
  File "/usr/local/bin/rma", line 9, in <module>
    load_entry_point('rma==0.1.13', 'console_scripts', 'rma')()
  File "/usr/local/lib/python3.5/site-packages/rma-0.1.13-py3.5.egg/rma/cli/rma_cli.py", line 92, in main
  File "/usr/local/lib/python3.5/site-packages/rma-0.1.13-py3.5.egg/rma/application.py", line 118, in run
  File "/usr/local/lib/python3.5/site-packages/rma-0.1.13-py3.5.egg/rma/application.py", line 153, in do_ram
  File "/usr/local/lib/python3.5/site-packages/rma-0.1.13-py3.5.egg/rma/rule/Hash.py", line 96, in analyze
  File "/usr/local/lib/python3.5/site-packages/rma-0.1.13-py3.5.egg/rma/rule/Hash.py", line 63, in __init__
ValueError: min() arg is an empty sequence
misterion commented 8 years ago

Looks like you Redis has lots of key deletes. I think here is two or three places there i do not take this in attention. Could you try more one patch?

       if total == 0:
            self.fieldAvgCount = 0
        elif total > 1:
            self.fieldAvgCount = statistics.mean(obj.count for obj in g3)
        else:
            self.fieldAvgCount = min((obj.count for obj in g3))

File rule\Hash.py line 60?

misterion commented 8 years ago

If this patch fix the Hash rule - i add same logic for List/Set and upload new version.

fenelon commented 8 years ago

I've posted a pull request with your fix and another divided by zero issue. Works perfectly now. #24

misterion commented 8 years ago

tnx, i merge and publish tomorrow