Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

redis performance problem #791

Closed
wociscz opened this Issue Aug 2, 2016 · 1 comment

Comments

Projects
None yet
2 participants

wociscz commented Aug 2, 2016

Hi, i just recognised the performance problem. After a few weeks my redis db is ~400MB on disk.
rspamd process sending periodically these commands to redis (allmost every second)
KEYS BAYES_SPAM* (which gets allways 1 key BAYES_SPAM)
KEYS BAYES_HAM* (which gets allways 1 key BAYES_HAM)
and HGET, HLEN variants.

It seems to be for statistics of how many learns we have or something like that.

In my situation these commands lasts ~10sec to get them done. And performance of redis is going to the hell. I have hundreds of connect timeouts to redis and rspamd is allmost useles in this situation.

In the redis doc, there is:

IMPORTANT NOTE: a VERY common source of latency generated by the execution of slow commands is the use of the KEYS command in production environments. KEYS, as documented in the Redis documentation, should only be used for debugging purposes. Since Redis 2.8 a new commands were introduced in order to iterate the key space and other large collections incrementally, please check the SCAN, SSCAN, HSCAN and ZSCAN commands for more information.

Is it possible to turn off these blocking commands, or are they important for some internals?

When i clean redis db, it works fast, so with bigger redis db these commands is slower and slower to the point where everything stops...

actual rspamc stat

Results for command: stat (0.015 seconds)
Messages scanned: 15979385
Messages with action reject: 10946421, 68.50%
Messages with action soft reject: 60936, 0.38%
Messages with action rewrite subject: 958341, 5.99%
Messages with action add header: 1322576, 8.27%
Messages with action greylist: 691139, 4.32%
Messages with action no action: 1999972, 12.51%
Messages treated as spam: 13288274, 83.15%
Messages treated as ham: 2691111, 16.84%
Messages learned: 10851525
Connections count: 13476
Control connections count: 4
Pools allocated: 13501
Pools freed: 13348
Bytes allocated: 3.96M
Memory chunks allocated: 489
Shared chunks allocated: 10
Chunks freed: 0
Oversized chunks: 3
Fuzzy hashes in storage "rspamd.com": 420130
Fuzzy hashes stored: 420130
Statfile: BAYES_SPAM type: redis; length: 67.11M; free blocks: 0; total blocks: 1.76M; free: 0.00%; learned: 80594; users: 1; languages: 0
Statfile: BAYES_HAM type: redis; length: 151.28M; free blocks: 0; total blocks: 3.98M; free: 0.00%; learned: 16460; users: 1; languages: 0
Total learns: 0

redis infos:

Keyspace

db0:keys=2607839,expires=2586332,avg_ttl=61159389

Memory

used_memory:910873168
used_memory_human:868.68M
used_memory_rss:1006358528
used_memory_rss_human:959.74M
used_memory_peak:979017744
used_memory_peak_human:933.66M
total_system_memory:25327726592
total_system_memory_human:23.59G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.10
mem_allocator:jemalloc-4.0.3

Server

redis_version:3.2.2

rspamd version
1.3.0-0git1738c58447~jessie
(but same behaviour on the newest 1.3.2*)

Regards,
Jan

@vstakhov vstakhov added a commit that referenced this issue Aug 2, 2016

@vstakhov vstakhov [Fix] Do not stress redis with KEYS command (#791)
Issue: #791
Reported by: @wociscz
d24212c
Owner

vstakhov commented Aug 2, 2016

That should be fixed now, thank you for the report.

@vstakhov vstakhov added a commit that referenced this issue Aug 8, 2016

@vstakhov vstakhov Release 1.3.2
* [Feature] Add a special symbol for SPF DNS errors: R_SPF_DNSFAIL
* [Feature] Add correlations report in fuzzy stats
* [Feature] Add experimental CGP integration
* [Feature] Add method to get urls length in a text part
* [Feature] Add new methods to lua_html to access HTML tags
* [Feature] Allow all types of symbols to be added via __newindex method
* [Feature] Allow to create settings for authenticated users
* [Feature] Allow to get block content for HTML tags
* [Feature] Improve DNS failures when dealing with SPF
* [Feature] Properly implement R_WHITE_ON_WHITE rule
* [Feature] Remove old ugly rules
* [Feature] Rspamc can now add dkim signature in mime mode
* [Feature] Store content length for HTML tags
* [Feature] Support reacher set of HTML colors
* [Feature] Try to avoid FP for low contrast fonts detection
* [Fix] Add missing HTML colors
* [Fix] Add spaces to dkim signature to allow folding
* [Fix] Avoid returning NaN as score on scan
* [Fix] Decode entitles in href parts
* [Fix] Do not cache SPF records with DNS errors
* [Fix] Do not crash on cyclic depends
* [Fix] Do not insert HELO/HOSTNAME unknown when they are not passed
* [Fix] Do not set absent hostname to "unknown"
* [Fix] Do not stress redis with KEYS command (#791)
* [Fix] Fix DMARC_BAD_POLICY symbol
* [Fix] Fix HFILTER_URL module
* [Fix] Fix HFILTER_URL_ONELINE rule
* [Fix] Fix buffering in CGP integration
* [Fix] Fix colors propagation from parent nodes
* [Fix] Fix confusing OpenSSL API usage of i2d_RSAPublicKey
* [Fix] Fix dependencies id sanity check
* [Fix] Fix folding for semicolon separated tokens
* [Fix] Fix largest possible TLD behaviour
* [Fix] Fix last token folding
* [Fix] Fix length calculations in white on white rule
* [Fix] Fix multiple request headers structure
* [Fix] Fix multiple values headers freeing
* [Fix] Fix parsing of background color
* [Fix] Fix printing from field in log_urls
* [Fix] Fix processing of last element of DMARC policies
* [Fix] Further fixes for HTML colors
* [Fix] Further fixes for multiple values headers
* [Fix] Further fixes for white on white rule
* [Fix] Further fixes in HTML tags parsing
* [Fix] Ignore content type/subtype case
* [Fix] Increase score of R_WHITE_ON_WHITE
* [Fix] Parse CGP envelope data
* [Fix] Propagate colors in HTML
* [Fix] Restore multiple values headers in protocol
* [Fix] Restore multiple values in headers processing
* [Fix] Some more changes to tag's content length calculations
* [Fix] Some more fixes for low contrast fonts detector
* [Fix] SpamAssassin plugin: support check_freemail_header('EnvelopeFrom', [..])
* [Fix] Trigger HTML_SHORT_LINK_IMG on any external image
* [Fix] rspamd_stats: remove deprecated defined(@array)

Signed-off-by: Vsevolod Stakhov <vsevolod@highsecure.ru>
cb85611

vstakhov closed this Aug 18, 2016

@larryhynes larryhynes added a commit to larryhynes/rspamd that referenced this issue Aug 25, 2016

@larryhynes larryhynes Merge remote-tracking branch 'upstream/master'
* upstream/master: (29 commits)
  [Fix] Add spaces to dkim signature to allow folding
  [Fix] Fix confusing OpenSSL API usage of i2d_RSAPublicKey
  [Minor] Really save privkey in file
  [Fix] Fix folding for semicolon separated tokens
  [Feature] Rspamc can now add dkim signature in mime mode
  [Fix] Do not stress redis with KEYS command (#791)
  [Minor] Integrate coveralls
  [Feature] Allow to create settings for authenticated users
  [Feature] Add experimental CGP integration
  [Fix] Ignore content type/subtype case
  [Test] Replace get_process_children with psutil function
  [WebUI] Try harder to clear password on disconnect
  [Feature] Add a special symbol for SPF DNS errors: R_SPF_DNSFAIL
  [Fix] Do not cache SPF records with DNS errors
  [Feature] Improve DNS failures when dealing with SPF
  [WebUI] Clear connect password (#783)
  [Minor] Update version to 1.3.2
  Release 1.3.1
  [Fix] Fix another locking issue with mapped files
  [WebUI] Fix saving actions from web interface (#769)
  ...
d984577
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment