1
00:00:00,000 --> 00:00:12,360
Okay, so this is top, the performance dashboard for Linux. When I tell people about top, there's

2
00:00:12,360 --> 00:00:17,120
always people asking me, Hey, Sander, have you heard of Htop? Yes, of course, I've heard

3
00:00:17,120 --> 00:00:23,320
of Htop. And there are other top like utilities as well. The reason I'm showing you top and

4
00:00:23,320 --> 00:00:28,480
nothing else is simple to explain. Top will always be present on your system. Because

5
00:00:28,480 --> 00:00:35,240
top is a standard Linux utility. Htop is a fancy version of top, it's showing you colors,

6
00:00:35,240 --> 00:00:40,360
it's showing you much more details. But it also has a much larger system overhead. And

7
00:00:40,360 --> 00:00:46,160
for that reason, you won't find Htop by default installed on most systems. You can see it

8
00:00:46,160 --> 00:00:53,360
right here in bold typeface. Top is using a CPU percentage of about 0.3%. I have seen

9
00:00:53,360 --> 00:00:59,880
Htop systems that are using about 4% just for Htop. And let's face it, you are using

10
00:00:59,880 --> 00:01:04,279
utilities like this. If you have an issue with your performance, then you don't want

11
00:01:04,279 --> 00:01:10,959
to run a utility that's a performance hit itself. Also notice that in many cases, it

12
00:01:10,959 --> 00:01:16,400
will not be allowed to install different utilities anyway. Imagine that you're a consultant and

13
00:01:16,400 --> 00:01:21,040
you want to help a customer with their performance problems. And then you are going to tell them,

14
00:01:21,080 --> 00:01:27,360
hey, can you install Htop for me? Most likely they are going to tell you no, because installing

15
00:01:27,400 --> 00:01:34,400
unauthorized software is not something that is easily done in many Linux installations. Now

16
00:01:34,400 --> 00:01:40,040
the top interface right here is a little bit boring. I'm using Qt to quit. And I'm going

17
00:01:40,040 --> 00:01:49,239
to give us some action using DDIF is dev zero, OF is dev null. And I'm making it background

18
00:01:49,239 --> 00:01:54,440
job. And then I'm running top again, so that at least we have one process that is creating

19
00:01:54,440 --> 00:01:59,959
some action. First thing I would look at in the top interface is the load average. Load

20
00:01:59,959 --> 00:02:06,720
average is giving the total amount of runnable processes over the last 1, 5 and 15 minutes.

21
00:02:07,480 --> 00:02:12,960
A runnable process is a process that is currently active, but also a process that wants to be

22
00:02:12,960 --> 00:02:19,679
served. So if you see six runnable processes, it doesn't mean that these are always active at the

23
00:02:19,679 --> 00:02:25,679
same time, because that is determined by the number of CPUs that you have. One CPU can only

24
00:02:25,679 --> 00:02:33,240
have one process active at any moment in time. So on a four CPU system, if you have a load

25
00:02:33,240 --> 00:02:38,440
average of six, that indicates that you have more processes than your system can handle. And

26
00:02:38,440 --> 00:02:43,639
you need to further investigate what is going on. So for the proper identification of what is

27
00:02:43,639 --> 00:02:49,839
going on, it's important that you know how many CPUs you have. Now here, you can almost guess,

28
00:02:49,919 --> 00:02:58,039
look, we have the DD process causing 100%. And we have my system, the CPUs line. And the

29
00:02:58,039 --> 00:03:04,520
parameter I'm looking at is ID for the idle loop. Idle loop is the amount of time my CPU is doing

30
00:03:04,520 --> 00:03:11,600
nothing. So for 50% of its time, my CPU is doing nothing. That means that this must be a two CPU

31
00:03:11,600 --> 00:03:18,119
system. You want to know it for sure, just press one from the top interface. And there you can see

32
00:03:18,119 --> 00:03:26,279
that yes, indeed, this is a two CPU system. Now CPUs is the next item that I'm interested in. You can

33
00:03:26,279 --> 00:03:34,639
see my active CPU is busy in user and in system space. User and system space are the areas of your

34
00:03:34,639 --> 00:03:40,839
operating system, where system space relates to kernel work, and user space relates to user

