A deep understanding of the multi-thread mechanism of IIS and a deep understanding of the multi-thread mechanism of iis

Source: Internet
Author: User

A deep understanding of the multi-thread mechanism of IIS and a deep understanding of the multi-thread mechanism of iis

First, let's take a look at the two numbers in IIS: Maximum number of concurrent connections and queue length. Let's talk about where the two numbers are.

 

Maximum number of concurrent connections: select a website in IIS, right-click the website name, right-click the website name, and choose Manage Website> advanced settings ]. The following dialog box is displayed:

 

Queue Length: Select application pool in IIS, right-click the application pool in the application pool list, and choose advanced settings from the context menu ]. Open the following dialog box:

 

On the surface, these two numbers affect the concurrent processing capability of our website. But how does it affect the concurrent processing capability of a website? To fully understand the concurrent processing capability of IIS, in addition to the two numbers, there is actually a very critical number: the maximum number of concurrent working threads in IIS.

 

1. Maximum number of concurrent working threads in IIS

For a long time, I always thought that the [maximum number of concurrent connections] of IIS would affect the maximum number of concurrent working threads of IIS. I thought to set [maximum number of concurrent connections] to 10 thousand. When 10 thousand requests arrive at the same time, IIS will enable 10 thousand threads for processing. If 20 thousand requests arrive at the same time, since the maximum number of concurrent connections is only 10 thousand, the remaining 10 thousand requests will be placed in the queue. One of the current 10 thousand threads completes the request and then retrieves a request from the queue. However, this understanding is completely wrong. I believe many of my friends have the same understanding as I have.

 

Now, let's first understand what is [maximum number of concurrent working threads in IIS ]. There is no interface for setting this number in IIS. I didn't know it before. This number is related to the operating system. The value of IIS In My win7 system is 10, and the value of IIS Express in VS2012 is 80. I have not tested the specific value of the windows Server version, but I guess there are limits.

 

What does this number mean? Return to the example above. When 10 thousand requests enter IIS at the same time, because IIS In win7 only has 10 working threads, at this time, only 10 of the 10 thousand requests will be processed immediately, and the remaining 9990 requests will be queued. That is to say, IIS can schedule up to 10 threads to simultaneously process requests (for IIS of win7 version, some may be 20 ).

 

Therefore, if you use your win7 system to test the performance of IIS, you may find that no matter how you set [maximum number of concurrent connections], your IIS processing capabilities are limited.

 

2. Maximum number of concurrent connections

The maximum number of concurrent working threads in IIS mentioned above seems to be the concurrent processing capability of IIS. If so, what is the significance of [maximum number of concurrent connections?

 

In the above example, if 10 thousand requests come at the same time, and the maximum number of concurrent working threads in IIS in our win7 system is only 10, then set [maximum number of concurrent connections] to 100, what will happen? The answer is: only 100 requests will receive a normal response, and the remaining 9900 requests will directly return the 503 (Service unavailable) error. In this case, only 90 requests are waiting in the queue.

 

Next, change the test parameter. If you set [maximum number of concurrent connections] to 5000, what will happen? You may already know the answer, that is, 5000 requests directly returned 503 at the beginning, and the remaining 5000 requests slowly returned normally.

 

Here you can see that [maximum number of concurrent connections] affects the number of queues in our test example. In this case, it seems that [queue length] does not know what it means?

 

3. Queue Length

In the preceding example, if 10 thousand requests arrive at the same time, set [maximum number of concurrent connections] to 100. At this time, we know that IIS will first arrange the 10 threads to process 10 requests, and the remaining 90 requests need to be queued. In this case, if we set [queue length] to 50, what will happen? The answer is: 40 requests will directly return the 503 service unavailable error (because the queue has only 50 requests, the remaining 40 will not be able to queue ), in the end, only 60 requests are processed correctly.

 

Do you understand this?

 

Conclusion

When many requests come at the same time, IIS will determine whether there are redundant requests based on [maximum number of concurrent connections]. If there are redundant requests, the system will directly return 503, then, based on the [queue length], determine whether redundant requests cannot be lined up. If there are no queues, 503 is returned. Therefore, the formula for setting the maximum number of concurrent connections and queue length can be calculated as follows:

 

Maximum number of concurrent connections = Queue Length + maximum number of concurrent working threads in IIS

 

Finally, let's talk about the impact of the default value of IIS on the concurrent processing capability of our website. The default [maximum number of concurrent connections] for IIS is 4294967295 (more than 4.2 billion), and the default [queue length] is 1000. For IIS of windows server, the maximum number of concurrent working threads may be several hundred (which may be unlimited). According to this default value, the number of requests simultaneously processed by IIS is more than 1000. More than 1000 of this number is the real concurrency processing capability of IIS, which has nothing to do with our code. Which indicators are used to judge the processing capability of our website? The most important indicator may be the number of requests processed per second (which can be viewed in the Performance Analyzer). This number is also called the throughput rate. If the processing speed of each request is very fast, the website throughput will be large, and the throughput will be large, so the number of concurrent online users will be large. If you want to perform a second kill, it depends on how much throughput your second kill-related URL supports. Having understood such a multi-index, it does not involve the computing power of the CPU. How does the computing power of the CPU affect the processing power of the website? If the CPU is very powerful and the processing time of each request can be reduced, the throughput will inevitably increase. There are still a lot of requests. if you spend a lot of time transmitting data over the network or to the database, the CPU is idle. If you can increase the CPU utilization, it may also improve the processing capability of the website and make full use of the server resources. If you do not want to change the code and want to increase the CPU usage, you can set the maximum number of working processes (1 by default) in the IIS application pool ), it can be set to 10. If the current CPU usage is only a few percent, you must note that each worker process is an independent application and Global static variables are not shared.


The principle of multi-thread programming, for example, Assembly

Multithreading is mainly used in 80286 or more processors. The earliest 32-bit multithreading is 80386. After reading your other post, you can understand the assembly language, I don't know. You don't understand Assembly 80386. Their command format is similar. The difference lies in the working mechanism and 32-bit. how do you want to implement multi-threading? First, we need to compile data under 386. Compared with the 8086 processor, it has many features, such as paging mechanism (Virtual Memory) and multithreading .. there are many other functions. As for its multi-threaded mechanism, it mainly uses the memory lookup method to put the address segments and offset addresses of all programs into the GDT table and IDT table, the table is read to the cs: eip register and the cs: eip content is saved in this table by means of clock frequency interruption, of course, this also involves many concepts, such as the storage of various registers, the protection of code segments, various control doors, descriptors, and the addresses of various registers in the cpu to save tables, this is the concept of a whole book. It is suggested that the book reading Yang Ji Wen is called the 8086 assembly language programming design. The first half of this book is about 8086, which is the basis, the second half of this book is the working mechanism and principles of 80386 and 386 and the compilation method. I will guide you here.

It can be said that 8086 and 80386 are very different, and we recommend you a group of simple bios and kernel research groups, 67286087

How does the Thread subclass implement the multithreading mechanism?

Let's talk about the mechanism of implementing multithreading in java:
Two Methods: Inherit the Thread class, and rewrite the run () method of the parent class, and implement the Runnable interface, which is also the run () method. The run () method is very important. It is the core of the runtime when you create a new thread. Note that you should not call the run () method yourself. If you call the run () method by yourself, it's just that you write the line of calling code. The thread that runs the line of code is executing this method, rather than creating a new thread for execution. This is also often confusing in my previous multi-threaded programming.
Speaking of this, how to create a thread? Simple: Thread newThread = new Thread (parameter); Parameters in the constructor are an instance of the previous two implementation classes. So when you call: newThread. after the start () method, a new thread is started. When the thread executes run (), that is, the run () method of the instance in the parameter is the main body of the thread execution.
Note: The main run () method executed by a thread does not need to be displayed and called.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.