First of all, I'm aware that there won't be any generic answer to this and the situation will be different for every setup. I'm however wondering if there's a way to determine with confidence if the memory usage is 'acceptable'.
I'm rendering a discussion page, with about 20 replies on each page and each reply having an average of ~10 likes. The average page load time as reported by Laravel Debugbar is about 300 - 600 ms; which I believe is okay.
My main worry is that the debugbar reports 22M. I've been able to keep the Query count down to 9 and max 11 for each page load, by using eager loading relationships.
Would you say that this memory usage is 'acceptable'? Or are there any ways to bring it down?
Hmm, I don't think 22 Megabytes is a lot of memory for your application. It is probably not worth any modification if the server is performing well. If I recall correctly, Laravel does not use a persistent DB connection so unless you made a persistent DB connection and failed to close each time you use it, you should be fine.
For me, I mainly look at the expected amount of DB queries before either expanding the server memory or for heavier usage...move to using a load balancer with multiple server instances.
No, the connection isn't persistent. I'm planning to host this on AWS, with DB server different from the application server.
My main concern is that even with paginated results (20 replies at max), the memory usage is north of 20-22 MB. Does that mean, 20 users accessing the site would end up consuming 400+ MB?
@ejdelmonico - number of queries on any page is ~10-12; which I believe is within acceptable limit for a basic forum with 'thread', 'replies', 'channels', 'likes' and 'users. This is my first ever web app so I'm bit skeptic.
Are there any general steps to reduce the memory footprint of the application? Or is it something that's beyond our control?
Keep in mind, running debugbar will consume a lot more resources than without. The more complex your page and everything it takes to generate it is (queries, etc), the more resources debugbar will consume to gather the data. On some of my complex pages, debugbar takes 2 seconds by itself. Without it, it's closer to 800ms.
You can disable it and do some timing and memory logging to compare and see.
Thanks @Cronix . What'd be the right way to get memory usage without the debugbar? Should I be using memory_get_usage()? If yes, where exactly should I put it - in the controller or in the model?
@ejdelmonico - I enabled show memory usage in 'Appearance' of phpStorm. It now shows x of y M memory usage in the bottom-right corner. Is that the setting you are talking about?
I've xdebug 2.6; does it require any other setting to show memory usage?
If you want an even better way then consider Blackfire. They have a hack plan which is free and Laravel works great with it. You can gather a lot of information about your app using that tool. There is plenty of information online about it.
Its 3 years old post but, when I use windows and start with php artisan serve, debugbar says app consumes 20+ MB but same app on the macOS served with valet debugbar says 5-6 MB
I have the exact same issue on my windows machine and Laragon. PHP 7.4, MySQL 5.7, Laravel 8.
Debugger shows 18MB, even with no query or models. and goes up in memory when query is involved and shows 20 or 22mb. Seems like debuggers one start from 18 lol
It has something with windows or server installed on windows. I have wamp on windows and debugbar shows 20mb. But on homestead it shows 5-6mb and on another linux machine it shows 5-6mb. I think it is normal for windows.