Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Memory Logging
Are there any plugins that could do memory utilization logging, essentially taking the memory measurement that is returned in debug mode, but logging it in the database for every Textpattern request?
The reason I need this is my latest hosting provider is claiming I“m periodically exceed 2.0GB of virtual memory!
This is baffling as it doesn’t align with what I see for typical per-request memory utilization (<10 MB), typical per request response time (<15ms) and typical. Hosting seems to indicate a maximum of 3 entry processes (which I presume corresponds to httpd request processes).
So, I thought it would be helpful to monitor memory against request URLs to see if I can find any anomalous pages.
Or, if not, does anyone know if there is a way to add per request memory to Apache logs? (not sure if hosting provider will do that)
Thanks!
Offline
Re: Memory Logging
Anyone with LAMP hosting experience know if there is any way to log per-request memory usage so I can track down how it is possible my website is consuming up to 2GB of virtual memory !?
Offline
Re: Memory Logging
mericson wrote:
This is baffling as it doesn’t align with what I see for typical per-request memory utilization (<10 MB), typical per request response time (<15ms) and typical.
Depends what they include in the memory usage, and how the environment is set up, virtualized, containers, shared etc.
But, one page doesn’t equal single request, right? Single page will generate tens of requests, if not hundreds. Unless you are serving plain-text files over single connection, which presumably you aren’t. How much resources Apache will use to serve the page, will depend on its configuration and set limits.
Your server stack will eat as much memory you let it to eat. In fact, it will eat all (as in all, and then even more) available memory it can within the set limits to improve performance. Want it to use less memory? Restrict the platform. Hosting provider complaining about memory usage is like complaining about your coworkers coming your open-invitation party you scheduled on Facebook. It will bloody use as much memory you let it to use, argh. For instance my idling development image is using 100 MB for Apache and 50 MB MySQL. There is no traffic, just single website. So Textpattern eats 150 MB? No. Caching, reserving, because I let it. Heck, I could be using my leftover 800 MB alone to MySQL.
Now, if you are on a hosting platform that charges from resource usage, that is how they operate. They will loosen restrictions, letting you to use more than enough resources, opposed to throttling your traffic, which is what standard shared hosting providers do. They make profit, when you use more resources.
Or, if not, does anyone know if there is a way to add per request memory to Apache logs? (not sure if hosting provider will do that)
Partially yes, not that it will tell the big picture. Its like outputting what your script alone eats for a single request. If you are running PHP as an Apache module, you can include memory allocated to PHP in the logs with a variable:
%{mod_php_memory_usage}
Other than, you are better off checking the actual process memory usage. Within PHP runtime, you can’t get anything more than allocated memory usage as seen by PHP at the time. You can of course log those values, but it has no other usefulness than seeing how much memory the PHP code itself uses to run. At the end of your page template you could put something stupid like:
<txp:php>
safe_insert('abc_memory_log', 'date = now(), memory_usage = '.memory_get_peak_usage(true));
</txp:php>
You would create a ‘abc_memory_log’ table to your database with a ‘memory_usage’ column. E.g.
CREATE TABLE abc_memory_log (
`id` INT(11) NOT NULL auto_increment,
`date` DATETIME NOT NULL default '0000-00-00 00:00:00',
`memory` INT(12) NOT NULL default 0,
PRIMARY KEY(`id`)
) AUTO_INCREMENT=1 CHARSET=utf8
Running actual stats on the server will pretty much require access to the server. And that you have the tools to do so. First you will have to SSH to box:
$ ssh user@example.tld
Requires that the server and you both have ssh. After which you can try some stat tools, if there are any installed on the box. ps
, if there, can help you to get the list of processes and their IDs, or if on GNU, you probably also have pgrep
:
$ ps
$ pgrep
pgrep
is basically the same as ps
, but uses regular expression based searching. Allows you to filter the process list by the process name. If its not there you can use grep in combination of ps:
ps -A | grep httpd
Or any other process list thing, if you have one. Then for actual logging you have tools such as top
, which can report memory usage:
$ top -h
Last edited by Gocom (2013-08-02 12:04:53)
Offline
Re: Memory Logging
They claim it is PHP that is exceeding the “virtual memory” limits of the server, in this case 2GB. So, other resources on the page (graphics) are probably not contributing to exceeding memory limits.
They also say that PHP is requesting a block that will exceed that amount, it fails, and then it recovers by requesting less memory.The only PHP app on my server is Textpattern, so hoping to track down which specific http request(s) might be contributing to the issue.
Oh, by the way, for some odd reason the memory exceeding is usually at the same time each day! It sometimes occurs at other times, but there is one hour of the day where it regularly happens. This is also a mystery since I don’t see any common patterns to that particular hour.
I have instrumented my code as you suggested, I have also included the request path in my log.
Last edited by mericson (2013-08-15 04:22:01)
Offline
Re: Memory Logging
Memory logging is working great, and I don’t see any more than 10MB for any TextPattern handled request. However, something in Textpattern is apparently occasionally requesting a large block of memory, resulting in a virtual memory fault, which is failing and then they say PHP is recovering.
They stated:
PHP is requesting more memory than allowed. Once it fails it simply requests less. The first memory allocation is all that fails, which shouldn’t cause any issues with your sites. We’ve checked to make sure that the server environment is not deviating from our normal specification. Unfortunately there isn’t much more we’ll be able to do to troubleshoot this. In these cases it is always best to obtain support from the developer or original designer. It would be a disservice for us to attempt to debug software that is not maintained by our company, as we are not familiar with the original code.
Anyone have any ideas why Textpattern might request 2GB of memory !? Are there any possible malicious requests that might be targeting my server which could cause TextPattern to do this?
Last edited by mericson (2013-08-17 01:19:08)
Offline
Re: Memory Logging
Where is the the memory and request size limits on the said server set? By their message, they have disabled them, or have you? Thing is, those upload and memory limits are there for a reason. Now, if they want to allocate PHP only so much memory, they can easily limit it, and they should…
mericson wrote:
Anyone have any ideas why Textpattern might request 2GB of memory
Request doesn’t really apply here. PHP is a scripting language. Like other scripting languages, it has no memory management. It works by garbage collector, and by you setting it a strict limits for it to unsure nothing goes bad. We, PHP-space creatures, don’t request memory, and particularly we don’t handle the server itself either. The server hosts us and provides us with information. The server consumes memory and processes packets before we are even running.
Thing is, if you remove those limits (memory, request, upload size), its pretty easy to make the server to eat tons of memory. What? …no nothing malicious or magical – just send the server a big packet. You know, its server. Public facing. If you send it a lot of data, what will it do? Yes, without those limits it will eat all of that data.
That’s why PHP and other server related software have configuration files where you can set the memory and other limits. Its public facing, it accepts traffic from out there. So use those limits, don’t elevate them globally and the problem is gone.
As Textpattern goes, it will use the most memory when;
- Creating thumbnails.
- Uploading files.
If you resize a large image or upload large file, PHP may easily try to consume a lot of memory. You know, if you haven’t set any limits. If you have set limits the process will merely fail if it requires too much memory. As file uploads go, anyone can bomb your server with those. Not specifically related to Textpattern, its just HTTP request and is handled by our supervisors Mr. Web Server and Mr. PHP.
Memory logging is working great, and I don’t see any more than 10MB for any TextPattern handled request.
I did say tho:
At the end of your page template you could put something stupid like:
Emphasis on word stupid. That code has no real value, for starters it will only log requests that do work.
Last edited by Gocom (2013-08-17 19:15:14)
Offline
Pages: 1