Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > General > Member Archives
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Details »»

Version: , by (Guest)
Developer Last Online: Jan 1970 Show Printable Version Email this Page

Version: Unknown Rating:
Released: 12-01-2000 Last Update: Never Installs: 0
 
No support by the author.

When I began development of the site I'm currently working on, I decided to store templates in mysql to make things a little easier to manage. But just a few days ago I decided to see what sort of performance change there would be if I moved the templates over to text files. Boy was I suprised. Page execution changed from about .12 to .16 down to .06, a complete 2/3's drop on some pages!

I figure vB already taxes mysql a great deal, why not alleviate some of that by transfering the templates over to text files. Anyone care to try this? I've written a script that'll transfer all the templates into text files and a quick change to the gettemplate function. Remember to have a backup of global.php, and to create a directory to write the templates too.

The script to create the text files:
--------------------------------------------------------------------------------------
<?php

require ("global.php");

$templates=$DB_site->query("SELECT title,template FROM template");
$dirtowrite = "/path/to/templates/dir";

while ($template=$DB_site->fetch_array($templates)) {
$file = fopen ("$dirtowrite/$template[title].txt", "w");
fwrite($file,$template[template]);
fclose($file);

print "$template[title]: created<br>\n";
}

?>
--------------------------------------------------------------------------------------

Now in global.php find:

