Tăng tốc cho magento - Ai bảo magento chậm?

Thảo luận trong 'Magento optimization' bắt đầu bởi trihungpc, 24 Tháng bảy 2013.

  1. trihungpc

    trihungpc Member

    Hôm nay buồn ngồi nghịch linh tinh. Thực sự mình hơi bất ngờ về tốc độ sau khi tối ưu. Các bác có thể xem demo http://trihung.com

    Mình test bằng SEO doctor tốc độ là 1.3s :D

    Mọi người cùng tham khảo nhé:

    A) Hosting environment/ General tips

    1. Get a dedicated server.
    2. Host your site in the country where your customers are.
    3. Don’t host files on your web server that you do not use, large or small.
    4. Goto MySQL Admin and select all the tables and repair and then optimize them.
    5. Use a PHP accelerator like APC, ZendOptimizer+ or Xcache.
    6. Only install necessary Apache modules.
    7. Use Apache mod_expires and be sure to set how long files should be cached. You could use the example below for your Apache virtualhost config:
      # Turn on Expires and set default to 0
      ExpiresActive On
      ExpiresDefault A0

      # Set up caching on media files for 1 year (forever?)

      ExpiresDefault A29030400
      Header append Cache-Control "public"

      # Set up caching on media files for 2 weeks

      ExpiresDefault A1209600
      Header append Cache-Control "public"

      # Set up 1 week caching on commonly updated files

      ExpiresDefault A604800
      Header append Cache-Control "proxy-revalidate"

      # Force no caching for dynamic files

      ExpiresActive Off
      Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
      Header set Pragma "no-cache"
    8. Enable Gzip Compression in htaccess.
    9. Compress output, use zlib.output_compression or mod_deflate.
    10. Use a Content Delivery Network (CDN) for parallel transfer of static content. There is a Magento extension that can help you do this with category and product images: the One Pica Image CDN. But… (see next tip).
    11. Don’t use too many different external sources (for images, iframes, (twitter/facebook)feeds etc.) because every DNS lookup takes extra time and you create an extra dependancy (on some 3rd party server) for your site to load properly.
    12. Enable Apache KeepAlives: Make sure your Apache configuration has KeepAlives enabled. KeepAlives are a trick where multiple HTTP requests can be funneled through a single TCP connection. The setup of each TCP connection incurs additional time, this can significantly reduce the time it takes to download all the files (HTML, JavaScript, images) for a website. More info at Apache.org. Be carefull though, I’ve heard from some that this create (a lot of) extra load on the server and might crash the server on high traffic moments!
    13. Minimize redirects.
    14. Make your output W3C compliant. Errors slow down the browser.
    15. Swap Apache for NginX or Litespeed. If this isn’t an option, then go for Zend Server (ideally the non-CE version so you can use full page caching).
    16. Turn off or at least reduce web server logging (reduces disk writes).
      • Disable Access Time Logging. Magento Wiki: For Linux servers, if you have access-time logging enabled on any of your mysql, web server or cache partitions, try turning it off for a performance boost. If you’re using ext3 or reiserfs there may be faster journal write methods you can use. For more info see Linux.com.
    17. Compile MySQL from source instead of your OS’s package manager.
    18. Always upgrade to the latest Magento version. Not only will you get more features and bug- and security fixes, but with every update Magento performs better.
    19. Query Cach size: Magento Blog: Modify the configuration for your MySQL server to take better advantage of your server’s RAM. Most Linux distributions provide a conservative MySQL package out of the box to ensure it will run on a wide array of hardware configurations. If you have ample RAM (eg, 1gb or more), then you may want to try tweaking the configuration. An example my.cnf is below, though you will want to consult the MySQL documentation for a complete list of configuration directives and recommended settings.
    20. set ‘php_value memory_limit 128M’ in your php configuration or add it to your .htaccess file to ensure you don’t run out of memory.
    21. Use a memory-based filesystem for dynamic data. If you store dynamic data (var/cache, var/session) on RAMdisk or tmpfs, the disk I/O is decreased.
    22. Change realpath_cache_size in php.ini.
      realpath_cache_size=1M (careful, this is per apache process) realpath_cache_ttl=86400 (ok for production site)
    23. Memcache (for the hardcore) is documented in http://www.magentocommerce.com/boards/viewthread/9037/ and more tips from http://alexle.net/archives/275 to get you up and running.
    24. Disable the PHP open_basedir directive. Read this.
    25. Eliminate directory structure scans for .htaccess files.
    26. Recommended innodb_buffer_pool_size.
      • Combined web and db server, 6 GB RAM: 2-3 GB
      • Dedicated database server, 6GB RAM: 5 GB
      • Dedicated database server, 12 GB RAM: 10 GB
    27. innodb_thread_concurrency.
      • 2 * [numberofCPUs] + 2
    28. Query Cach: query_cache_size: 64MB, query_cache_limit: 2MB
    29. Use sa seperate backend server to handle admin users, process backend activity (cron), pre generate full page caching and to handle media queries.
    30. Use multiple web nodes (frontend servers) to handle browsing and checkout.
    31. Use Varnish reverse proxy caching, Magento explanation by @alistairstead: Varnish your Magento store, make it fly!.
    32. If you have a popular site that is heavily crawled by searchengines, you can save some resources by tweaking your robots.txt.
    33. Try some of these cache extensions:
  2. trihungpc

    trihungpc Member

    B) Template

    1. Optimize all your (template) images- Most if not all should be at least below 10kb.
      • Crop the white space using your image editor.
      • Use PNG8 Files or GIF files rather than Jpegs and don’t use transparency (depending on how many colors you use and how large the image is, but try for yourself).
      • Scale images: make images in the dimensions you need and not resizing them in the editor.
      • Use image compression (you can use smush.it to do it for you).
      • Use CSS Sprites, there even are CSS Sprite Generators.
    2. Minify your Css, remove unused code.
    3. Minimize Javascript use.
    4. Use a lightweight template as a basis for your template. For example: the Yoast Blank SEO theme.
    5. Specify Image dimensions.
    6. Use Block cache and HTML output in your extensions.
    7. Apply Javascript Lazy Loader for prototype.
    C) Magento configuration

    1. Uninstall any extensions that you don’t actually use.
    2. Disable modules that you don’t use: System -> Configuration -> Advanced -> Advanced.
      This is an example setting
    3. Enable all Magento Caches: System -> Cache Management.
    4. Use an offsite Stats Tracker like Google Analytics and not an onsite one. Most of this will use Javascript, host the Javascript yourself.
    5. Combine Javascript and Combine CSS files: System ->Configuration ->Advanced ->Developer -> ‘Javascript settings’ and ‘CSS Settings’. You can also consider using an extensions to do this like the Fooman Speedster extension, whichever works best for you.
    6. Try some of the Magento performance extensions.
    7. Enable the Magento Flat Catalog, only helpful for very large catalogs to feel the improvements.
    8. Don’t use layered navigation if you don’t really need it, it’s resource intensive.
    9. Use Magento’s Compilation feature. It’s reported to give you a 25%-50% performance boost: System > Tools > Compilation.
      Edit: Yoav Kutner (Magento CTO) let me know that “in later versions since we optimized the catalog EAV, Magento Compilation is not really needed if you have byte code caching and if it is configured correctly“.
    10. Use the correct session storage, choose file system or database (during setup). Most installations should use “file system” because it’s faster and doesn’t cause the database to grow. But if your site will run on multiple servers, you should select “database” so that a user’s session data is available regardless of which server his/her request is served from. More info about this from Ashley Schroder at Magebase.com.
    11. Limit the number of products on a product overview page.
    12. Set only those attribute frontend properties to ‘Yes’ that you’re actually going to use. Set all other to ‘No’. Don’t use in quick search, advanced search compare, etc etc.: Catalog -> Attributes -> Manage Atributes -> Frontend Properties.
    13. Disable the Magento log: System -> Configuration -> Advanced -> Developer -> Log Settings (default is disabled).
    Enterprise only tip:
    • Disable Enterprise_CatalogEvent. Go to Admin -> System -> Configuration -> Catalog -> Catalog Events.
      Then you want to turn off the settings for “Enable Catalog Events Functionality” and “Enable Catalog Event Widget”.
    • Enable Solr search, it’s quicker compared to the default setup, especially when you have lots of products (>10k).
    • Enable Full Page Caching.
    D) Speed testing, analysing, monitoring

    1. Test your Magento site with Magento Speed Test (by Ashley Schroder)
    2. Run your site through websiteoptimization.com.
    3. Use Google Page Speed Firefox extension or Yahoo Yslow for some tips from Google and Yahoo.
    4. Implement Google Speed measurements in Analytics: Measure Page Load Time with Site Speed Analytics Report
    5. Speed monitoring and downtime alerts.
      • Mon.itor.us
      • Pingdom
    Bonus Tips

    (because it doesn’t actually speed up the frontend but only the backend):
    • Use K-Meleon if you are on Windows for your general Admin work. It renders Magento’s heavy JS back-end significantly faster than any other browser.
    • Use the GoogleGears extension from Yireo.com to cache static files locally.
    • Use a local pc/mac application to manage Magento (like mag-manager.com).
    I do realize that you probably can’t use all of the above tips but it’s not about using them all, and sometimes you just make the choice to give a functionality a priority over performance and that’s OK. If you can only apply some of them you will still increase speed and gain in user experience. And remember: because speed depends on many variables, some of the tips might not have an impact on your website at all while others can have a huge impact. So always test the impact of every step you take and take actions accordingly.
    Nguyen Thien An thích bài này.
  3. admin

    admin Mai Văn Hải Staff Member

    Chuẩn đấy.

    Note: các anh em cẩn thận khi dùng chức năng Magento’s Compilation nhé.

    Các cách con lại thì hoàn toàn do quá trình code và config hệ thống

    Note bác Hưng: http://trihung.com/gia-dung.html để chống link gãy bác remove .html cho catalog đi, website của bác sẽ rất good đấy.
    trihungpc thích bài này.
  4. Nguyen Thien An

    Nguyen Thien An New Member

    @admin: admin có thể vui lòng nói rõ hơn được không? (sẽ có lỗi hay thế nào mà phải cẩn thận?)
  5. hoang van dong

    hoang van dong New Member

    Bác nào có thể hướng dẫn phần 5 Use a PHP accelerator like APC, ZendOptimizer+ or Xcache chi tiết được không nhỉ, có hình ảnh càng tốt, @_@
  6. hoangtrungnqt

    hoangtrungnqt New Member

    Tôi có dùng tính năng này thì bị lỗi cả site luôn. Không biết lý do gì.
  7. ktgroup

    ktgroup New Member

    Các cao thủ ở đây có ai viết lại API của magento cho nó chạy nhanh hơn không?
    Có bác nào rảnh em mời 1 buổi cafe ạ.
  8. thankiemvdk

    thankiemvdk New Member

    Đang học hỏi ... mò mẫm, site của mình chậm quá
    nammdp thích bài này.
  9. Ngô Ngọc Đức

    Ngô Ngọc Đức New Member

    Nếu có hướng dẫn cụ thể thì hay quá...;)
  10. diaochado

    diaochado New Member

    đặt gạch cái đã, nghiên cứu sau vậy
  11. nammdp

    nammdp New Member

    site sanhangre của bác dùng theme nào thế ?đẹp quá.
  12. vantienart

    vantienart New Member

    Em cũng đang tìm cách cho nó nhanh hơn, nhiều lúc vào vẫn còn chậm quá
  13. pvd276

    pvd276 Member

    Lâu k thấy bác trí hưng vào chia sẻ ,site của bác ấy nhanh kinh
  14. admin

    admin Mai Văn Hải Staff Member

    chắc kiếm tiền bội rồi, lo đếm tiền hết time để share cho anh em...
  15. vantienart

    vantienart New Member

    Thật tuyệt vời, sau khi tối ưu thì web của mình test bằng SEO doctor tốc độ là 1.5s
  16. hoangbb

    hoangbb New Member

    hic, em cũng đang làm một web bằng magento này mà sao nó chạy chậm quá. Đọc trên này thấy chỉ cách làm web nhanh hơn nhưng thú thật là không biết làm theo làm sao, nếu ai đó chỉ dẫn cách làm từng cái thì xin cám ơn nhiều. Đã chỉ thì xin anh chị chỉ chi tiết giúp luôn, chứ như thế này em không biết làm sao. Xin cám ơn nhiều.
  17. admin

    admin Mai Văn Hải Staff Member

    Hoangbb đã biết những gì rồi: SSH, PHP, CSS, HTML, cấu trúc magento, cách gọi file trong Magento>
  18. vantienart

    vantienart New Member

    Mình nghĩ bác đấy cũng mới vào nghề nên nhiều cái còn tơ lơ mơ. Thôi thì bác cứ từ từ tìm hiểu đi chứ bài viết cũng khá chi tiết rồi mà
  19. hoangbb

    hoangbb New Member

    Hic, em chưa biết gì nhiều cả.
    Em làm theo phần B, C, D thì cũng làm được nhiều thứ, nhưng phần A thì em không biết làm theo thế nào. Hiện web em mới được 35/100 theo như chấm điểm của google đó anh. Trong phần A nên làm cái gì quan trọng để nó tăng tốc vậy anh.
    Cám ơn anh Hải nhiều.
    Cám ơn anh Tiến, em đúng là lơ tơ mơ anh à, nhờ anh chỉ giúp chứ em không biết làm thế nào ạ.
  20. admin

    admin Mai Văn Hải Staff Member

    Phần A là công việc của system, developer ko biết là phải.
    Bạn tìm hiểu thêm về system nhé

Chia sẻ trang này