Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
How To Check Your Plugins For Performance
Kentaurus
Join Date: Dec 2001
Posts: 332

by Kentaurus Kentaurus is offline 21 Jan 2007

Warning: Advanced tutorial - for developers only.

We all love the new product & plugins system that was introduced in vbulletin. No more doing file modifications, no more writing a lot of instructions in a long txt and following them for an hour to install a hack, just upload the product, run.. ready (with some exceptions, of course).

I found myself trying to find a "good" method for checking my plugins for performance. After all, I don't want a hack or modification going wild and slowing my whole forum. I seriously needed to find a way to find out how much resources my plugins were using. And, while developing, I wanted to make sure that I didn't have "bad code" that used too many resources.

We already had the solution, for logging the page load time, a microtime() is used. Why not do it with every hook as well, then we could check the statistics and if a hook is taking too much time to execute, disable it, or reprogram it.

Gettings these statistics is a simple modification.

1) We'll need to create a new table, run the following query (add your table prefix if necessary):


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

2) Open class_hook.php (in the includes directory), and find:


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

Change it to:


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

Curious? I just added to every hook some lines to insert into the database the start and end time, the microtime. Now all the hook execution time is logged into the database.

3) Open a couple pages on which the plugins are used. Browse a while. We need the plugins to be executed before checking the stats!


4) Run the following query on your favorite sql client, phpmyadmin, the console, or wherever you want to check the stats (add the table prefix if necessary):



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

You will get something like this:


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

This means that forumhome_complete, on average, takes 0.5 seconds to execute. Depending on your server that could be ok, or very bad. newpost_process takes 0.02 seconds to execute (that's better).

You can check the average execution time for every hook.


These are the average execution times for each hook on your forum. Of course, what you probably needed was the execution time for a plugin, or a product, not the whole hook. Doing so is out of the scope of this tutorial, this technique shouldn't be so difficult to extend for logging the time per plugin or per product. For now, seeing the information per hook is useful and a good start.

The irony? Try not to use this on a production environment since logging in the database takes some resources. You are adding a lot of queries, 2 per hook. This should be used whenever you need to benchmark performance, test your mod, and disabled after.

Last edited by Princeton; 21 Jan 2007 at 17:26..
Views: 2372
Reply With Quote
Comments
  #2  
Old 22 Jan 2007, 00:43
scotsmist scotsmist is offline
 
Join Date: May 2005
that's a handy little routine. thanks for sharing, it will be put to good use.
Reply With Quote
  #3  
Old 11 Feb 2007, 19:03
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia
one thing isnt correkt

you make a table hookstats but you insert things into ".TABLE_PREFIX."hookstats
so use just one
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 00:30.

Layout Options | Width: Wide Color: