I have seen a number of posts on the forum around the topic of how to install and configure Redis or Memcache with Mautic. Alas there is not one person that has put the solution. Also the documentation in Mautic docs seems super outdated and not explanatory at all: Mautic Developer Documentation
Some background of what I have done, yet I am unclear if it is working as I think my syntax is incorrect in local.php file (but it is not breaking it) - all done with the help of Google & chatGPT.
I am running on ubuntu 20.04 and did the following:
Installed memcach and php module:
sudo apt-get install memcached
sudo apt-get install php-memcached
restarted php7.4-fpm service
added the following to my local.php
Sadly this section has not yet been updated and brought over to the new developer docs so I can’t help here!
If someone does have a working config, we are happy to help with documenting - the repo is here:
Here is the issue for the cache bundle:
Also worth noting this PR in the new end-user docs:
We have the entire configuration section documented now (see here) so that PR will also add the things which you can document in the local config file. We could add the specifics for setting up cache providers - I don’t know if this sits best in the dev docs or the end-user docs? What do you think @mikew?
I think that @m.abumusa has been doing some work on the read/write and primary/secondary DBs, I recall seeing some PRs. Maybe he can help with the docs too
I am really hoping that someone (@ekke , @joeyk , @Yosu_Cadilla - sorry all had to tag you) can shed some light on the two main issues I am trying to face at the moment which are:
implementing redis/memcached for Mautic including API
setting up master/master master/slave environment.
@mikew I created two PRs for Master/Replica implementation, and I am using both of them in two production environments one that uses AWS RDS and the other one using Google Cloud MySQL.
As you can see from the file changes in PR #12038, I am only targeting a few areas of Mautic like reports, segments creation, and campaigns.
A better implementation may be in the future I can direct all the SELECT (except ones inside a COMMIT) statements to the read replica, all INSERT, UPDATE, DELETE, and COMMIT to the master node.
For the time being you can use these two PRs on both 5.x and 4.4 and it will work you and distribute the load in your database
There was a group of 4-6 relatively young DEVOPS guys a few years ago, pushing this and other high level initiatives, like RabbitMQ integration and other similar stuff.
Since these community people are long gone, as almost everyone else from that time, no one is supporting those integrations anymore and they have degraded over time, meaning they will work out of the box on, let’s say M2.14 and probably on 2.26.5 , but after that, it’s a coin flip.
The initial Master/Slave integration in particular, I believe was written by Heath Dutton and was added to the main stable version of Mautic at the time, hence there is no independent repo, however this is the repo he used for most Mautic related things, so maybe you can find something buried there…
If you also take into account the 2 great engineers working at Mautic first and then at Acquia are also gone, there’s no one to clarify those long forgotten issues anymore.
Glad to see that m.abumusa is picking the baton for M4 and M5, but if you are on M3, you might need to do a bit of scavenging…
Personally, Master-Slave is of no use to me, reads and caches are plenty fast already, what I usually need is faster writes, for that I prefer to use master-master also called multi-master replication, commercial name: MariaDB Galera Cluster.
Additional advantages of this type of setup:
Every database in the cluster behaves just as a regular DB and no extra configuration is required for Mautic, the data replication is entirely managed by the DB layer over the local network. However, it is not as simple as master-slave to set it up on the MySQL level, but it’s also not rocket science.
If you are using Multi-master, you can switch to one Mautic to another instantly, hence enabling full read-write High Availability to any number of nodes.
You can define all nodes individually as read only, write only or write/read, and you can change that while the DB is running, whithout changing anything in Mautic.
Do you happen to know if there’s any documentation on how/if Mautic can handle in-memory (instead of in-disk) Symfony cache, which is available since Symfony 3 and as you shared, configurable on the local.php file?
Other related topics I am looking for info about (all related to the piece of code you shared) Is there any information somewhere about how to properly configure memcached or how to check if it is working?
Also for Redis and/or RabbitMQ: Do you know about any info about the configuration of these parameters that are on the local.php file?
It would be great if we could put together what parameters are usable or legacy or just history and do not do anything at all in current Mautic versions.
If they are usable, how to configure them and how to check proper configuration is in place.
And things like queues, can be used on ingress and egress, for example for page visit tracking and email queuing, some info about the supported use cases would be great too, don’t you agree?
Oh! Since we are discussing documentation, The API docs were quite good a few years ago, but have had little to no love since. It also never had much useful documentation for non-Symfony programmers.
Currently, besides the very basic information available in the docs, the only place to be able to understand how the Mautic API really works is by looking at the code, which is not just PHP, but also Symfony based, making it anything from hard to impossible for programmers of the other 999 programming languages and frameworks out there to use the API.
Additionally, the comments on the code are not very explicit, so sometimes it is hard, even looking at the code, to understand which parameters are mandatory.
API requirements are not documented and also not enforced in the code and error codes aren’t always returned, so if you want to do anything out of the basic few things, you need to test the limits and requirements “by hand”, not complaining, but also does not help Mautic’s image as a enterprise-ready solution…
Since an API’s reason to exist is to be able to communicate with other systems, regardless of language, stack, etc… it would make a lot of sense to have an API documentation that does a bit more than pointing to some PHP implementation of the API.
2023/03/07 07:12:10 [error] 3856#3856: *8874 FastCGI sent in stderr: "PHP message: PHP Notice - Undefined variable: inline - in file /var/www/mautic/offline.php - at line 77PHP message: PHP Notice: Undefined variable: inline in /var/www/mautic/offline.php on line 77PHP message: ParseError: syntax error, unexpected '=>' (T_DOUBLE_ARROW) - in file /var/www/ams/app/config/local.php - at line 769" while reading response header from upstream, client: 46.116.227.13, server: ams1.surge-ams.com, request: "GET /s/dashboard HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.4-fpm.sock:", host: "mtest.surge-ams.com", referrer: "https://mtest.surge-ams.com/s/login"
I have played around a lot with positioning the code and changing parenthesis with the square brackets however am unable to get it to not break Mautic.
I have checked and bot memcached and the php extension are installed and I am also able to telnet into memcached port and run stats items there to see if there is any data - unfortunately not, but the service is running.
I followed the first PR that you posted and updated the following files:
app/bundles/CoreBundle/Config/config.php
Created file: app/bundles/CoreBundle/Doctrine/Connection/PrimaryReadReplicaConnectionWrapper.php and crowned it to www-data:www-data
app/config/config.php
I then went and added the new parameter ‘db_host_ro’ => ‘10.10.0.3’, to my local.php file. I have confirmed that my slave is working and accessible
I restarted php7.4-fpm service.
Cleared cache manually rm -rf var/cache/*
When I tried to get to my Mautic instance, I get a broken site and in the error log I am seeing the following error:
2023/03/07 08:27:41 [error] 3856#3856: *9000 FastCGI sent in stderr: "PHP message: PHP Notice - Undefined variable: inline - in file /var/www/mautic/offline.php - at line 77PHP message: PHP Notice: Undefined variable: inline in /var/www/mauitc/offline.php on line 77PHP message: Symfony\Component\DependencyInjection\Exception\LogicException: Messenger support cannot be enabled as the Messenger component is not installed. Try running "composer require symfony/messenger".
I am not using composer and running Mautic 4.4.4 so I went and installed this manually with this command:
sudo apt-get install php-symfony-messenger
Unfortunately I am still getting the same error message.
If I change back the config.php file back to the original my instance comes up again…
I have done some research, in order to test if memcached you can telnet 127.0.0.1 11211, once inside the terminal write: stats items and then you are meant to see keys and some other info there, for me I am not seeing anything.
I think these two aspects are rather crucial for getting Mautic enterprise ready.
Some other things that might be of interest that I have done is setup an environment where I have created a nfs server and multiple Mautic workers sitting behind a load balancer for traffic, another instance outside of the load balancer but still pulling from the nfs server to run cron jobs, I was even thinking of splitting this up even further to have one server just taking care of campaign jobs and the other for segment update and sending. I am seeing on big installations even when there is ample resources campaigns triggers are being killed in the middle. I also setup an Redis server to share the php resources as well.
Currently giving better improvement but I believe if I was able to set up master-master or master-slave as well as memcache it could help as well.
Some other performance issues I have seen is API rate limit which I would be interested in hearing some thoughts around. I read an article where certain applications (not mautic), would have a separate server for api requestes on a different domain like api.mautic.com…
Interested in hearing what everyone thinks of the above. Maybe together we can come up with a nice cook book on best practices and howtos for big traffic sites.
I don’t have any experience with the QueueBundle. But there are discussions in Slack that the QueueBundle should be removed and replaced with Messenger: Sync & Queued Message Handling (Symfony 5.4 Docs) which is already part of Mautic 5 dependencies. I haven’t seen any work started on that though.
Harddrive is slower than ram. We place the whole mautic cache dir in a ram disk.
But for mautic you don’t need to change any source code or configuration.