Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
[How to] Cut down on memory usage
Brad
Join Date: Nov 2001
Posts: 4,765

Washington
by Brad Brad is offline 06 Jan 2006

This is in the manual but I've yet to see it mentioned here.

The plugin system works by storing all plugin code for all scripts in memory, so you can quickly find your plugins using large amounts of memory if they contain a lot of code.

A simple way to avoid this problem is to use the plugin code simply to call an external script, which contains all the complex code. In this way the code is only loaded when it is actually required.

For example, a plugin could contain this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

or alternatively, that code could be placed into a file called (for example) plugins/my_script.php, and the plugin itself would contain this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Naturally, the second option will use up far less memory than the first, and this saving will become more and more beneficial as the amount of code to be run increases.
You should also take a look at this project: http://www.vbulletin.org/forum/showthread.php?t=107315

Last edited by Brad; 09 Feb 2006 at 08:43..
Views: 11210
Reply With Quote
Comments
  #2  
Old 06 Jan 2006, 22:27
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Real name: Paul M
Would this slow execution if lots of plugins were calling lots of files ?
__________________
Former vBulletin.org Staff Member


Cable Forum
Please do not PM me about custom work - I no longer undertake any.
Note: I will not answer support questions via e-mail or PM - please use the relevant thread or forum.
Reply With Quote
  #3  
Old 06 Jan 2006, 22:38
The Geek's Avatar
The Geek The Geek is offline
 
Join Date: Sep 2003
Originally Posted by Paul M
Would this slow execution if lots of plugins were calling lots of files ?
A lot less then housing all the PHP for all files in memory at all time.

The bulk of my processing is done via external files.
Reply With Quote
  #4  
Old 03 Feb 2006, 07:24
Milad's Avatar
Milad Milad is offline
 
Join Date: May 2005
Real name: Milad
Originally Posted by Paul M
Would this slow execution if lots of plugins were calling lots of files ?
I agree

I think files modifications would be better for this purpose
Reply With Quote
  #5  
Old 03 Feb 2006, 08:28
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
I have been thinking about creating an extension that will allow 'include-files' for plugins. They would be loaded as regular plugins (not file uploads), and can be loaded into memory whenever needed (for example: require_pluginlibrary_once('myfunctionlibraryplugin'); ).

Like this you might get the best of both worlds:
- No file uploads
- Only loaded into memory when needed
__________________
Marco van Herwaarden
Ex vBulletin.org Coordinator
Reply With Quote
  #6  
Old 03 Feb 2006, 17:26
PennylessZ28 PennylessZ28 is offline
 
Join Date: Mar 2002
Real name: Mike
I like that concept, I think I am going to play with this some more.
Reply With Quote
  #7  
Old 03 Feb 2006, 17:30
99SIVTEC 99SIVTEC is offline
 
Join Date: Nov 2001
i'm ditching the plugin system on most of my larger sites. I'm just hardcoding the hacks. The plugin system is great in principal, but it eats up memory, increases queries, and slows down execution.
Reply With Quote
  #8  
Old 03 Feb 2006, 17:36
PennylessZ28 PennylessZ28 is offline
 
Join Date: Mar 2002
Real name: Mike
Arrow

Originally Posted by 99SIVTEC
i'm ditching the plugin system on most of my larger sites. I'm just hardcoding the hacks. The plugin system is great in principal, but it eats up memory, increases queries, and slows down execution.
Oh so true. If only there was a way to use this concept of the xml plugin to also upload a file like the above. So its not stored in memory.
Reply With Quote
  #9  
Old 03 Feb 2006, 19:37
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Originally Posted by 99SIVTEC
i'm ditching the plugin system on most of my larger sites. I'm just hardcoding the hacks. The plugin system is great in principal, but it eats up memory, increases queries, and slows down execution.
If coded for saving memory(ie. 99% of executable code in include files), a plugin don't need to use much memory, nor does it need to use more queries or slow down significantly.
__________________
Marco van Herwaarden
Ex vBulletin.org Coordinator
Reply With Quote
  #10  
Old 03 Feb 2006, 19:40
amykhar's Avatar
amykhar amykhar is offline
 
Join Date: Oct 2001
Real name: Amy
Originally Posted by Brad
This is in the manual but I've yet to see it mentioned here.
I feel better now. Somebody griped when I wrote my Amazon plugin this way
__________________
amykhar.com
----------------------------------------
I do not respond to PM requests for coding assistance.
Reply With Quote
  #11  
Old 03 Feb 2006, 20:06
99SIVTEC 99SIVTEC is offline
 
Join Date: Nov 2001
Just having the plugin system turned on uses extra queries. A good programmer ca hack vbulletin in such a way as to add few if any extra queries, but the system itself is what adds the extra queries.

Originally Posted by MarcoH64
If coded for saving memory(ie. 99% of executable code in include files), a plugin don't need to use much memory, nor does it need to use more queries or slow down significantly.
Reply With Quote
  #12  
Old 03 Feb 2006, 20:10
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Originally Posted by 99SIVTEC
Just having the plugin system turned on uses extra queries. A good programmer ca hack vbulletin in such a way as to add few if any extra queries, but the system itself is what adds the extra queries.
Not sure on the exact amount of added queries when the plugin system is turned on, but it is not much, and they are good optimiyed and won't effect your board much from a performance point of view.

Remember that the number of queries is almost irrelevant for performance, it is the execution time that counts.
__________________
Marco van Herwaarden
Ex vBulletin.org Coordinator
Reply With Quote
  #13  
Old 03 Feb 2006, 20:21
PennylessZ28 PennylessZ28 is offline
 
Join Date: Mar 2002
Real name: Mike
Seems to me that just putting the plugin code in a php file and replacing it with

include('./plugins/my_script.php');

Doesn't work 100%
Reply With Quote
  #14  
Old 03 Feb 2006, 20:45
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Nobody ever said that things would work without any modification.
__________________
Marco van Herwaarden
Ex vBulletin.org Coordinator
Reply With Quote
  #15  
Old 03 Feb 2006, 20:57
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Real name: Andreas
1. Turning the Plugin System On or Off does not have any impact on the amout of queries.
2. Memory Footprint is not a such a big issue. In most cases, forumcache (which is loaded on every page) for example will be a lot bigger then the plugins.

Having to eval() the code all the time, that is an issue.

Therefore, complex plugin code (especially in high-traffic places like global.php, postbit, showthread, forumdisplay, etc.) should be moved out to include files.
(Could even be done automatically. I wrote a proof-of-concept hack that writes include-files if the plugin-code on one hook is > X bytes long.)
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Article Options

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


New To Site? Need Help?

All times are GMT. The time now is 18:01.

Layout Options | Width: Wide Color: