Redis vs MySQL Benchmarks

Redis vs MySQL Benchmarks

In this article, we would be discussing the performance benchmarks of Redis and MySQL. To begin with, we would start with the introduction and installation of Redis over Ubuntu Machine. Then we would move towards the benchmarking between these two.

In this article, we would be discussing the performance benchmarks of Redis and MySQL. To begin with, we would start with the introduction and installation of Redis over Ubuntu Machine. Then we would move towards the benchmarking between these two.

Table of Contents

  • Introduction to Redis
  • Prerequisites
  • Installation of Redis over Ubuntu
Introduction to Redis:

According to the official website, Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. Actually, Redis is an advanced key-value store. It is literally super fast with amazingly high throughput as it can perform approximately 110000 SETs per second, about 81000 GETs per second. It also supports a very rich set of data types to store. As a matter of fact, Redis keeps the data in-memory every time but also persistent on-disk database. So, it comes with a trade-off: Amazing speed with the size limit on datasets (as per memory). In this article, to have some benchmarks in comparison to MySQL, we would be using Redis as a caching engine only.

Prerequisites: Installation of Redis over Ubuntu:

In this section, we would be discussing the steps required to install/configure the Redis over ubuntu machine. Here is the stepwise approach for this:

Installation and Configuration of Redis over Ubuntu:

To start with, run the following commands:

 sudo apt update  
 sudo apt install redis-server  

These commands would update the apt package and install the Redis over your Ubuntu machine.

Now, As a matter of fact, to enable Redis being used as a Service, you need to configure it by updating the supervised directive present inside the configuration file of Redis. You can easily find the configuration file here:

 sudo vi /etc/redis/redis.conf  

By default, the supervised directive is set to "no". You need to set it to: systemd . After updating, this section of configuration file would look like something similar to this:

 ################################# GENERAL #####################################  
 # By default Redis does not run as a daemon. Use 'yes' if you need it.  
 # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.  
 daemonize yes  
 # If you run Redis from upstart or systemd, Redis can interact with your  
 # supervision tree. Options:  
 #  supervised no   - no supervision interaction  
 #  supervised upstart - signal upstart by putting Redis into SIGSTOP mode  
 #  supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET  
 #  supervised auto  - detect upstart or systemd method based on  
 #            UPSTART_JOB or NOTIFY_SOCKET environment variables  
 # Note: these supervision methods only signal "process is ready."  
 #    They do not enable continuous liveness pings back to your supervisor.  
 supervised systemd  
 # If a pid file is specified, Redis writes it where specified at startup  
 # and removes it at exit.  
 #  
 # When the server runs non daemonized, no pid file is created if none is  
 # specified in the configuration. When the server is daemonized, the pid file  
 # is used even if not specified, defaulting to "/var/run/redis.pid".  
 #  
 # Creating a pid file is best effort: if Redis is not able to create it  
 # nothing bad happens, the server will start and run normally.  
 pidfile /var/run/redis/redis-server.pid  
 # Specify the server verbosity level.  
 # This can be one of:  
 # debug (a lot of information, useful for development/testing)  
 # verbose (many rarely useful info, but not a mess like the debug level)  
 # notice (moderately verbose, what you want in production probably)  

Save this file now and to have the changes reflected over Redis, restart the Redis Service by using the following command:

 sudo systemctl restart redis.service  

Enabling Password Authentication:

Configuring the Redis with password authentication is not mandatory though, but it is super important (and easy too) as it enables the security factor over Redis. Configuring our Redis server with the password is super easy and can be done through the same configuration file as mentioned above. So, open the configuration file and look for *requirepass *directive. You would that line is commented by default, just uncomment that and enter your password there. The configuration file would look similar to this:

 # Require clients to issue AUTH  before processing any other  
 # commands. This might be useful in environments in which you do not trust  
 # others with access to the host running redis-server.  
 #  
 # This should stay commented out for backward compatibility and because most  
 # people do not need auth (e.g. they run their own servers).  
 #  
 # Warning: since Redis is pretty fast an outside user can try up to  
 # 150k passwords per second against a good box. This means that you should  
 # use a very strong password otherwise it will be very easy to break.  
 requirepass yourpasswordhere  
 # Command renaming.  
 #  
 # It is possible to change the name of dangerous commands in a shared  
 # environment. For instance the CONFIG command may be renamed into something  
 # hard to guess so that it will still be available for internal-use tools  
 # but not available for general clients.  
 #  
 # Example:  
 #  
 # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52  

