almalino Is it possible to run 2 or more flarum servers connecting to the same single database? And all this behind a loadbalancer that decide which server will serve next request based on servers load?
matteocontrini It would be great to have some kind of guidance on how to achieve that, meaning the things that should be considered when doing so. I have a bit of experience with distributed setups/Docker/etc. but I don't know so much of Flarum internals or Laravel, so I can't really find all the information I need. These are the things I came up with: The sessions are stored in the file system by default but it's possible to move them to the database as perfectly described by luceos here; Avatars are stored in the file system by default but it should be possible to move them to something like S3, probably by changing the driver configuration. However I'm unsure on how to do that in practice, and also if it's possible to customize the avatars URL so that a CDN is used, for example; Other public assets, like compiled JavaScript/LESS, are created at runtime and theoretically if they never change it would be possible to have each instance generate them on their own (or in a CI/CD pipeline before deploying). However, if you enable/disable an extension they will go out of sync. I guess it's possible to move these files to a remote destination as well; Extensions assets are copied to the public folder when enabling an extension. Are these operations affected by the assets file system driver as well? Favicon/logo: from the source code I see that the Flysystem interface is used, so I guess that the general assets file system affects this as well? Cache of views/formatter/etc.: is there anything wrong with a situation where each instance has its own cache, or could it cause problems? I know that there's the Redis cache & queues extension that puts cache in a Redis database, but is it necessary? Also, I see in the source code that when clearing cache the files are cleared with unlink. How can that work when Redis is used? Does it just fail silently? Is there anything else I'm missing? Thank you very much!
luceos matteocontrini sessions stored to db or redis is both possible we override the flarum/flarum skeleton to instantiate a replacement InstalledSite class, we also don't have a config.php because that doesn't make sense in a scalable architecture. Instead we rely heavily on a config directory which reads env variables. except for the formatter renderer, we push everything into the CDN; we use the cache-assets extension for this, the same command is executed when cache clear happens through en- or disabling extensions. Extension assets is a great point, I hadn't even considered that 🙂 I guess I need to create a card for Blomstra. Favicon/logo can also be uploaded to the CDN if you replace the global filesystem. You can replace the cache driver by using redis or the database. This also replaces the cache for views. Formatter renderer is the only sour thing that cannot be pushed outside of the node. I wrote a fix to circumvent errors with it. And will start building a patch upstream (flarum/core) after Flarum stable hits (no time before that sorry). Missing? Try to push as much of the processing to other services: Queues? Scheduled tasks? Websocket? The assets in Flarum are compiled using frontend-hash.js, this won't work. You need to extend the RevisionCompilers for js/css to using the format frontend.js?v=hash. I will also push this upstream later. As to queues, sessions and cache. You can use redis, but also the database. Whipped this up from memory real quick.
matteocontrini luceos well that sounds even more complex than I expected 😅 I guess I'll give up again for a while, it's a pity that all these "hacks" are required to make it work, since it is straightforward to achieve with Discourse, for example...
askvortsov matteocontrini We are very aware of this and making many of these better is on the agenda. Just a matter of getting to it. I will note that some CDN stuff is listed on 1.0 milestone
luceos matteocontrini we never worked closely with highly volatile, scalable communities and directly received feedback for improvement about performance, except for this one. With Blomstra moving entirely into the direction of scalable, cloud-based hosting it is just a matter of time to gather the findings and start fixing upstream.
luceos /me marks this as following 😉 One of the toughest things to solve right now is the Flarum Formatter. It uses the s9e textformatter library in the background which generates a PHP file known as the Renderer on disk when recompiled. Right now I've solved storing a revision into the manifest (similar to css/js) and saving a version into the cache; so that other nodes can read the revision and if it differs save that cached version to its own disk. Scaled nodes that share a disk won't have this issue.
matteocontrini luceos aaaand... what happens if that file is not shared between instances? Isn't it some kind of cache that can be generated and stored independently?
DongyunLee Hello, sorry for reply this old post, I found a CSRF Tokrn invalid error when i wanna use load balancing. Any idea is helpful!