The Main Factors Influencing Memory Usage
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #1
The Main Factors Influencing Memory Usage
What is the main factors influencing our memory usage (MyBB forum)?

(This post was last modified: 10-04-2010 07:35 AM by RateU.)
10-04-2010 07:34 AM
Find all posts by this user Quote this message in a reply
leefish Offline
Hamster
*****
Posts: 1,009
Joined: Apr 2010
Post: #2
RE: The Main Factors Influencing Memory Usage
Hmmm, is this a test question? I always thought it was calling images and SQL queries.....


[Image: leelink.gif]
MYBB1.6 & XThreads
10-04-2010 08:47 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #3
RE: The Main Factors Influencing Memory Usage
In terms of code or forum settings?

I don't really know that much to be honest.  I've generally been more interested in optimising for speed, since the memory is only going to be used for however long the script takes to run, and as long as you're not doing something silly, you won't be consuming too much (and PHP will kill your script if you use too much anyway).  I think MyBB's memory usage thing at the bottom only measures peak usage too, which may only be allocated at a tiny part during script execution.
PHP, being such a high level scripting language, is somewhat difficult to predict how much memory it will allocate; although I guess you could say speed is difficult to predict, but memory usage would be even harder to predict.

Apart from certain admin functions, I think the biggest memory users in MyBB, would potentially be the attachment download script.  The script reads the entire attachment file into memory and it will stay in memory until the script finishes running (ie when user finishes downloading (not quite, due to potential webserver buffering)).  So if a user is trying to download a 2MB attachment, MyBB reads the entire file into memory, consuming 2MB data memory plus any PHP string overheads (also, plus MyBB's core overheads) and this will stay in memory until the user nearly finishes downloading the file.
So to avoid that, I guess, don't allow really big attachments, or do a code edit to attachment.php, changing

PHP Code:
echo file_get_contents($mybb->settings['uploadspath']."/".$attachment['attachname']);

to

PHP Code:
$fp = fopen($mybb->settings['uploadspath']."/".$attachment['attachname'], 'rb');
while(!feof($fp)) echo fread($fp, 8192);
fclose($fp);

(XThreads attachment downloads do not suffer from this issue)

There are potentially a number of other places where a lot of memory could be used, for example, using a remote (URL) avatar, if a user doesn't like you and sticks like a link to a 4GB file there or something like that.


As for coding, I guess it depends on the number of variables and size of each you have, resources allocated, and amount of code loaded.


My Blog
(This post was last modified: 10-04-2010 09:03 AM by ZiNgA BuRgA.)
10-04-2010 09:02 AM
Find all posts by this user Quote this message in a reply
Firefox Wins Offline
Member
***
Posts: 164
Joined: Mar 2008
Post: #4
RE: The Main Factors Influencing Memory Usage
Your my.cnf (MySQL config) settings can be 'tweaked' to encourage using large amounts of memory.
This will speed up your site(s) if you have the memory to spare, since virtually every table is stored in memory.  Smile
10-04-2010 09:02 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #5
RE: The Main Factors Influencing Memory Usage
Ah.... I see... Thanks for the explanation and tips Smile

10-05-2010 03:30 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: