<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.4-libertus1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Memory Usage in WordPress 2.0.2</title>
	<link>/libertus/2006/05/29/wordpress-memory/</link>
	<description>The languishing ex-blog of a bloke with a job</description>
	<pubDate>Wed, 20 Aug 2008 13:10:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.4-libertus1</generator>

	<item>
		<title>by: Libertus</title>
		<link>/libertus/2006/05/29/wordpress-memory/#comment-8069</link>
		<pubDate>Mon, 29 May 2006 14:35:15 +0000</pubDate>
		<guid>/libertus/2006/05/29/wordpress-memory/#comment-8069</guid>
					<description>&lt;h3 id='plugin-memory-usage'&gt;Memory Usage of Plugins&lt;/h3&gt;

Your requests in a comment below please.</description>
		<content:encoded><![CDATA[<h3 id='plugin-memory-usage'>Memory Usage of Plugins</h3>
<p>Your requests in a comment below please.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Libertus</title>
		<link>/libertus/2006/05/29/wordpress-memory/#comment-8068</link>
		<pubDate>Mon, 29 May 2006 13:59:57 +0000</pubDate>
		<guid>/libertus/2006/05/29/wordpress-memory/#comment-8068</guid>
					<description>&lt;h3 id='unusual-admin-activity'&gt;Nothing Unusual?&lt;/h3&gt;

&lt;blockquote&gt;
1,init,3472960,73672
2,admin_menu,4090776,617816
&lt;/blockquote&gt;

Wait a minute! Between initialisation and admin_menu hooks being called, 600KB of RAM is consumed. I didn't pay much attention to that earlier on because it was just there. Now I think I'll take a closer look. If that figure could be reduced, the WP admin working set might drop below the magic 4MB limit.

What consumes 600KB between init and menu?

&lt;h4&gt;Tracing The Path Between Initialisation And The Admin Menu&lt;/h4&gt;

Action 'init' is triggered at the end of &lt;code&gt;wp-settings.php&lt;/code&gt;, which is required by &lt;code&gt;wp-config.php&lt;/code&gt;, which is required at the beginning of &lt;code&gt;wp-admin/admin.php&lt;/code&gt;.

Action 'admin_menu' is triggered at the end of &lt;code&gt;wp-admin/menu.php&lt;/code&gt;.

The code that needs to be examined lies between lines 19 to 54 of &lt;code&gt;wp-admin/admin.php&lt;/code&gt;. The quickest way to find out what's happening is to add more of my little memory probes. Here's a Dashboard memory dump to get your teeth into.

&lt;dl class='shell'&gt;
&lt;dt&gt;&lt;kbd&gt;php dump.php admin-memtest-20060529-151631&lt;/kbd&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;samp&gt;0,plugins_loaded,3347456,3347456
1,init,3417504,70048
2,post-admin-functions,3850776,433272
3,post-admin-db,3949256,98480
4,post-registration-functions,3978648,29392
5,post-auth_redirect,3978880,232
6,post-nocache_headers,3979000,120
7,post-update_category_cache,3979000,0
8,post-get_currentuserinfo,3979168,168
9,pre-menu,3980288,1120
10,admin_menu,4037104,56816
11,admin_head,4003152,-33952
12,admin_notices,4025184,22032
13,update_option_rss_42109a30548dd2078da9009859b481aa_ts,4348832,323648
14,activity_box_end,4376616,27784
15,update_option_rss_0ff4b43bd116a9d8720d689c80e7dfd4_ts,4466824,90208
16,update_option_rss_867bd5c64f85878d03a060509cd2f92c,4967152,500328
17,update_option_rss_867bd5c64f85878d03a060509cd2f92c_ts,4650208,-316944
18,admin_footer,4545680,-104528
19,shutdown,4485632,-60048
20,/~paul/wp-memtest/wp-admin/,4481344,-4288&lt;/samp&gt;&lt;/dd&gt;
&lt;/dl&gt;

The inclusion of &lt;code&gt;wp-admin/admin-functions.php&lt;/code&gt; consumes the most RAM followed by the database "abstraction" layer in &lt;code&gt;wp-admin/wp-db.php&lt;/code&gt;. Given the nature of these files, I am not at all surprised by the scale of the memory usage so I can't imagine I'll find much to trim away. Best to be sure though.

&lt;h4&gt;Why Do The Admin Functions Need 400KB Of RAM?&lt;/h4&gt;

No reason I can see. It's just a big file that costs 400KB to load.

&lt;h4&gt;Why Do The Database Functions Need 100KB Of RAM?&lt;/h4&gt;

This file constructs an object that connects to a database. If that only costs 100KB of RAM, fantastic!</description>
		<content:encoded><![CDATA[<h3 id='unusual-admin-activity'>Nothing Unusual?</h3>
<blockquote><p>
1,init,3472960,73672<br />
2,admin_menu,4090776,617816
</p></blockquote>
<p>Wait a minute! Between initialisation and admin_menu hooks being called, 600KB of RAM is consumed. I didn&#8217;t pay much attention to that earlier on because it was just there. Now I think I&#8217;ll take a closer look. If that figure could be reduced, the WP admin working set might drop below the magic 4MB limit.</p>
<p>What consumes 600KB between init and menu?</p>
<h4>Tracing The Path Between Initialisation And The Admin Menu</h4>
<p>Action &#8216;init&#8217; is triggered at the end of <code>wp-settings.php</code>, which is required by <code>wp-config.php</code>, which is required at the beginning of <code>wp-admin/admin.php</code>.</p>
<p>Action &#8216;admin_menu&#8217; is triggered at the end of <code>wp-admin/menu.php</code>.</p>
<p>The code that needs to be examined lies between lines 19 to 54 of <code>wp-admin/admin.php</code>. The quickest way to find out what&#8217;s happening is to add more of my little memory probes. Here&#8217;s a Dashboard memory dump to get your teeth into.</p>
<dl class='shell'>
<dt><kbd>php dump.php admin-memtest-20060529-151631</kbd></dt>
<dd><samp>0,plugins_loaded,3347456,3347456<br />
1,init,3417504,70048<br />
2,post-admin-functions,3850776,433272<br />
3,post-admin-db,3949256,98480<br />
4,post-registration-functions,3978648,29392<br />
5,post-auth_redirect,3978880,232<br />
6,post-nocache_headers,3979000,120<br />
7,post-update_category_cache,3979000,0<br />
8,post-get_currentuserinfo,3979168,168<br />
9,pre-menu,3980288,1120<br />
10,admin_menu,4037104,56816<br />
11,admin_head,4003152,-33952<br />
12,admin_notices,4025184,22032<br />
13,update_option_rss_42109a30548dd2078da9009859b481aa_ts,4348832,323648<br />
14,activity_box_end,4376616,27784<br />
15,update_option_rss_0ff4b43bd116a9d8720d689c80e7dfd4_ts,4466824,90208<br />
16,update_option_rss_867bd5c64f85878d03a060509cd2f92c,4967152,500328<br />
17,update_option_rss_867bd5c64f85878d03a060509cd2f92c_ts,4650208,-316944<br />
18,admin_footer,4545680,-104528<br />
19,shutdown,4485632,-60048<br />
20,/~paul/wp-memtest/wp-admin/,4481344,-4288</samp></dd>
</dl>
<p>The inclusion of <code>wp-admin/admin-functions.php</code> consumes the most RAM followed by the database &#8220;abstraction&#8221; layer in <code>wp-admin/wp-db.php</code>. Given the nature of these files, I am not at all surprised by the scale of the memory usage so I can&#8217;t imagine I&#8217;ll find much to trim away. Best to be sure though.</p>
<h4>Why Do The Admin Functions Need 400KB Of RAM?</h4>
<p>No reason I can see. It&#8217;s just a big file that costs 400KB to load.</p>
<h4>Why Do The Database Functions Need 100KB Of RAM?</h4>
<p>This file constructs an object that connects to a database. If that only costs 100KB of RAM, fantastic!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Libertus</title>
		<link>/libertus/2006/05/29/wordpress-memory/#comment-8067</link>
		<pubDate>Mon, 29 May 2006 12:21:04 +0000</pubDate>
		<guid>/libertus/2006/05/29/wordpress-memory/#comment-8067</guid>
					<description>&lt;h3 id='wordpress-admin-memory-usage'&gt;WordPress Administrative Interface Memory Usage&lt;/h3&gt;

My probes are being gathered during the admin interface but not dumped. I reckon wp-admin/admin.php is a good place to register my shutdown function which dumps the memory probe data.

&lt;h4&gt;First Run&lt;/h4&gt;
I do like it when things work first time. Especially this time, as the results confirm &lt;a href="/libertus/2006/03/16/wordpress-option-spam/"&gt;something I already knew&lt;/a&gt;.

&lt;dl&gt;
&lt;dt&gt;&lt;kbd&gt;php dump.php admin-memtest-20060529-132332&lt;/kbd&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;samp&gt;0,plugins_loaded,3343480,3343480
1,init,3413632,70152
2,admin_menu,4031776,618144
3,admin_head,4000568,-31208
4,admin_notices,4022600,22032
5,update_option_rss_42109a30548dd2078da9009859b481aa_ts,4346512,323912
6,activity_box_end,4374360,27848
7,update_option_rss_0ff4b43bd116a9d8720d689c80e7dfd4_ts,4464528,90168
8,update_option_rss_867bd5c64f85878d03a060509cd2f92c,4964856,500328
9,update_option_rss_867bd5c64f85878d03a060509cd2f92c_ts,4647880,-316976
10,admin_footer,4543160,-104720
11,shutdown,4483112,-60048
12,/~paul/wp-memtest/wp-admin/,4478824,-4288&lt;/samp&gt;&lt;/dd&gt;
&lt;/dl&gt;

The Dashboard is a monster! It uses &lt;small&gt;4964856-3343480=&lt;/small&gt;1.6MB of RAM, a fifth of the total! I hope this is a limited phenomenon.

&lt;h4&gt;Write A Post, Post A Picture&lt;/h4&gt;

Hmm... I appear to have introduced a bug. On uploading the picture for my post, the picture upload box says &lt;q&gt;This script was not meant to be called directly.&lt;/q&gt; It worked before. Maybe a different picture. Odd, the second picture worked fine. I'll try the first one again.

Why does my image named &lt;q&gt;emmas-flower.png&lt;/q&gt; upload OK but my image named &lt;q&gt;emmas flower drawing.png&lt;/q&gt; does not? It might be the spaces in the filename, so I'll replace them with dashes. Upload &lt;q&gt;emmas-flower-drawing.png&lt;/q&gt;. No, same response. &lt;q&gt;This script was not meant to be called directly.&lt;/q&gt;

Is something wrong with the image? Oh. Yes. Duh! &lt;q&gt;emmas-flower-drawing.png&lt;/q&gt; is 12.7MB in size! Not a hope in hell of uploading that. I'll need to drop it in size, to under 2MB, which is the standard upload file size limit. A quick "file save as..." later and I now have a rather more svelte 750KB JPEG. Upload that. It works, almost. Although I can clearly see a thumbnail of the picture, the options menu tells me there is no thumbnail associated with the image. Whatever.

After a bit of faffing, I post some pictures and a bit of text. What memory probe goodness have I got?

&lt;h4&gt;WordPress Write Post and Inline Image Uploading Memory Use&lt;/h4&gt;

I have 15 probe files so I must have been doing more faffing than I thought. There are a lot from the inline uploading, as I expected. I get the feeling that I'm losing probe data due to the admin interface program being executed more than once per second. The reading I was after, the actual saving of a post, is as follows:

&lt;dl&gt;
&lt;dt&gt;&lt;kbd&gt;php dump.php admin-memtest-20060529-135413&lt;/kbd&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;samp&gt;0,plugins_loaded,3399288,3399288
1,init,3472960,73672
2,admin_menu,4090776,617816
3,check_admin_referer,4043952,-46824
4,publish_post,4065600,21648
5,save_post,4241208,175608
6,wp_insert_post,4241208,0
7,edit_post,4270256,29048
8,publish_post,4270256,0
9,save_post,4271456,1200
10,wp_insert_post,4271456,0
11,shutdown,4262984,-8472
12,/~paul/wp-memtest/wp-admin/post.php,4262224,-760&lt;/samp&gt;&lt;/dd&gt;
&lt;/dl&gt;

Nothing unusual.

&lt;h4&gt;Minor Changes To The Probe&lt;/h4&gt;

I ensure that the dump output filename is unique.

&lt;h4&gt;Clean Sheet, Once More With A Post And Pictures&lt;/h4&gt;

No need to bore with the details. Overall, WordPress uses memory efficiently, apart from the Dashboard.</description>
		<content:encoded><![CDATA[<h3 id='wordpress-admin-memory-usage'>WordPress Administrative Interface Memory Usage</h3>
<p>My probes are being gathered during the admin interface but not dumped. I reckon wp-admin/admin.php is a good place to register my shutdown function which dumps the memory probe data.</p>
<h4>First Run</h4>
<p>I do like it when things work first time. Especially this time, as the results confirm <a href="/libertus/2006/03/16/wordpress-option-spam/">something I already knew</a>.</p>
<dl>
<dt><kbd>php dump.php admin-memtest-20060529-132332</kbd></dt>
<dd><samp>0,plugins_loaded,3343480,3343480<br />
1,init,3413632,70152<br />
2,admin_menu,4031776,618144<br />
3,admin_head,4000568,-31208<br />
4,admin_notices,4022600,22032<br />
5,update_option_rss_42109a30548dd2078da9009859b481aa_ts,4346512,323912<br />
6,activity_box_end,4374360,27848<br />
7,update_option_rss_0ff4b43bd116a9d8720d689c80e7dfd4_ts,4464528,90168<br />
8,update_option_rss_867bd5c64f85878d03a060509cd2f92c,4964856,500328<br />
9,update_option_rss_867bd5c64f85878d03a060509cd2f92c_ts,4647880,-316976<br />
10,admin_footer,4543160,-104720<br />
11,shutdown,4483112,-60048<br />
12,/~paul/wp-memtest/wp-admin/,4478824,-4288</samp></dd>
</dl>
<p>The Dashboard is a monster! It uses <small>4964856-3343480=</small>1.6MB of RAM, a fifth of the total! I hope this is a limited phenomenon.</p>
<h4>Write A Post, Post A Picture</h4>
<p>Hmm&#8230; I appear to have introduced a bug. On uploading the picture for my post, the picture upload box says <q>This script was not meant to be called directly.</q> It worked before. Maybe a different picture. Odd, the second picture worked fine. I&#8217;ll try the first one again.</p>
<p>Why does my image named <q>emmas-flower.png</q> upload OK but my image named <q>emmas flower drawing.png</q> does not? It might be the spaces in the filename, so I&#8217;ll replace them with dashes. Upload <q>emmas-flower-drawing.png</q>. No, same response. <q>This script was not meant to be called directly.</q></p>
<p>Is something wrong with the image? Oh. Yes. Duh! <q>emmas-flower-drawing.png</q> is 12.7MB in size! Not a hope in hell of uploading that. I&#8217;ll need to drop it in size, to under 2MB, which is the standard upload file size limit. A quick &#8220;file save as&#8230;&#8221; later and I now have a rather more svelte 750KB JPEG. Upload that. It works, almost. Although I can clearly see a thumbnail of the picture, the options menu tells me there is no thumbnail associated with the image. Whatever.</p>
<p>After a bit of faffing, I post some pictures and a bit of text. What memory probe goodness have I got?</p>
<h4>WordPress Write Post and Inline Image Uploading Memory Use</h4>
<p>I have 15 probe files so I must have been doing more faffing than I thought. There are a lot from the inline uploading, as I expected. I get the feeling that I&#8217;m losing probe data due to the admin interface program being executed more than once per second. The reading I was after, the actual saving of a post, is as follows:</p>
<dl>
<dt><kbd>php dump.php admin-memtest-20060529-135413</kbd></dt>
<dd><samp>0,plugins_loaded,3399288,3399288<br />
1,init,3472960,73672<br />
2,admin_menu,4090776,617816<br />
3,check_admin_referer,4043952,-46824<br />
4,publish_post,4065600,21648<br />
5,save_post,4241208,175608<br />
6,wp_insert_post,4241208,0<br />
7,edit_post,4270256,29048<br />
8,publish_post,4270256,0<br />
9,save_post,4271456,1200<br />
10,wp_insert_post,4271456,0<br />
11,shutdown,4262984,-8472<br />
12,/~paul/wp-memtest/wp-admin/post.php,4262224,-760</samp></dd>
</dl>
<p>Nothing unusual.</p>
<h4>Minor Changes To The Probe</h4>
<p>I ensure that the dump output filename is unique.</p>
<h4>Clean Sheet, Once More With A Post And Pictures</h4>
<p>No need to bore with the details. Overall, WordPress uses memory efficiently, apart from the Dashboard.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
