Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Avoid usage of file-system for compiled templates

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
sdonald
Smarty n00b


Joined: 23 May 2007
Posts: 1

PostPosted: Wed May 23, 2007 9:55 am    Post subject: Avoid usage of file-system for compiled templates Reply with quote

Hi!

My team and me are using Smarty as a primary interface technology. Year or two ago Smarty was perfect. Today, we have more dynamic Web and even Web applications so, interface is changing and becaming more dynamic too.

Problem we've noticed few weeks ago was:
- we have developed a web application
- application has very dynamic interface (every request means new render)
- there are about 100-200 users using application at the same time
- users has about 5-10 requests per minute
- server is under Linux OS and with 8 CPUs

Where is the problem? Well, we have noticed messages like:

Smarty::include(): Failed opening './temp/%%0F^0F8^0F826A75%%form.tpl.php' for inclusion

But that file does exist! And problem occurs when different requests on a different CPUs try to change a same file. Problem is at 'Smarty.class.php', line 1265:
include($_smarty_compile_path);

We changed that line into:
$Retries = 0;
while ($Retries < 10)
{
if (@include $_smarty_compile_path)
{
break;
}
else
{
usleep(rand(1000,100000));
}
$Retries++;
}
and problem i solved, for now.

Other solutions we have tried was to keep templates on a virtual partition because of speed but that didn't helped.

Is there any way to skip writing of compiled files into FS and after that reread them? If not, that would be nice option in a new Smarty version.

Best regards
sdonald
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed May 23, 2007 1:41 pm    Post subject: Reply with quote

It looks like there is a race condition when a template is getting compiled. Are you by chance compiling templates more often than need be? Or are you often creating and editing templates that are live?
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed May 23, 2007 1:52 pm    Post subject: Reply with quote

Just thinking aloud here,

When Smarty re-writes a file, it first writes out to a tmp file, then unlinks (deletes) the original file and then moves the tmp file over to the original file name (rename). The unlink step only happens because windows has problems with rename() and overwriting a file.

Since you're on linux, you could try commenting out @unlink($params['filename']); in the internals/core.write_file.php file and see if that helps any with the race condition.
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed May 23, 2007 6:13 pm    Post subject: Reply with quote

mohrt wrote:
Just thinking aloud here,

When Smarty re-writes a file, it first writes out to a tmp file, then unlinks (deletes) the original file and then moves the tmp file over to the original file name (rename). The unlink step only happens because windows has problems with rename() and overwriting a file.

Since you're on linux, you could try commenting out @unlink($params['filename']); in the internals/core.write_file.php file and see if that helps any with the race condition.


The unlink only happens under windows-based environments.

Retries are not a bad idea, although I think it is more usual to use an increasing time delay rather than a purely random delay. Another idea is to introduce an flock around the relevant rename/copy/move functionality, though I see that as a band-aid and somewhat unreliable fix -- especially since it may not actually help Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP