Internet Development (I) Basic concurrency knowledge and basic concurrency knowledge

Source: Internet
Author: User

Internet Development (I) Basic concurrency knowledge and basic concurrency knowledge

I. Basic Meaning of concurrency
In the operating system, concurrency means that several programs in a period of time are between started and running, and these programs are all running on the same processing machine, however, at any time point, only one program runs on the processing machine.
In relational databases, multiple users are allowed to access and change the process of shared data at the same time. SQL Server uses locking to allow multiple users to access and Change shared data at the same time without conflict with each other.
On a network server, concurrency refers to the number of connections that can be processed at the same time. It can be understood as the maximum number of sessions maintained by the server. For example, the server can establish 1000 TCP connections, that is, the server maintains 1000 sockets at the same time, and the server concurrency is 1000, but the server may only have single-core, 8-core, 16-core, and so on, in short, the processing of these 1000 socket connections is also done in time. If the processing time of each socket server is 1 s, the server can process 1000 requests within 1 s. If each socket processes ms, then the server can process 10000 requests within 1 s.
Ii. Differences from Parallelism
Concurrency: when multiple threads are operating, if the system has only one CPU, it is impossible for the system to perform more than one thread simultaneously, it can only divide the CPU running time into several time periods, and then allocate the time segments to each thread for execution. When the thread code is running in one time period, other threads are suspended .. This method is called Concurrent ).
Parallel: when the system has more than one CPU, the thread operations may be non-concurrent. When one CPU executes one thread, the other CPU can execute another thread. The two threads do not compete for CPU resources and can run at the same time. This method is called Parallel ).
Difference: concurrency and parallelism are two similar and different concepts. parallelism refers to the occurrence of two or more events at the same time; concurrency means that two or more events occur at the same time interval. In a multi-program environment, concurrency means that multiple programs run at the same time within a period of time, but in a single processor system, only one program can be executed at a time, therefore, these programs can only be executed in a time-based manner. If there are multiple processors in the computer system, these programs that can be concurrently executed can be allocated to multiple processors for parallel execution, that is, each processor is used to process a program that can be concurrently executed, so that multiple programs can be executed simultaneously.
Iii. Concurrent management in IIS
1. IIS concurrency related terms and settings
▲Connections and concurrent connections: these two concepts are different from each other on the Internet. However, through experiments, I found that one of their concepts in IIS is to set concurrent connections, that is, the site can accommodate the maximum number of connections requested by the customer at the same time, and I set two parameters to find that they will affect each other. Maybe the number of connections on the internet refers to the virtual host environment.
▲Maximum number of concurrent working threads: Simply put, it is the processing mechanism of IIS when concurrent connection requests come over. It can be processed in batches in a certain order of magnitude, queue the connection requests that are not processed. For example, if the maximum number of concurrent working threads is set to 50, when 200 connection requests come, 50 requests are processed, and the remaining 150 will show loading, rather than 503 errors. In this case, other users will not need to refresh the button, because the more points you have, the more requests you have in the queue. This setting is not in IIS, but ASP. NET configuration file machine. config (Win10 default location: C: \ Windows \ Microsoft. NET \ Framework \ v4.0.30319 \ Config \ modify reference: https://msdn.microsoft.com/zh-cn/library/7w2sway1.aspx)
▲Queue length of the application pool: the previous concept mentioned request queuing. Is it unreasonable to queue all unprocessed queues. This option can be used to set the number of queues. If the number is exceeded, the error 503 is returned, which is the same as the number of concurrent connections.
▲Maximum Number of worker processes in the application pool: if this value is greater than 1, multiple new worker process instances will be started when there is a connection request, the maximum number of worker processes that can be started is the maximum number of worker processes you specify. More requests will be sent to the worker process in a loop. Each worker process can bear some connection requests, of course, it is worth the cost of consuming cpu and other hardware. If the cpu usage of the web server is low but concurrent connection requests need to be processed more efficiently, why not do this?
If the website uses process-dependent sessions, caches, and other objects, they cannot be stored in the server memory. It is better to use StateServer or SQLServer for storage. In addition, context replication occurs when multiple worker processes are switched, this is also where resource consumption is more
Maximum number of worker processes: (copy) the maximum number of worker processes in the application pool is determined based on the principle that each worker process can carry 30 concurrent tasks. Note that each worker process occupies about MB of system memory. When setting the maximum number of worker processes, the product of the maximum number of worker processes and the maximum number of available memory of the system must not exceed the maximum number. Generally, we recommend that you adjust the maximum number of worker processes by increasing the number of five worker processes each time. After the adjustment, observe the website for a period of time. If the requirements still cannot be met, then, increase the number of worker processes.
2. Observe the number of concurrent connections
A: View IIS Connection Request status statistics using the command line Method
C: \> netstat-an | find "10.0.1.13: 80" | find "ESTABLISHED"/C
1297
C: \> netstat-an | find "10.0.1.13: 80" | find "TIME_WAIT"/C
129
B: Use the windows client tool NSClient ++-0.2.7 monitored by nagios to monitor the corresponding counter. If the threshold value is exceeded, the system reports an alert through fetion!
C: Add a counter, which can be displayed in a graphical manner.
Step: Run "perfmon. msc" to open the Performance Monitor and click "add counter. Select "Web Service"> "Current Connections" for the counter object, select "_ Total" for the object instance, and select a specific Web Service as needed.
Instance. Click Add. The result is shown in.

Delete information unrelated to this monitoring, leaving only the Web service information of interest. From sending concurrent requests from multiple clients, you can monitor the number of concurrent connections in real time. According to the results shown in the figure, it is not difficult to find that the current number of concurrent connections at the same time is 5.

You can right-click the counter to Open Properties and set the chart, such as color and step size.


Reference: http://blog.csdn.net/coolmeme/article/details/9997609
Http://www.cnblogs.com/qmfsun/p/4997307.html
Http://ylw6006.blog.51cto.com/470441/1058070/

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.