In this session we are going to learn about Benchmarking Performance. So since
we have already installed Redis on one of the machine.
So we will see what is the, you know, Read and Write performance which we are going to achieve.
And I will let you know how we are going to do that.
Okay.
So before that what I have done is, I have logged into a machine. So I have closed previous sessions and
I have opened a new session now and currently I am in /home/redisadmin directory.
So as you know to connect to rediscli, you need to type redis-cli
and since we have installed Redis server on Port 6 3 7 0. We also need to pass port explicitly by
specifying-p.
So once I do that I should be able to log into Redis server.
So what do you think?
Will I be able to log in to Redis Server?
Or will I be able to connect or not?
Let's check that.
So as you see again I have, I'm getting the error that Rediscli is not found.
OK.
As I told you in previous session that our Redis
Utilities are under, you know, here under src directory.
So in the previous session, we had also set up the path.
OK.
And then we were able to run Redis-server or Redis-cli or any utility, which is under src
directory. We were able to run that utilities from anywhere but now what has happened is since that command,
which we ran that is only in session specific.
OK.
So that path variable which we had set up that was only in session specific.
So when I closed that session and I opened a new session.
So whatever changes which were there, has actually gone because that was session specific.
So in this kind of situation what you need to do is, if you want to make that permanent, you actually go
to your Home Directory.
So the way to do that is cd space ~ and press enter.
So you'll be going back to your user's Home Directory.
Now here if you're using bash, you'll be having something like bash_profile.
it is not .bash-profile, it is .bash_profile. OK, you see I have this file which
actually exist.
So whenever you log into a server, any or using a bash cell.
So by default as soon as you log in, whatever is inside this file, an Operating System executes whatever
the command which you have put inside this file.
So what I will do is,
whatever command which we had ran previously, I will put that here.
OK.
So if you remember we had put
export PATH=$PATH and then we had put the complete path of until the source directory
So it was /home/redisadmin/redis-stable/src
OK.
So I'm not going to make any other changes. I have just added this line.
Now what it does is.
So when I log into
when basically I log into this user again, using any other Session than those a piece of code
which I put under .bash profile, that is going to be executed first.
So when I log in I'm going to feel like you know that the command has already been executed and I'll
be able to run Redis-server or Redis-cli utility directly.
So let's do that. Let's open a new shell.
So I'm going to Right Click and going to Duplicate Session.
okay.
By default I'm logged in with some other user. So, I will switch to the user, using which we have installed
Redis
okay.
Right now you can see I am into /home/redisadmin directory.
Now if I do redis-cli-p 6 3 7 0.
So now I am successfully able to connect to Redis server.
So now you know how to make your, you know whatever command you are running.
If you want to, if you put that into a .bash profile, that is going to be the first thing which
is going to be executed and then so basically whatever path you want to set you can put that there and
then that is going to be the first thing which is going to run and you will be able to run all the other
utilities, which is inside that path from anywhere or any directory
okay.
So, let's do Keys*
So we know these are the things which we have put there.
So I'm just exiting from here.
And yeah the way to do that is Exit and hit enter.
There's no ; required.
So right now we are in to Redis Admin Directory.
So if I go inside redis/stable/src and I do ls-lrt, you will also
notice
We have something called
redis-benchmark utility.
So this is a utility which you can use to benchmark performance in your environment. So the first thing
is you install Redis in the way which is going to be, you know, like production like and then you can run this Redis-
benchmark, to benchmark the performance.
So what it does is, it is going to execute a set of operations. Okay, using some Dummy Data and you can define
the set of operations you want to do or you can define the size of the data which you are going to read
or write and you can also define the number of Records which you want to read or write.
And based on that it will be able to let you know the Performance, which you are going to achieve from
this Redis instance.
OK.
So
let me go to this Documentation.
Now the easiest thing to do is, you can just run Redis benchmark using this command.
okay.
So
okay this is a previous session which which we had opened. So let me close this session.
This is not going to work here.
And yeah, let me come back here.
Okay.
So
what this going to do is, actually it is going to run Redis benchmark Utility with,in a q mode
And also it is going to pass 100000 records.
And based on that it is going to benchmark the performance ,which we are going to achieve.
So let's hit enter and let's try to understand what it is does.
All right.
So
right now it has actually given us Connection Refused Error.
The reason being is, that by default this utility also tries to connect to 6 3 7 9
port.
And since we have changed the Port. We should have also passed Port explicitly.
So I'm going to run this command like this.
And also let's say, if you want to pass the host name. You can actually do -h pass the host
name.
So if your, you know, Redis is running on some other server, you can use -h to give the Host Name and
then -p to give the Port Name and then Hit enter. Okay, so you can see this is running and what
it is doing is, all the set of commands which are available under Ping, it is actually, which are
actually available under Redis. It is running those commands and trying to show us the, you know, number which
we are achieving
So these are the different commands which are available in Redis.
OK.
So we can perform Set operation, we can perform Get operation, we can perform Increment operation, we
can perform Left Push operation, we can perform Right Push operation.
So what this utility is doing is, it is running all of these different set of commands and it is running
on 100000 records and then it is telling us the performance which we are going to achieve.
So basically in the Set.
Command or
that is the way to write anything or any Key Value appear in the Redis database.
So we are achieving something around 42000 request per second. Okay.
So again considering the resources which I have, this is very High Performance, which I am able to get.
So just to show you if I run free -h Command. This is the number of RAM which is available right
now on my machine.
OK.
So you can see this machine is actually having only total 3.5 GB of RAM, out of which
1.9 GB is already used and free is only 548 MB
So if your machine is actually a Production like machine. So you are going to achieve more number of you know,
Reads or Writes or other Operations Performance.
So whenever you install Redis in your environment, you can use Redis benchmark utility to test this. OK.
Now let's say we want to change these parameters and we know that each record or each key value pair
in our case is going to be of N number of Bytes.
OK.
So we can simulate that as well.
So the way to do that is
OK.
So just follow this Document
Actually you'll be able to understand.
Now if I come here and if I see this command Redis-benchmark.
or probably you can go back to, you know, in the beginning and here you can see
there is something called, -d parameter.
And using this I can specify the date size of Set and Get Value in Bytes.
So basically what I am telling is, telling to Redis is that each record is going to be of these many bytes.
OK so let me run this one
and lets say i am telling Redis that each of my record is going to be of
10 bytes.
OK.
So that's the way I do it.
So you specify -d, followed by space and followed by the number of bytes. So 10 is going to be 10 bytes
so by default it runs with 2 bytes. So previous operation which we have ran it, using default
number. So which means, it was assuming that the byte or total number of bytes which going to be in each
record is 2 bytes.
Okay.
So now let's run this. Hit enter.
OK.
So basically it is going to run the same way, which it ran previously and going to show us the
number.
So I do not see any significant change, you know, by changing the number from 2 bytes to 10 bytes, in
my case.
But once you have a real number. Let's say you have a real size of your Key Value Pair. That can be probably
100 bytes and then once you execute with that number you will be able to get the actual benchmarking
and let's assume that we also know the kind of operation we are going to run in Redis.
You know
You are not going to run all of these commands in all the environment.
So probably in most of the scenarios, you are just going to run Get or Set.
Command.
OK.
So you are going to write the value to RedisDB and going to read the values from
RedisDB.
So in those case, we don't need to benchmark on all of these operations.
We can actually specify to run only Get or Set operations.
So now the way to do that is,
so here you see we have something called -t, which specifies a command which you want to run.
So with a , separation you can pass the list of Test Cases which you want to test and then it will
be running only those Test Cases.
So if I go back and if I specify -t and if I type Get,Set so in this case it is only going
to run Get and Set operation.
So let's Hit enter.
and you can see, it ran only Get and Set operations and then it exited because we had specified
to run only Get and Set operations and do the Performance Benchmarking
okay.
So -n basically specify the total number of Requests which you want, to you know, test with.
So by default
or right
now we had actually given 100000
So if you want to test probably on one million record. We can change this value to one million.
OK.
And then this is going to take a bit longer
Because now it has to test one hundred or i am sorry
now it has to test one million records.
So it is going to, read and write 1 million records in Redis and then going to give us the performance.
So I'm not going to run this now.
I just wanted to show you that if you need, you can do that way.
And also if you know that how many number of Applications or number of Clients, which are going to access
Redis Database, in parallel you can also specify number of expected Clients, by providing -c.
So let's say I know, I know that any point of time there are going to be you know, maximum of 5 connections
which are going to be run in parallel.
You know those are the 5 connections which are going to perform Read or Write Operations from Redis Database.
So with -c option, I can specify that. Now it is going to create 5 client and then going to
test this. So let's see what is the performance which we achieve
okay.
Actually I had also increase the number of Records which it is going to test.
So I had changed that to one million.
So now it is performing the test on one million records and with client of 5.
So it is assuming there are 5 parallel clients, which are going to access or perform Read or Write
operations and there are total going to be one million Request.
So it is simulating that and going to tell you the you know, performance which is going to achieve with these
condition.
So you can already see, so probably this time we have not achieved, what we have achieved previously.
We are now only able to achieve somewhere around 38000 you know, Read or Write per second.
Also there is something called -r, which actually specifies the number of random keys which, which
it is going to test.
Redis is going to test this performance with.
so when you specify something like -r 100.
So in this case, even though it is going to perform you know one million queries, which is based on the
value which is specified here after -n, it is actually going to create only 100 Unique Keys and
then it will be performing Read or Write Operations.
So if you want to test, based on let's say 1 million Unique Keys. You can specify those number by providing
-r and the number here.
OK.
So let me test it on a lower value.
I'm just going to probably give only 1000 and here I'm going to be 1000 Unique Keys
OK.
Since the value Set or the Test Set which I given was very smaller. So we got the result very fast.
Now I'm going to connect to Redis, by using Redis-cli and i forgot, I also need to specify
the Port
So guys, again if not required do not change the default Port from 6 3 7 9 to other Ports because otherwise
you need to specify the Port Number every time.
So now if I do dbsize. It is going to give me the total number of records which are available in database
right now.
So right now we have around 957 Records.
These are the records which got created by all the tests, which we performed and let's say we want
to just flush everything which is there.
So for that one we use Flushall
command. Please be very careful in, in terms of using this command.
This is going to clean up everything, which is there in Redis database.
OK.
So right now we have 957 Records.
If I do Flushall, it is just going to clear everything. So be very very careful. This is a very destructive
command and it runs very fast.
It just clears up you know, millions of or billions of records in very short time.
So I just ran Flushall. Immediately I got
the output.
Now if I do dbsize. I do not have anything stored in my database
OK.
So once you do the performance testing, you can actually do the cleanup.
So all the test data is removed.