35
00:03:40,839 --> 00:03:49,559
processes. So here, the usage is mainly happening in kernel space. That is surprising in most cases,

36
00:03:49,759 --> 00:03:55,520
because in most cases, you will see a higher level of activity in user space. And if you see a high

37
00:03:55,520 --> 00:04:02,279
level of activity in kernel space, that indicates that you have very busy drivers. Now knowing what

38
00:04:02,279 --> 00:04:08,720
is going on in my command, the DD if is and of is, I know that I'm going from one driver to another

39
00:04:08,720 --> 00:04:16,600
driver. So that does make sense. The other parameter I'm interested in is ID. ID is the idle loop, the

40
00:04:16,600 --> 00:04:21,720
percentage of time that your system is doing nothing. And I want the idle loop to be as high as

41
00:04:21,720 --> 00:04:28,040
possible. The other parameters are not so interesting. In the past, when disks were still slow, instead of

42
00:04:28,040 --> 00:04:37,880
all being SSD, you would be interested in WA. WA is waiting for IO. And waiting for IO is what you get if

43
00:04:37,880 --> 00:04:43,920
your system is waiting for your disk to process the files. But nowadays, disks are fast enough. And for

44
00:04:43,920 --> 00:04:50,519
that reason, you don't see waiting for IO anymore. Now we have the memory usage. And in the memory

45
00:04:50,519 --> 00:04:56,279
usage, we have this line indicating that we have about four gigabytes in total, of which three

46
00:04:56,279 --> 00:05:06,359
gigabytes is free, and only 530 mebibytes is used. And we also have 554 in buffers and cache. Buffers

47
00:05:06,359 --> 00:05:12,119
and cache is an area that your Linux system is using to speed up a little bit. And by keeping more files

48
00:05:12,119 --> 00:05:17,359
in buffers and cache, the next time you read the same file, you can serve it from the cache. And that

49
00:05:17,359 --> 00:05:23,679
will make your system faster. In the end, buffers and cache is not required. And that is why available

50
00:05:23,679 --> 00:05:30,720
memory is showing even more than what you see in free. And that is because your operating system is

51
00:05:30,720 --> 00:05:37,200
considering everything in cache. And it knows if the data in cache is actively being used or not. And if

52
00:05:37,200 --> 00:05:44,480
it's not actively being used, the Linux kernel knows that it can be dropped if more memory is needed. And

53
00:05:44,480 --> 00:05:51,359
in the last column, we can see the actual activity. By default, it's sort on CPU usage. You can also

54
00:05:51,359 --> 00:05:57,839
sort it on other things. And the easy way to do so is by using greater than or smaller than. Greater

55
00:05:57,839 --> 00:06:04,079
than is bringing you to the right. So right now, I'm sorting on memory usage. And smaller than is

56
00:06:04,079 --> 00:06:12,119
bringing you to the left. So if I do that a couple of times, right now, it is sorting on virtual memory

57
00:06:12,119 --> 00:06:18,040
usage. The virtual memory is not memory that is really in use. If you want to check memory that is

58
00:06:18,040 --> 00:06:23,640
really in use, go for a resident memory. So I'm using my uppercase arrow to the right once more.

59
00:06:24,519 --> 00:06:31,880
Now, top is awesome. Because apart from this overview, you can reanalyze and kill processes.

60
00:06:31,880 --> 00:06:38,839
And you can also reorganize the top interface. If you press F, then you get all the fields that

61
00:06:38,839 --> 00:06:44,839
you could be seeing in top. And if there is anything that you would like to see, you just

62
00:06:44,839 --> 00:06:51,079
use your arrow key to go over the option that you want to see. Here, I see last used CPU. Well,

63
00:06:51,079 --> 00:06:56,760
that's what I want to see. So I'm using spacebar to select it, Q to get back to top. And look at

64
00:06:56,760 --> 00:07:04,119
that. We now have an additional column for the last CPU. And if you want to write your modifications

65
00:07:04,119 --> 00:07:11,640
to a persistent configuration file, use uppercase W. Uppercase W will write a file with the name

66
00:07:11,640 --> 00:07:16,760
toprc to make your setting persistent. So when I quit and I start top again,

67
00:07:16,760 --> 00:07:19,880
I can see my CPU column is listed again.

