Nginx took a large number of web servers in just a few short years. As we all know, Nginx is significantly more efficient than httpd in handling large concurrent static requests, and can even easily solve C10K problems. In the case of high concurrent connections, Nginx is a good alternative to the Apache server. Nginx can also be used as a 7-tier load balancing server. According to my test results, Nginx 0.7.14 + PHP 5.2.6 (FastCGI) can withstand more than 30,000 concurrent connections, which is equivalent to 10 times that of Apache in the same environment. In general, 4GB of memory server + Apache (prefork mode) can only handle 3,000 concurrent connections, because they will occupy more than 3GB of memory, but also have to reserve 1GB of memory for the system. I used to have two Apache servers because the MaxClients set in the configuration file was 4000. When the number of Apache concurrent connections reached 3800, the server memory and Swap space used up and crashed. This Nginx 0.7.14 + PHP 5.2.6 (FastCGI) server consumes 150M of memory (15M * 10 = 150M) for the 10 Nginx processes opened with 30,000 concurrent connections. The 64 php-cgi processes that are started consume 1280M. Memory (20M*64=1280M), plus the memory consumed by the system itself, consumes less than 2GB of memory in total. If the server's memory is small, you can only open 25 php-cgi processes, so the total memory used by php-cgi is only 500M. Under the 30,000 concurrent connection, accessing the PHP program of the Nginx 0.7.14 + PHP 5.2.6 (FastCGI) server is still fast. Why Nginx is better than httpd in dealing with high concurrency, we start with the working principle and working mode of the two web servers. We all know that Apache has three kinds of work modules, namely prefork, worker, and event. Prefork: multi-process, each request with a process response, this process will use the select mechanism to notify. Worker: multi-threaded, a process can generate multiple threads, each thread responds to a request, but the notification mechanism or select can accept more requests. Event: Based on the asynchronous I/O model, a process or thread, each process or thread responds to multiple user requests, it is implemented based on event-driven (ie, epoll mechanism). 4.2 How does prefork work? If you do not explicitly specify an MPM with "--with-mpm", prefork is the default MPM on the Unix platform. The pre-derived child process it uses is also the one used in Apache 1.3. Prefork itself does not use threads, version 2.0 uses it to maintain compatibility with version 1.3; on the other hand, prefork uses separate child processes to handle different requests, and the processes are independent of each other, which also makes them become independent. One of the most stable MPM. 4.3 How Workers Work Compared to prefork, worker is a new version of MPM that supports multi-threaded and multi-process mixed models in version 2.0. Due to the use of threads for processing, it is possible to handle a relatively large number of requests, and the overhead of system resources is less than that of process-based servers. However, workers also use multiple processes, each process generates multiple threads, in order to obtain stability based on the process server, this MPM way of working will be the development trend of Apache2.0. 4.4 event Based on the characteristics of the event mechanism A process responds to multiple user requests and uses a callback mechanism to reuse sockets. After the request is received, the process does not process the request. Instead, it is directly passed to other mechanisms for processing. The epoll mechanism is used to notify whether the request is completed. In this process, In the process, the process itself is always idle and can always receive user requests. A process can be implemented to respond to multiple user requests. Supports massive concurrent connections and consumes less resources. There are several basic conditions: 1. Based on threads, a process generates multiple threads, each thread responds to each request of the user. 2. Based on the event-based model, a process handles multiple requests and informs the user through the epoll mechanism that the request is complete. 3. Disk-based AIO (Asynchronous I/O) 4 support mmap memory mapping, mmap traditional web server, page input, the disk is the first page input to the kernel cache, and then copied from the kernel cache to the web server, mmap mechanism is to let the kernel cache Map with the disk, web server, directly copy the page content. It is not necessary to first input the page on the disk to the kernel cache first. As it happens, Nginx supports all of the above features. Therefore, Nginx official website said that Nginx supports 50000 concurrent, is based on. Nginx's excellence Traditionally, a web service based on a process or thread model architecture processes concurrent connection requests per process or thread, which is bound to block during network and I/O operations. Another inevitable result is the utilization of memory or CPU. low. Generating a new process/thread requires that its runtime environment be prepared in advance. This includes allocating heap memory and stack memory for it, creating a new execution context for it, and so on. These operations all need to occupy the CPU, and too many processes/threads will bring thread jitter or frequent context switching, and the system performance will be further reduced. Another high performance web server/web server reverse proxy: Nginx (Engine X), nginx's main focus is its high performance and high density of physical computing resources, so it uses a different architecture model. Inspired by advanced processing mechanisms based on "events" in a variety of operating system designs, nginx employs a modular, event-driven, asynchronous, single-threaded, and non-blocking architecture and has adopted a number of multiplex and event notification mechanisms. In nginx, connection requests are handled by a small number of process workers that contain only one thread, with an efficient run-loop mechanism. Each worker can process thousands of concurrent connections and requests in parallel. How Nginx Works Nginx will run multiple processes at the same time as needed: a master and several worker processes. When the cache is configured, there will be cache loader and cache manager. . All processes contain only one thread, and inter-process communication is mainly achieved through the "shared memory" mechanism. The main process runs as root and the worker, cache loader, and cache manager all run as non-privileged users. Nginx is a good alternative to Apache server in high-concurrency concurrency situations Nginx installation is very simple, the configuration file is very simple (it also supports perl syntax), Bugs very few servers: Nginx start is particularly easy, and almost 7*24 can run without interruption, even if you run for months do not need to re start up. You can also upgrade software versions without interruption. The birth of Nginx mainly solves the problem of C10K Finally we analyze from the multiplexed IO models used by each: Select model: (apache use, due to the restrictions of the module, not much used) Maximum number of file descriptors that a single process can monitor The data structure stored by select() that stores a large number of file descriptors. As the number of file descriptors increases, the overhead incurred by the user space and the kernel's address space will increase linearly. Because the delay of network response time makes a large number of TCP connections inactive, calling select() still performs a linear scan on all the sockets, causing some overhead. Poll:poll is a re-implementation of Unix using select itself, the only problem is that poll does not have the maximum number of file descriptors Epoll model: (for nginx use) Epoll brings two advantages, dramatically improving performance: Based on the event-ready notification mode, select/poll mode, the process will only scan the file descriptors of all monitored files after calling a certain method, and the epoll event registers a file descriptor through epoll_ctl(). When the file descriptor is ready, the kernel will use a callback mechanism like call back to activate the file descriptor quickly. epoll_wait() will be notified Calling epoll_wait() once to get a ready file descriptor returns not the actual descriptor, but a value representing the number of ready descriptors. Get these values ​​to an array specified by epoll to obtain the corresponding number of file descriptions in order You can use the memory map (mmap) technique to avoid the overhead of copying a large number of file descriptors. Of course, epoll also has certain limitations. epoll is only implemented in Linux 2.6, but not in other platforms. This is a good cross-platform server with apache, which is obviously somehow runs counter to it. In simple terms, epoll is an upgraded version of select. There is no maximum limit on file descriptors managed by a single process. However, epoll is only available on the linux platform. Not used as a cross-platform Apache
ZGAR Accessories
ZGAR electronic cigarette uses high-tech R&D, food grade disposable pod device and high-quality raw material. All package designs are Original IP. Our designer team is from Hong Kong. We have very high requirements for product quality, flavors taste and packaging design. The E-liquid is imported, materials are food grade, and assembly plant is medical-grade dust-free workshops.
Our products include disposable e-cigarettes, rechargeable e-cigarettes, rechargreable disposable vape pen, and various of flavors of cigarette cartridges. From 600puffs to 5000puffs, ZGAR bar Disposable offer high-tech R&D, E-cigarette improves battery capacity, We offer various of flavors and support customization. And printing designs can be customized. We have our own professional team and competitive quotations for any OEM or ODM works.
We supply OEM rechargeable disposable vape pen,OEM disposable electronic cigarette,ODM disposable vape pen,ODM disposable electronic cigarette,OEM/ODM vape pen e-cigarette,OEM/ODM atomizer device.
ZGAR Accessories Disposable Pod Vape,ZGAR Accessories Disposable Vape Pen,ZGAR Accessories,ZGAR Accessories Electronic Cigarette,ZGAR Accessories OEM vape pen,ZGAR Accessories OEM electronic cigarette. ZGAR INTERNATIONAL(HK)CO., LIMITED , https://www.szvape-pen.com