muneeb456 Posted April 26, 2013 Share Posted April 26, 2013 Hi, I've setup prestashop on my local dev machine with wampserver 2.2, php 5.3. Machine has 4GB of ram and i3 processor. When I try to browse my local site it takes 10-15 seconds for Smarty to generate the template files. When I enable caching it goes down to 5 seconds. However, I am debugging and developing so I need to disable caching for now. The template files are pretty much the default ones. Yet, they are still running so slow. Anybody have experience or suggestions on how can I speed up performance. I need to develop on my local machine, but the lag is very painful. Thanks, Muneeb Link to comment Share on other sites More sharing options...
Bill Dalton Posted April 26, 2013 Share Posted April 26, 2013 In prestashop\config\settings.inc.php Change define('_DB_SERVER_', 'localhost'); to define('_DB_SERVER_', '127.0.0.1'); Link to comment Share on other sites More sharing options...
muneeb456 Posted April 26, 2013 Author Share Posted April 26, 2013 Thanks for your response. I tried it. However, it does not affect the performance of smarty. Smarty is taking a very long time to compile and render product.tpl. The load time sometimes goes up to 30 seconds for the whole page. The same thing is much faster online on my webhost. Any other suggestions? Link to comment Share on other sites More sharing options...
Bill Dalton Posted April 27, 2013 Share Posted April 27, 2013 Have you installed FastCGI? http://wiki.ninjafocus.net/WAMP/FastCGI Also APC, http://blog.lardev.com/2011/07/06/install-apc-on-wamp-server/ Link to comment Share on other sites More sharing options...
Doulas Akula Posted April 27, 2013 Share Posted April 27, 2013 For me what I normally do is enable caching as I develop. However when I edit a template file I go to this directory (tools/smarty/compile/)and delete manually the compiled file corresponding to the file I edited. Its usually some hexadecimal like characters at the beginning though at the end the name of the file has similarity with the file I edited. E.g for product-list I normally delete this file 3917a7e29d3fc95a94c853a221acc78ea51ab199.file.product-list.tpl. This way my site does not have to regenerate all template files every time I reload. However if you are making changes in css files that affects a wide range of templates files,then this method may not be the best. I hope you find this useful in some later development cycle. 1 Link to comment Share on other sites More sharing options...
muneeb456 Posted April 29, 2013 Author Share Posted April 29, 2013 So, I ended up installing Zend Server with memcached... I had trouble with URL rewrites, so I had to turn that off for now, but at least it is now loading faster... 3-6 seconds instead of 10-15. @Bill, I tried for the longest time to set up FastCGI on wampserver, but it simply was not working. I searched online and read somewhere that wampserver installs the ts (thread-safe) version of php, whereas fastcgi only works with nts (non-thread-safe) version of php. Installing APC did not improve times much. @Doulas: thanks for the suggestion, I think I'll definitely use it! Link to comment Share on other sites More sharing options...
benjamin utterback Posted April 29, 2013 Share Posted April 29, 2013 Hi muneeb456, thank you for the explanation. I also read today that memcached had the best results of all caching options. However, I personally have seen APC speed a store dramatically as well. Link to comment Share on other sites More sharing options...
Bill Dalton Posted April 29, 2013 Share Posted April 29, 2013 muneeb456, is this just a default install of Prestashop, or have you loaded the database with thousands of products? Here is a default install on a windows box and just the built in cache, fastcgi, and IIS with WinCache, http://bdalton.ca/en/ It's fast. Link to comment Share on other sites More sharing options...
muneeb456 Posted April 29, 2013 Author Share Posted April 29, 2013 Yeah, I added about 2500 products. However, I was not expecting Smarty to slow down page rendering just because of the number of products in the database. However, I am open to moving the list of products to a new setup. Can you guide me how I can set up something like the one you sent me? Link to comment Share on other sites More sharing options...
benjamin utterback Posted April 29, 2013 Share Posted April 29, 2013 muneeb456, is this just a default install of Prestashop, or have you loaded the database with thousands of products? Here is a default install on a windows box and just the built in cache, fastcgi, and IIS with WinCache, http://bdalton.ca/en/ It's fast. That is fast. Thanks for the share. Link to comment Share on other sites More sharing options...
Bill Dalton Posted April 29, 2013 Share Posted April 29, 2013 muneeb456, I would make a backup of your database. Then I would just leave your current setup as is. I think you should create a new directory and add a new database and make an additional install of another copy of Prestshop and lets take a look at the speed of it on that box with just the default data and theme. Might give us some insight into your current environment. I'd also remove memcached. That sort of software is great for somethings but can just get in the way in the beginning. Link to comment Share on other sites More sharing options...
muneeb456 Posted April 29, 2013 Author Share Posted April 29, 2013 Bill, I set up a brand new setup of Prestashop with default data and theme as you said. This one's much faster....around 1 second, and often faster... without any caching. (btw, I'm back on wampserver. Zend server was giving some more issues, so I gave up.) What could be causing the dramatic difference between this and the other setup (which has default theme, but many products) Config details: Server information: Windows NT build 7601 (Windows 7 Home Premium Edition Service Pack 1) i586 Server software version: Apache/2.2.22 (Win32) PHP/5.3.13 PHP version: 5.3.13 Memory limit: 512M Max execution time: 60 Database information MySQL version: 5.5.24-log MySQL engine: InnoDB Tables prefix: ps_ Store information PrestaShop version: 1.5.4.0 Shop URL: http://newalbalagh.com/prestashop3/ Current theme in use: default Mail configuration Mail method: You are using the PHP mail function. Your information Your web browser: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31 Link to comment Share on other sites More sharing options...
Bill Dalton Posted April 30, 2013 Share Posted April 30, 2013 You should now import your backup sql file into the new database. Lets see if we get the same level of "slow". If so we will know it's a mySQL problem and we can work on that. Link to comment Share on other sites More sharing options...
muneeb456 Posted April 30, 2013 Author Share Posted April 30, 2013 Hmm, I imported my SQL data and my modified files. I now have two versions of Prestashop.. the old one still takes about 6 seconds to load. The new one is now doing about 2-3 seconds. Still slower than the default setup, but faster than the old one. Link to comment Share on other sites More sharing options...
Bill Dalton Posted April 30, 2013 Share Posted April 30, 2013 Did you make sure to change local host to 127.0.0.1 ? Very important on Windows. There is a know bug in Windows with resolving to localhost. Link to comment Share on other sites More sharing options...
muneeb456 Posted April 30, 2013 Author Share Posted April 30, 2013 I have localhost in the hosts file set to point to 127.0.0.1. I'm also using a TLD otherwise (newalbalagh.com) and have it pointing to 127.0.0.1 as well. Either way, the time is the same (whether I point _DB_SERVER_ to localhost or 127.0.0.1) Anyways, while continuing my investigation: I figured out some causes that might be slowing it down. I have >250 manufacturers. I checked the code that was populating blockmanufacturers, and it turned out to be very inefficient (creating a new object for each manufacturer before spitting out the link)... taking more than 1 second in the PHP code before passing it to smarty which would take 0.1 seconds to render the block... I crunched that code, and that sped up things quite a bit. I also have another list ("authors") which had > 500 members. It was taking even longer due to the same reasons. After making these changes, I am down to about 3 seconds on the first load attempt and 1.5 seconds on the second. So, it seems like we are making progress... Thanks for all your help. Link to comment Share on other sites More sharing options...
muneeb456 Posted April 30, 2013 Author Share Posted April 30, 2013 Now, I'm noticing that the Debug console shows a certain time at the top of the window, and shows timings for the include template and config files. However, they don't add up to the time shown at the top. e.g. top shows 2.64269 seconds, but the sum total of all the times below is just 0.42716 seconds... what is taking up the remaining time? I've attached a sample result of the console below: Smarty Debug Console - Total Time 2.64269 included templates & config files (load time in seconds) C:\wamp\www\prestashop3\modules\favoriteproducts\views\templates\hook\favoriteproducts-header.tpl(compile 0.00000) (render 0.00156) (cache 0.00000) C:\wamp\www\prestashop3\modules\feeder\feederHeader.tpl (compile 0.00000) (render 0.00180) (cache 0.00000) C:\wamp\www\prestashop3\modules\blocklanguages\blocklanguages.tpl (compile 0.00000) (render 0.00148) (cache 0.00000) C:\wamp\www\prestashop3\modules\blockcurrencies\blockcurrencies.tpl (compile 0.00000) (render 0.00166) (cache 0.00000) C:\wamp\www\prestashop3\modules\blockpermanentlinks\blockpermanentlinks-header.tpl (compile 0.00000) (render 0.00000) (cache 0.00096) C:\wamp\www\prestashop3\modules\blocksearch\blocksearch-top.tpl (compile 0.00000) (render 0.00000) (cache 0.00116) C:\wamp\www\prestashop3\modules\blockuserinfo\blockuserinfo.tpl (compile 0.00000) (render 0.00423) (cache 0.00000) C:\wamp\www\prestashop3\modules\blocktopmenu\blocktopmenu.tpl (compile 0.00000) (render 0.00092) (cache 0.01375) C:\wamp\www\prestashop3\themes\default\modules\blockcart\blockcart.tpl (compile 0.00000) (render 0.00570) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\modules\blockcategories\blockcategories.tpl (compile 0.00000) (render 0.05582) (cache 0.01514) C:\wamp\www\prestashop3\themes\default\modules\blockcategories\category-tree-branch.tpl (compile 0.00000) (render 0.05651) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\modules\blockviewed\blockviewed.tpl (compile 0.00000) (render 0.00422) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\modules\blockmanufacturer\blockmanufacturer.tpl (compile 0.00000) (render 0.03096) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\modules\blockcms\blockcms.tpl (compile 0.00000) (render 0.00532) (cache 0.00000) C:\wamp\www\prestashop3\modules\blockadvertising\blockadvertising.tpl (compile 0.00000) (render 0.00000) (cache 0.00089) C:\wamp\www\prestashop3\themes\default\modules\blocknewsletter\blocknewsletter.tpl (compile 0.00000) (render 0.00000) (cache 0.00087) C:\wamp\www\prestashop3\modules\blockwriter\blockwriter.tpl (compile 0.00000) (render 0.02740) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\modules\blockbestsellers\blockbestsellers.tpl (compile 0.00000) (render 0.00274) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\modules\blockspecials\blockspecials.tpl (compile 0.00000) (render 0.00287) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\modules\blockcontact\blockcontact.tpl (compile 0.00000) (render 0.00000) (cache 0.00095) C:\wamp\www\prestashop3\modules\blockreinsurance\blockreinsurance.tpl (compile 0.00000) (render 0.00000) (cache 0.00086) C:\wamp\www\prestashop3\themes\default\modules\blockcategories\blockcategories_footer.tpl (compile 0.00000) (render 0.05222) (cache 0.04473) C:\wamp\www\prestashop3\themes\default\modules\blockmyaccountfooter\blockmyaccountfooter.tpl(compile 0.00000) (render 0.00000) (cache 0.00119) C:\wamp\www\prestashop3\themes\default\modules\blocksocial\blocksocial.tpl (compile 0.00000) (render 0.00000) (cache 0.00099) C:\wamp\www\prestashop3\themes\default\modules\blockcontactinfos\blockcontactinfos.tpl (compile 0.00000) (render 0.00000) (cache 0.00077) C:\wamp\www\prestashop3\themes\default\category.tpl (compile 0.00000) (render 0.06518) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\breadcrumb.tpl (compile 0.00000) (render 0.00147) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\errors.tpl (compile 0.00000) (render 0.00070) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\category-count.tpl (compile 0.00000) (render 0.00094) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\pagination.tpl (compile 0.00000) (render 0.01105) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\product-sort.tpl (compile 0.00000) (render 0.00261) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\product-compare.tpl (compile 0.00000) (render 0.00320) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\nbr-product-page.tpl (compile 0.00000) (render 0.00434) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\product-list.tpl (compile 0.00000) (render 0.02240) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\layout.tpl (compile 0.00000) (render 0.00890) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\header.tpl (compile 0.00000) (render 0.00162) (cache 0.00000) C:\wamp\www\prestashop3\themes\default\footer.tpl (compile 0.00000) (render 0.00125) (cache 0.00000) 1 Link to comment Share on other sites More sharing options...
Bill Dalton Posted April 30, 2013 Share Posted April 30, 2013 >>I crunched that code, and that sped up things quite a bit. You are way ahead of me. At best I could have suggested increasing your database cache. You are able to rewrite the actual query! Good stuff. I never worried to much about the tpl files. I assumed that after they compile they are cached with the rest of my static content. If you have the knowledge to optimize SQL queries, you are way ahead of the average user. I hope you keep posting in this thread as you move forward over the next few days. I for one am really interested in learning new tricks to speed things up. Link to comment Share on other sites More sharing options...
muneeb456 Posted April 30, 2013 Author Share Posted April 30, 2013 Thanks for the compliment. Appreciate your patience with me. I actually did not optimize the SQL query (in Manufacturer::getManufacturers()). The greatest slow down was in blockmanufacturer.tpl's repeated call to $link->getmanufacturerLink(): {foreach from=$manufacturers item=manufacturer} <option value="{$link->getmanufacturerLink($manufacturer.id_manufacturer, $manufacturer.link_rewrite)}">{$manufacturer.name|truncate:40|escape:'htmlall':'UTF-8'}</option> {/foreach} I looked up the code for getManufacturerLink in Link.php: public function getManufacturerLink($manufacturer, $alias = null, $id_lang = null) { if (!$id_lang) $id_lang = Context::getContext()->language->id; $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang); if (!is_object($manufacturer)) $manufacturer = new Manufacturer($manufacturer, $id_lang); // Set available keywords $params = array(); $params['id'] = $manufacturer->id; $params['rewrite'] = (!$alias) ? $manufacturer->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($manufacturer->meta_keywords); $params['meta_title'] = Tools::str2url($manufacturer->meta_title); return $url.Dispatcher::getInstance()->createUrl('manufacturer_rule', $id_lang, $params, $this->allow); } As you can see, it generates a new object for each manufacturer, if $manufacturer represents an id instead of a manufacturer object. That may be fine if we are dealing with one manufacturer object. But, when iterating over a list of hundreds, it slows things down. Now, if you are using the default link rewrite rule for manufacturers, it turns out that we don't really need the meta_keywords and meta_title. Thus, we only need the id_manufacturer and link_rewrite, both of which the code in the template already provided to the function: {$link->getmanufacturerLink($manufacturer.id_manufacturer, $manufacturer.link_rewrite)} Thus, we have no need to generate a new Manufacturer object, if both the id and link_rewrite have been provided. So, I overrode getManufacturerLink() to the following: public function getManufacturerLink($manufacturer, $alias = null, $id_lang = null) { if (!$id_lang) $id_lang = Context::getContext()->language->id; $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang); $params = array(); if (!is_object($manufacturer) && !$alias) { $manufacturer = new Manufacturer($manufacturer, $id_lang); $params['id'] = $manufacturer->id; } else { if (is_object($manufacturer)) $params['id'] = $manufacturer->id; else $params['id'] = $manufacturer; } $params['rewrite'] = (!$alias) ? $manufacturer->link_rewrite : $alias; return $url.Dispatcher::getInstance()->createUrl('manufacturer_rule', $id_lang, $params, $this->allow); } That sped up things quite a bit. 1 Link to comment Share on other sites More sharing options...
muneeb456 Posted April 30, 2013 Author Share Posted April 30, 2013 Any insight on the question about the difference in the timings displayed in the debug console for smarty? Link to comment Share on other sites More sharing options...
Bill Dalton Posted April 30, 2013 Share Posted April 30, 2013 >>I actually did not optimize the SQL >>I overrode getManufacturerLink() :)Even better! I've no idea why Smarty debug is reporting an incorrect time. Hopefully someone else can help us out with that. You mention that when you imported the data you also added the modified files. Can you break that up into steps ... I do like the logic you applied to getManufacturerLink(). Thanks for sharing. Link to comment Share on other sites More sharing options...
muneeb456 Posted April 30, 2013 Author Share Posted April 30, 2013 Sorry, by modified files, I meant files that I had modified from the base code for my needs. I.e. some class overrides, etc. Link to comment Share on other sites More sharing options...
muneeb456 Posted April 30, 2013 Author Share Posted April 30, 2013 I just discovered this thread http://www.prestashop.com/forums/topic/176681-slow-blockcategoriestpl/. Applied it to blockmanufacturers and blocktopmenu along with my own blockwriters and time has decreased further to 1-1.5 seconds. Link to comment Share on other sites More sharing options...
Bill Dalton Posted May 1, 2013 Share Posted May 1, 2013 Good find. That thread started last summer when I was away. Missed it. I haven't given it a go yet, but I will. My main way until this thread was to cure the problem with faster hardware. The couple of sites I'm working on also are very small so the need for this type of tweaking isn't front and center for me. But I love to learn new tricks and I think you just found a great one. This should help a lot of people. Link to comment Share on other sites More sharing options...
Recommended Posts