View previous topic :: View next topic |
Author |
Message |
ziege Smarty Rookie
Joined: 16 Aug 2005 Posts: 13
|
Posted: Tue Jul 12, 2011 6:08 pm Post subject: Performance improvement for Windows/IIS |
|
|
Hi,
I moved my website to a Windows Server (2008 R2) with the IIS Webserver (7.5, PHP via FastCGI) some time ago and recognized a really bad performance, especially on higher load.
I knew that file operations are more expensive on Windows Servers, but the results of XDebug showed, that these operations are very expensive - and that Smarty caused most of these file operations.
Every call of file_exists() or filemtime() can take 200ms and more on high load, and Smarty calls these functions about 30 times (one page with some includes). So this leads to several seconds to load a page...
A first fix improved the performance a lot (one call instead of two in most cases).
I changed the method "getCompiledTimestamp" in "Smarty_Internal_Template" as follows:
Code: | ...
public function getCompiledTimestamp ()
{
return $this->compiled_timestamp === null ?
($this->compiled_timestamp = (!$this->resource_object->isEvaluated) ? @filemtime($this->getCompiledFilepath()) : false) :
$this->compiled_timestamp;
}
... |
Changes:
- Removed file_exists() call
- added a "@" to suppress a potential error for the filemtime() call
Perhaps this should be added to Smarty for a better performance (perhaps with an additional OS check).
Bye,
Christoph |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Jul 12, 2011 8:47 pm Post subject: |
|
|
Both file_exists() and filemtime() do cache the file status, so just the first call for a specific file is slow. So you should not see a big difference in performance.
Anyway the template handling has changed quite a bit for optimizations at resource and file handling in Smarty 3.1 and file_exists() call have been removed whenever possible. |
|
Back to top |
|
ziege Smarty Rookie
Joined: 16 Aug 2005 Posts: 13
|
Posted: Wed Jul 13, 2011 5:26 am Post subject: |
|
|
I thought so too, but I couldn't see any real caching effect, although I already optimized the settings. AFAIK the calls are only cached when they are successful (when the file exists).
I will try the 3.1 version soon... |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Jul 13, 2011 12:05 pm Post subject: |
|
|
Yes you are right, the file status is only cached when the file does exists. But this is normally the case. You will have none existing compiled files only if the source template is a new file or on cache files when when it was never created before. |
|
Back to top |
|
ziege Smarty Rookie
Joined: 16 Aug 2005 Posts: 13
|
Posted: Mon Jul 18, 2011 1:27 pm Post subject: |
|
|
I just tested the 3.1 version and it works great, overall about 25% faster on my dev system. And I like the new CacheResource API - it was really simple to integrate a KeyValueStore for WinCache. |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Mon Jul 18, 2011 1:46 pm Post subject: |
|
|
ziege wrote: | I just tested the 3.1 version and it works great, overall about 25% faster on my dev system. And I like the new CacheResource API - it was really simple to integrate a KeyValueStore for WinCache. |
Feel free to share your performace tests… |
|
Back to top |
|
ziege Smarty Rookie
Joined: 16 Aug 2005 Posts: 13
|
Posted: Mon Jul 25, 2011 9:59 am Post subject: |
|
|
My dev system isn't a good system for performance tests, but I will try to post results of the live system later.
Here is the WinCache version of the KeyValueStore (I could not find any information on limitations for the key, as mentioned for the memcache example - if you know any limitations, please notify me).
Code: |
<?php
/**
* WinCache CacheResource
*
* CacheResource Implementation based on the KeyValueStore API to use
* wincache as the storage resource for Smarty's output caching.
*/
class Smarty_CacheResource_Wincache extends Smarty_CacheResource_KeyValueStore {
/**
* Read values for a set of keys from cache
*
* @param array $keys list of keys to fetch
* @return array list of values with the given keys used as indexes
* @return boolean true on success, false on failure
*/
protected function read(array $keys)
{
return wincache_ucache_get($keys);
}
/**
* Save values for a set of keys to cache
*
* @param array $keys list of values to save
* @param int $expire expiration time
* @return boolean true on success, false on failure
*/
protected function write(array $keys, $expire=null)
{
return wincache_ucache_set(array_keys($keys), array_values($keys), $expire);
}
/**
* Remove values from cache
*
* @param array $keys list of keys to delete
* @return boolean true on success, false on failure
*/
protected function delete(array $keys)
{
return wincache_ucache_delete($keys);
}
/**
* Remove *all* values from cache
*
* @return boolean true on success, false on failure
*/
protected function purge()
{
return wincache_ucache_clear();
}
}
|
|
|
Back to top |
|
|