Save this file now and to have the changes reflected over Redis, restart the Redis Service by using the following command:

 sudo systemctl restart redis.service  

Installation of PHPRedis over Ubuntu:

Now, to enable your PHP code to use Redis as a service:

 sudo apt-get install php-redis  

 extension=redis.so  

Workflow: Source Code:

MySQL Only Source Code :

(When we try to fetch key from MySQL only)

 <?php  
 $con = mysqli_connect("localhost","root","admin","blog_db");  
 for($i = 1; $i <= 10000000; $i = $i *10) {       
      $startTime = microtime(true);  
      for($j = 1; $j <= $i; $j++) {  
           $rand = rand(1, 100000);  
           $sql = "SELECT VALUE from data WHERE `key` = $rand";            
           if (!mysqli_query($con, $sql)) {  
             echo "Error: " . $sql . "" . mysqli_error($con);  
           }  
      }  
 $endTime = microtime(true);  
 file_put_contents('/home/ayush/Desktop/temp/blog/mysqlonly.log', $i . ',' . ($endTime - $startTime) . "\n" , FILE_APPEND);  
 }       

MySQL and Redis Source Code :

(When we try to fetch key from Redis first and then from MySQL if we are unable to find that key on Redis)

 <?php  
 $con = mysqli_connect("localhost","root","admin","blog_db");  
 $client = new Redis();  
 $client->connect('localhost');  
 for($i = 1; $i <= 10000000; $i = $i *10) {  
      $startTime = microtime(true);  
      for($j = 1; $j <= $i; $j++) {  
           $rand = rand(1, 100000);  
           if(!$client->exists($rand)) {  
                $client->set($rand, $rand);  
                $sql = "SELECT VALUE from data WHERE `key` = $rand";            
                if (!mysqli_query($con, $sql)) {  
                  echo "Error: " . $sql . "" . mysqli_error($con);  
                }  
           }   
      }  
      $endTime = microtime(true);  
      file_put_contents('/home/ayush/Desktop/temp/blog/redis.log', $i . ',' . ($endTime - $startTime) . "\n" , FILE_APPEND);  
      $client->flushAll();  
 }       

BenchMarks:

Tabular Data :

Graphical Representation :

Conclusion :

As it can be easily seen from graphical representation given above, as the number of requests increases significantly, Redis starts outperforming by a significant margin. Hence, using a caching engine like Redis along with your database is a good idea if the number of requests processed is huge.

PhP MySQL Projects

PhP MySQL Projects

Simpliv LLC, a platform for learning and teaching online courses. We basically focus on online learning which helps to learn business concepts, software technology to develop personal and professional goals through video library by recognized industry experts and trainers.

Description
PHP Projects in Urdu is a comprehensive course. It has five PHP projects in Urdu. Each project is created from scratch. You will get source code of each project as well. The list of 5 projects is as under:

Project 1: Find and Replace Application
Project 2: Building an Email Marketing Application
Project 3: Creating a Contact Form
Project 4: Building a Search Engine For Database
Project 5: Building a PHP Quiz Application
As this is an intermediate level course so it has some requisites as well

This is a Urdu/Hindi video course

Who this Course is for:

Anyone who wants to learn Web development
Who wants to become a PHP Developer
Basic knowledge
You must have basic knowledge about PHP and Mysql
You must be able to write HTML and CSS as well
What will you learn
How to Find and Replace Application
How to Build an Email Marketing Application
How to Create a Contact Form
How to Build a Search Engine For Database
How to Build a PHP Quiz Application
To continue:

The Complete PHP MySQL Professional Course with 5 Projects

The Complete PHP MySQL Professional Course with 5 Projects

The Complete PHP MySQL Professional Course with 5 Projects

Description
Have you ever wonder why their are so many PHP Mysql Courses but they offer very little practical skills. Sometimes its difficult for beginners to understand the long project right after learning basics due to lack of practice.Furthermore, big courses just give presentation to projects they never ever let students see their actual content. For example the basic videos, Free starter content etc. However this course is Scam-Free course. Students can watch more than 2 hour of initial content free of cost to decide weather to buy this course or not.

This course is designed in more logical way from easy to complex modules step by step. Here is description of the course

Road Map:

Building Blocks Fundamentals 5 Hour 30 mints of Content

Projects:

Regular Expressions 25 mints
Complete Contact Form + Email 1 Hour of Content
Dynamic Web Pages (Directory Project) 1 Hour of Content
CMS Based Employee Management CRUD 2 Hour + 30 minutes of Content
CMS + Admin Panel with Stunning blog + FREE Bootstrap 4.2.1 12 Hour of Content
This course will focus on all the Fundamentals , Building blocks and Advance Concepts of PHP in complete details which are essentials for beginners. In this Course students will build project after every section to see the real world representation of PHP.

Bonuses:

Getting Started with Bootstrap 4 FrameWork from scratch without using any Bootstrap Template
Latest Bootstrap 4.2.1 Essentials Practically in a Project
Using PHP Sessions in a more sophisticated way and pass information easily on different modules of Project
Full Coding Exercises
Login Logout Admin System
Tips / Tricks
Code Re-usability
Strong Security Techniques on Public Pages
PDO layer for Database Operations
Enhancing UI UX in admin Panel so that the Admin can manage the different Components of CMS / Blog easily
Enhancing UI UX in Public Panel so that the Public / Users can easily interact with the different Functionalities of Blog easily.
Using PHP Sessions in a more sophisticated way and pass information easily on different modules of Project
Login Logout Admin System
URL Tracking
Font Awesome
PHP 5.6 and 7 Supports
Admin Info Update
Now if you want to learn PHP and start your professional career, Take this course now

This course is for complete beginners and for those who want to build projects in PHP.

Who this course is for:

Complete Beginners
PHP Aspirants
Designers who want to Start Back-End Programming
College Students
Basic knowledge
No Knowledge required of PHP. This course will teach students everything about PHP from Scratch
Basic HTML
PC of-course :)
What will you learn
All PHP Fundamentals and Building Blocks with practical implementation in Projects
Form Validation with most Secure way using Regular Expressions
Making web pages dynamic with the variety of PHP Techniques
Employee Management System CRUD Application in PHP From Scartch
Complete CMS ( Content Management System) with Admin-Panel
Getting Started with Bootstrap 4 FrameWork from scratch without using any Bootstrap Template
Using PHP Sessions in a more sophisticated way and pass information easily on different modules of Project
Stunning Blog with Commenting functionality
Powerful Web Forms which will be Free of Hack
Build Professional CRUD
CMS Based Projects
Full Coding Exercises
Login Logout Admin System
Tips / Tricks
Sending Email using PHP
Bootstrap 4.2.1
PDO
URL Tracking
Security Techniques on Public pages
Font Awsome
To continue:

PHP Interview Questions with Solutions: Prepare for PHP Interview

PHP Interview Questions with Solutions: Prepare for PHP Interview

Prepare for PHP Interviews. Set Variable With php.ini File. Logic & Output Behind PHP Code Segment. Class Concept, Error & Functions in PHP. Start PHP Now!

Description
In this course you will be introduced with some tricky questions that everyone face during their interview. In each solutions I have included some useful functions which we generally use at the time of development also. I have covered the following area in my course with Questions, Attractive Presentations and Practical Solutions that will help you to understand the logic behind PHP in a different way.

Some useful functions
PHP error types
Class concept
Access specifiers public, private and protected
Set variable with php.ini file
Operators introduced in PHP7
Logic and its output behind some code segment
Basic knowledge
PHP7, XAMPP Server, Notepad++
What will you learn
This course is build for the person who is facing interviews. Every question is well explained with the practical solution through videos. So that everybody can prepare themselves for the tricky questions asked during interviews
To continue: