crowdsecurity / cs-wordpress-bouncer

CrowdSec is an open-source cyber security tool. This plugin blocks detected attackers or display them a captcha to check they are not bots.
https://wordpress.org/plugins/crowdsec/
MIT License
37 stars 6 forks source link

Same redis DB for multiple WP sites #94

Closed cRUSHr2012 closed 2 years ago

cRUSHr2012 commented 2 years ago

Hi, regarding the use of Redis for caching. Do we need to use different databases (example: DSN : redis://localhost:6379/1 for site 1 and DSN : redis://localhost:6379/2 for site 2) for each site ? Or it doesn't matter because the names for the keys are generated with unique names for each site ?

LtSich commented 2 years ago

Hi, I don't use the wp plugin atm. But, redis is "mono thread", then if you have more request it can slow down and can't "scale" on all your threads. But before you "overload" your redis you have time. This mean that using multiple DB doesn't give any performance advantage, only a better "organisation" to allow you to "isolate" your sites. The other point, for the few times that I have use this plugin, is that "for me", it's probably better to use 1 redis database, and to only update that database from 1 site, and let all other site retrieve information in that base.

But if each site use is own keys then that's not a good thing for me, as each site will refer to the same LAPI... Using 1 central cache is probably more efficient that having 100 site pulling data from the LAPI...

As a final answer :

cRUSHr2012 commented 2 years ago

Yes, the idea is to use the same Redis database for all the WP sites.

If in "STREAM" mode, the Redis DB is synced at each 60 seconds from the LAPI, this means that only one site should do this and all the others should have a very big number, or 0 for the option Resync decisions each X seconds (stream mode only) ?

LtSich commented 2 years ago

Yes, 1 website who update frequently from LAPI, all other you can deactivate that. But I didn't use that plugin for a long time now, the dev will probably confirm or deny this way of using the plugin.

julienloizelet commented 2 years ago

Hi,

keys are based only on the scope/value pair. For the WP plugin, we are for the moment only using IP scope, so cache key depends only on IP and not on the website.

For now, I don't see any way to deactivate the cron (maybe there is some other cron manager plugin that could help). So, setting a very big number is maybe an acceptable workaround.

julienloizelet commented 2 years ago

Hi, I close this one. See https://github.com/crowdsecurity/cs-wordpress-bouncer/issues/96 for some details about a multiple WP site implementation with a shared Redis cache system.