Posted on

Magento 2 too Slow on Windows without SSD

Anyone who has started development on Magento 2 platform or those who have turned to Magento 2 and still date developing applications on Magento 1 software might faced one issue which is rather critical on windows machines.

Magento 2 is too slow on Windows systems if you are not using a Solid State Drive aka SSD. The reason is – in the background Magento generates a lot of dynamic content on disk which leads to a lot of disk write and read operations. In all modern computers, the disk is the slowest component if it is not an SSD.

So, what can you do to improve the performance of Magento at the same time running on ‘developer’ mode to develop Magento e-commerce applications, customization or module development. Well, if you have plenty of RAM available, you may use it to store cache and session data to speed up the development at some extent. Using main memory (RAM) instead of disk makes the routine operations like cache purging quick.

For utilizing the additional RAM, you may use some RAMDisk kind of utility, but it is very tedious process to install and takes a hell lot of time to implement. So, we shall use Redis (yes, Redis) on Windows machine to store cache and session data.

How to download and install Redis on Windows OS

Download Redis for windows from below URI and extract the zip archive.
https://github.com/ServiceStack/redis-windows/raw/master/downloads/redis-latest.zip

Enter into the directory and run redis-server.exe file in CMD of windows. You may configure memory and other parameters in the provided “conf” file.

To run Redis commands, redis-cli.exe utility is available. To shutdown the Redis server, press CTRL+C keys twice – it will gracefully shutdown Redis server and allows the state to be saved on the disk. So when you start it again the previous cache and session data will become available.

Now, configure Magento to use the Redis server. By default, Redis listens port 6379.

Open up app/etc/env.php and replace your ‘session’ array block by below parameters

'session' => 
  array (
    'save' => 'redis',
    'redis' => 
    array (
      'host' => '127.0.0.1',
      'port' => '6379',
      'password' => '',
      'timeout' => '2.5',
      'persistent_identifier' => '',
      'database' => '0',
      'compression_threshold' => '2048',
      'compression_library' => 'gzip',
      'log_level' => '1',
      'max_concurrency' => '6',
      'break_after_frontend' => '5',
      'break_after_adminhtml' => '30',
      'first_lifetime' => '600',
      'bot_first_lifetime' => '60',
      'bot_lifetime' => '7200',
      'disable_locking' => '0',
      'min_lifetime' => '60',
      'max_lifetime' => '2592000',
    ),
  ),

Then, replace/add your ‘cache’ array parameter by below snippet.

'cache' => 
  array (
    'frontend' => 
    array (
      'default' => 
      array (
        'backend' => 'Cm_Cache_Backend_Redis',
        'backend_options' => 
        array (
          'server' => '127.0.0.1',
          'port' => '6379',
          'persistent' => '',
          'database' => '1',
          'force_standalone' => '0',
          'connect_retries' => '1',
          'read_timeout' => '10',
          'automatic_cleaning_factor' => '0',
          'compress_data' => '0',
          'compress_tags' => '1',
          'compress_threshold' => '20480',
          'compression_lib' => 'gzip',
        ),
      ),
      'page_cache' => 
      array (
        'backend' => 'Cm_Cache_Backend_Redis',
        'backend_options' => 
        array (
          'server' => '127.0.0.1',
          'port' => '6379',
          'persistent' => '',
          'database' => '1',
          'force_standalone' => '0',
          'connect_retries' => '1',
          'read_timeout' => '10',
          'automatic_cleaning_factor' => '0',
          'compress_data' => '1',
          'compress_tags' => '1',
          'compress_threshold' => '20480',
          'compression_lib' => 'gzip',
        ),
      ),
    ),
  ),

Now, clear your caches by running below command.

php bin\magento cache:clean

Access your Magento application and see the difference in speed of accessing the pages as well as your development, too. 😉

Enjoy developing on Magento 2 software.

More Magento tricks you can find at https://awebtech.blogspot.com.