You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
11 KiB
61 lines
11 KiB
3 months ago
|
import { addBanner, addArticle, addTitle, addHeader, addParagraph, addSubHeader } from '/scripts/article.js';
|
||
|
import { addInset, addInsetList, addInsetCodeListing, addInsetBulletList } from '/scripts/inset.js';
|
||
|
import { addImageWithCaption, addButtonGroup } from '/scripts/visuals.js';
|
||
|
import { addSidebar} from '/scripts/sidebar.js';
|
||
|
import { addSyntax } from '/scripts/code.js';
|
||
|
|
||
|
const heading = document.querySelector(".heading");
|
||
|
const global = document.querySelector(".global_menu");
|
||
|
const local = document.querySelector(".local_menu");
|
||
|
const sidebar = document.querySelector(".sidebar");
|
||
|
const main = document.querySelector(".main_content");
|
||
|
|
||
|
heading.append(addTitle("Linux Performance Tuning"));
|
||
|
heading.append(addParagraph("Kevin Dankwardt - LinkedIn Learning - February 2018"));
|
||
|
heading.append(addParagraph("Chapter 1 - PERFORMANCE OVERVIEW"));
|
||
|
|
||
|
main.append(addHeader("What Do We Mean by Performance?"));
|
||
|
main.append(addParagraph("Often, when we talk about performance, we are talking about timing or response time, but response time can mean different things, including the following."));
|
||
|
main.append(addSubHeader("Minimum Time"));
|
||
|
main.append(addParagraph("This really just means that we want things to happen as quickly as possible. An example of this might be rendering a webpage. There are not usually any time constraints on this, but if it takes too long, it can be annoying for the user and it may lead them to visit another web site or just give up."));
|
||
|
main.append(addSubHeader("Deterministic"));
|
||
|
main.append(addParagraph("This means that the response time must be predetermined and predictable. In other words, you want something to happen at a specific time. An example of this might be software that is controlling a sensor that is measuring something at fixed intervals such as temperature. For instance, let's asy that you want to measure the temparature once an hour over a 24 hour period, the readings have to be taken at one hour intervals, if they are all taken in the first hour, they probably won't be of any use."));
|
||
|
main.append(addSubHeader("Deadline"));
|
||
|
main.append(addParagraph("Sometimes, we need a repsonse to happen by a certain time or before some other event and it may be the case, that having the response occuring earlier may not provide any added benefit. A good analogy here is the braking system in a car. If you brake to avoid a collision, you need the brakes to respond before the collision occurs, but it doesn't really matter whether that happens a second before or a millisecond before, as long as it happens in time."));
|
||
|
main.append(addSubHeader("Throughput"));
|
||
|
main.append(addParagraph("This isn't a matter of timing but it is related. Sometimes, you may need to complete a certain amount of actions or transactions in a given time such as a minimum number of transactions per second or an optimal number of web pages server per minute. This is distinct from a minimum time response in that we don't really care about how long it takes for an individual response time, we are more concerned about the number of responses within a set time."));
|
||
|
main.append(addParagraph("Let's say that we have a webpage that takes half a second to serve up and we want to improve on that. We might take steps to achieve a faster speed but paradoxically, that may mean that we server fewer pages per second overall. If we optimise the page so that we can serve as many instances of it as possible within a set time, this may mean individual pages load more quickly but fewer pages are server per minute. After all, the simplest way to ensure the fastest response time is probably to limit the number of pages that can be served simultaneously!"));
|
||
|
main.append(addParagraph("So this gives us something of a conflict. For this reason, when you are optimising a system, you need to be very cleat about what your goals are and what exactly you are trying to optimise."));
|
||
|
main.append(addSubHeader("Completion Time"));
|
||
|
main.append(addParagraph("Sometimes, we need to have some task complete as quickly as possible so this sounds as though we are talking about a minimum response time as described above and in a sense, we are. However, when we talk about response time, we are usually referring to some task that should complete as quickly as possible so that the user doesn't have to wait. In a sense, the goal is to get as close to zero response time as possible so that the user doesn't even notice that the system took some time to complete a task."));
|
||
|
main.append(addParagraph("Completion times tend to be on a grander scale in that it relates to tasks that take a considerable amount of time to complete. An example of this might be a software build where the user is going to have to wait some time for the task to complete. If we want to optimise completion times, we are trying to minimise this delay, so this might mean, for instance, optimising the build process to minimise the time."));
|
||
|
main.append(addSubHeader("Other Metrics"));
|
||
|
main.append(addParagraph("Of course, when it comes to optimising the performance of a machine, there are other things that we might measure and that we might want to target when optimising a system. We won't be looking at these in this course, but they include things like"));
|
||
|
main.append(addInsetBulletList(["Efficiency", "Scalability", "Power Consumption"]));
|
||
|
main.append(addParagraph("The main thing to take away from this section is that in this course, we will mainly (if not exclusively) be looking at optimisations in terms of response times. It is important to remember that optimising for time can lead to decreased performance in other areas, throughput is an obvious example of that which we mentioned earlier."));
|
||
|
main.append(addHeader("Timing Techniques"));
|
||
|
main.append(addSubHeader("Using Wall Clock Time"));
|
||
|
main.append(addParagraph("If a task takes a long time (let's say, long enough for us to want to time it to the nearest minute), we can use a clock to time it. If we want to be a little more precise, you can use the date command before and after the command you want to execute. You can put all of this on a single line using semi-colons so that the tasks execute in sequence. That is - the date command followed by the command you want to time followed by the date command again. For example, on my web server, if I want to know how long it takes to copy the files for the website into the HTML folder, I can time it like this."));
|
||
|
main.append(addSyntax("date; sudo cp -Rf /home/philip/FTP/website/* /var/www/html/; date"));
|
||
|
main.append(addImageWithCaption("images/figure1.png", "Figure 1 - the result of timing a command using the date command"));
|
||
|
main.append(addParagraph("My web server is actually configured to run this command every ten minutes between the hours of 7am and 1am, and I use a slightly different method which isn't intended to time the process, but it does have that effect. It logs the start of the process and the end of the process so I can check the logs to see how long the process has taken at any time. The command in cron looks like this (to be fair, it could probably be a bit tidier with respect to the timings - there is probably a more concise way to tell cron to execute a task every 10 minutes)."));
|
||
|
main.append(addSyntax("*/10 * * * * logger Starting to copy files && cp -Rf /home/philip/FTP/website/* /var/www/html/ && logger Finished copying the files"));
|
||
|
main.append(addParagraph("The messages, 'Starting to copy files' and 'Finished copying files' are logged in syslog which is in the /var/log folder. Figure 2 shows part of that file."));
|
||
|
main.append(addImageWithCaption("images/figure2.png", "Figure 2 - an excerpt from the file, /var/log/syslog."));
|
||
|
main.append(addParagraph("As you can see in figure 2, the messages are logged at around 23:50 and show that the process took 53 seconds and at around 11:40, the process took around 54 seconds. Looking further back, we can see that the process is fairly consistent in terms of how long it takes so this is a useful method for checking how long a process in cron can take."));
|
||
|
main.append(addSubHeader("The time Command"));
|
||
|
main.append(addParagraph("Another method which is similar is to configure the shell prompt to display the time. When you execute the command, the prompt will show the time when it executes and by looking at the time when the prompt reappears, you can get a rough idea of the time the process has taken. You need to be careful with this though, because you can't be sure that the prompt when you first execute the command reflects the time of execution exactly. For example, let's say that you execute a command at a given time, say 2pm, but then you don't use the terminal again for some time, the start time will show as 2pm so first of all, you will want to press return to refresh the time on the prompt. You should also bear in mind the fact that if it takes a long time to type the command (perhaps you need to look something up whilst typing the command), the prompt time will not take this into account. If it is a repeatable command, you might want to execute it then press enter to refresh the prompt, press the up arrow to recall the command and then execute it."));
|
||
|
main.append(addParagraph("Another method is to use the time command. For example, I can use it to time the process of copying files on my web server as follows."));
|
||
|
main.append(addSyntax("time sudo cp -Rf /home/philip/FTP/website/* /var/www/html/"));
|
||
|
main.append(addImageWithCaption("images/figure3.png", "Figure 3 - using the time command to see how long a process takes."));
|
||
|
main.append(addParagraph("As you can see in figure 3, the process took around 54 seconds in real time which is the same as it takes when it is executed from cron. Note that in addition to the real time, the time command also displays the user time and sys time."));
|
||
|
main.append(addParagraph("The bash shell has a built in time command and this is the one that we used in figure 3. However, there is also a time command in /usr/bin which provides some additional information. We can specify this version of the time command by providing the path. We can see this usage along with the output in figure 4."));
|
||
|
main.append(addImageWithCaption("images/figure4.png", "Figure 4 - using the /usr/bin/time command to see how long a process takes."));
|
||
|
main.append(addParagraph("This gives us the same output as we saw in figure 3 in a slightly different format. The real time is shown as elapsed tine and we also have some additional output such as the CPU usage, pagefaults, swaps and so on."));
|
||
|
main.append(addSubHeader("Operations Per Second"));
|
||
|
main.append(addParagraph("A useful technique when it comes to timing can be to count the number of operations per some time interval such as per second"));
|
||
|
|
||
|
|
||
|
|
||
|
addSidebar("linux");
|