function gettemplate(...

And replace the entire function with this one:

function gettemplate($templatename,$escape=1) {
// grab a template

$temp_file = "/dir/to/templates/$templatename.txt";
$fd = fopen ($temp_file, "r");
$template = fread ($fd, filesize ($temp_file));
fclose($fd);

return $template;
}

I'm anxious to hear if there are any noticable performance changes on high-traffic sites.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 12-01-2000, 11:09 PM
Guest
 
Posts: n/a
Default

I take it you didn't try to read 20+ files per page, on every page.

vB 1.1.4 alleviates a lot of the queries for templates by getting every template needed in one query, and put into a cache.
Reply With Quote
  #3  
Old 12-01-2000, 11:12 PM
Guest
 
Posts: n/a
Default

Also,

Code:
function gettemplate($templatename,$escape=1) { 
// grab a template 

$temp_file = "/dir/to/templates/$templatename.txt"; 
$fd = fopen ($temp_file, "r"); 
$template = fread ($fd, filesize ($temp_file)); 
fclose($fd); 

return $template; 
}
Try viewing a thread with 30 posts. You're going to read 30 postbit.txt's alone.
Reply With Quote
  #4  
Old 12-01-2000, 11:18 PM
Guest
 
Posts: n/a
Default

Never the less, I'm going to try it anyway, I'll be back with findings in about 30 minutes.
Reply With Quote
  #5  
Old 12-01-2000, 11:28 PM
Guest
 
Posts: n/a
Default

hey Krucifyx

well i believe freddie/rangersfan did a similar hack with templates i think ? you'd have to ask freddie though
Reply With Quote
  #6  
Old 12-02-2000, 12:04 AM
Guest
 
Posts: n/a
Default

Results were inconclusive:
Code:
Using flat file templates:
----------------------------------------------------------------------
                                /vb114/index.php		1.7282350063324
                                /vb114/index.php		INVALID TIME
                                /vb114/index.php		1.5354700088501
                                /vb114/index.php		0.5702189207077
                                /vb114/index.php		0.53852188587189
                                /vb114/index.php		1.5131859779358
                                /vb114/index.php		0.56164300441742
                                /vb114/index.php		0.64329504966736
                                /vb114/index.php		0.51034200191498
                                /vb114/index.php		0.53449499607086
               /vb114/forumdisplay.php?forumid=1		1.563912987709
               /vb114/forumdisplay.php?forumid=1		INVALID TIME
               /vb114/forumdisplay.php?forumid=1		1.4870719909668
               /vb114/forumdisplay.php?forumid=1		INVALID TIME
               /vb114/forumdisplay.php?forumid=1		1.4797700643539
               /vb114/forumdisplay.php?forumid=1		0.42898499965668
               /vb114/forumdisplay.php?forumid=1		0.49602794647217
               /vb114/forumdisplay.php?forumid=1		0.51602602005005
               /vb114/forumdisplay.php?forumid=1		0.52056705951691
/vb114/forumdisplay.php?forumid=1&daysprune=1000		0.55617499351501
/vb114/forumdisplay.php?forumid=1&daysprune=1000		INVALID TIME
/vb114/forumdisplay.php?forumid=1&daysprune=1000		1.5123800039291
/vb114/forumdisplay.php?forumid=1&daysprune=1000		INVALID TIME
/vb114/forumdisplay.php?forumid=1&daysprune=1000		1.5282100439072
                /vb114/showthread.php?threadid=4		0.97411799430847
                /vb114/showthread.php?threadid=4		0.73896205425262
                /vb114/showthread.php?threadid=4		0.65621793270111
                /vb114/showthread.php?threadid=4		INVALID TIME
                /vb114/showthread.php?threadid=4		INVALID TIME
                /vb114/showthread.php?threadid=4		1.6474299430847
                /vb114/showthread.php?threadid=4		0.66209602355957
                /vb114/showthread.php?threadid=4		0.27366995811462
                /vb114/showthread.php?threadid=4		0.69844806194305
                /vb114/showthread.php?threadid=4		0.7712379693985
                /vb114/showthread.php?threadid=4		0.87718105316162
----------------------------------------------------------------------

Using MySQL templates:
----------------------------------------------------------------------
                                /vb114/index.php		0.56958401203156
                                /vb114/index.php		INVALID TIME
                                /vb114/index.php		0.52925097942352
                                /vb114/index.php		0.56821501255035
                                /vb114/index.php		0.56365704536438
                                /vb114/index.php		0.61730802059174
                                /vb114/index.php		1.5742579698563
                                /vb114/index.php		0.52257800102234
                                /vb114/index.php		INVALID TIME
                                /vb114/index.php		1.6354759931564
                                /vb114/index.php		0.60910892486572
               /vb114/forumdisplay.php?forumid=1		INVALID TIME
               /vb114/forumdisplay.php?forumid=1		INVALID TIME
               /vb114/forumdisplay.php?forumid=1		1.4293439388275
               /vb114/forumdisplay.php?forumid=1		INVALID TIME
               /vb114/forumdisplay.php?forumid=1		0.48564791679382
               /vb114/forumdisplay.php?forumid=1		0.43799495697021
               /vb114/forumdisplay.php?forumid=1		0.52786505222321
               /vb114/forumdisplay.php?forumid=1		1.4195520877838
               /vb114/forumdisplay.php?forumid=1		INVALID TIME
/vb114/forumdisplay.php?forumid=1&daysprune=1000		INVALID TIME
/vb114/forumdisplay.php?forumid=1&daysprune=1000		0.61003601551056
/vb114/forumdisplay.php?forumid=1&daysprune=1000		INVALID TIME
/vb114/forumdisplay.php?forumid=1&daysprune=1000		0.5251590013504
/vb114/forumdisplay.php?forumid=1&daysprune=1000		0.55706202983856
/vb114/forumdisplay.php?forumid=1&daysprune=1000		0.60305690765381
                /vb114/showthread.php?threadid=4		INVALID TIME
                /vb114/showthread.php?threadid=4		0.68921291828156
                /vb114/showthread.php?threadid=4		0.68019592761993
                /vb114/showthread.php?threadid=4		1.6432230472565
                /vb114/showthread.php?threadid=4		INVALID TIME
                /vb114/showthread.php?threadid=4		0.63571894168854
                /vb114/showthread.php?threadid=4		0.71191096305847
                /vb114/showthread.php?threadid=4		0.63852798938751
----------------------------------------------------------------------
Here's my time testing code, inserted under set_magic_quotes_runtime(0); in global.php:
Code:
function timeinsert() {
	global $starttime,$PATH_INFO,$QUERY_STRING;
	
	$timeparts = explode(" ",microtime());
  	$endtime = $timeparts[1].substr($timeparts[0],1);
  	
	$timedif = $endtime - $starttime;
	if ($timedif<0) {
		$timedif = "INVALID TIME";
	}
	if ($QUERY_STRING) {
		$blah = "$PATH_INFO?$QUERY_STRING";
		$write = sprintf("%60s", $blah);
	} else {
		$write = sprintf("%60s", $PATH_INFO);
	}
		$write .= "\t\t$timedif\n";
	$file = fopen("C:/Inetpub/wwwroot/vb114/timingtest.txt", "a");
	fwrite($file, "$write");
	fclose($file);
}
register_shutdown_function("timeinsert");

$timeparts = explode(" ",microtime());
$starttime = $timeparts[1].substr($timeparts[0],1);
(edit so it works in your directory)

Here's the updated gettemplate function for flat files:
Code:
function gettemplate($templatename,$escape=1) { 
	global $templatecache;

	if ($templatecache[$templatename]!="") {
		$template = $templatecache[$templatename];
	} else {
		$temp_file = "C:/Inetpub/wwwroot/vb114/templates/$templatename.txt"; 
		$fd = fopen ($temp_file, "r"); 
		$template = fread ($fd, filesize ($temp_file)); 
		fclose($fd); 
		$templatecache[$templatename] = $template;
	}
	if ($escape==1) {
    $template=str_replace("\"","\\\"",$template);
  	}

	return $template; 
}
"Tests" done on a Celeron500, 64MB (ick, soon to be 198), Win98SE, PWS.
Reply With Quote
  #7  
Old 12-02-2000, 12:37 AM
Guest
 
Posts: n/a
Default

I have done this before but I didn't run any time tests. I also cached the .txt files so there were no differences between the two.

My interest was would the less load on MySQL (no longer loading templates) vs the increased load on the webserver (now loading files) benefit vB. I also didn't come to any usable conclusions as I had no way to put it to the test on a large site.

[Edited by freddie on 12-01-2000 at 09:39 PM]
Reply With Quote
  #8  
Old 12-02-2000, 06:49 AM
Guest
 
Posts: n/a
Default

Just a tip for 1.14 users on high-traffic sites...

Add an index on the "title" field in the "template" table. Its CRITICAL.
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 03:15 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04098 seconds
  • Memory Usage 2,259KB
  • Queries Executed 21 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (4)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (7)postbit
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete