Apache is an open source HTTP server that can run in most computer operating systems. Because of its cross-platform and security (note 1), it is widely used and is one of the most popular Web server-side software at present. It is fast and reliable, and can be extended by simple API. Interpreters such as Perl/Python can be compiled into the server.
history
Street hooligans
It was originally developed by the National Center for Advanced Computing Planning at the University of Illinois at Urbana-Champaign. Since then, Apache
Members of the open source community are constantly growing. Street hooligans
The server has a reputation of reliability and credibility, and has been used on more than half of Internet websites, especially almost all the most popular and visited websites.
At first, Apache was just a Netscape Web server (now Sun
1) Open source options. Gradually, it began to function and speed. Beyond other Unix-based HTTP servers. Since1April, 996, Apache has been
The most popular HTTP server on the Internet: 1999 May, which runs on 57% of web servers; By July 2005, this proportion had risen to 69%.
work
The author claims that the name was originally chosen because it is easy to remember, but the most popular explanation is that the name comes from the fact that 1995 developed Apache at the beginning.
Hou was modified with the code of the most popular HTTP server NCSAHTTPd 1.3 at that time, so it was "patched (a)"
Odds and ends) "server. But it is explained in the FAQ of the server official website: "The name' Apache' commemorates an American Indian named Apache (Hindi).
As one of the aborigines, it is well known that they have superb operational strategies and endless patience. "In any case, the Apache2.x branch does not contain any NCSA code.
characteristic
Street hooligans
Supports many functions, most of which are realized by compiling modules. These features range from server-side programming language support to authentication schemes. Some common language interfaces support Perl, Python, Tcl,
And PHP. Common authentication modules include mod_access, mod_auth and mod_digest. Other examples are SSL and TLS support.
(mod_ssl), proxy module, very useful URL rewriting (realized by mod_rewrite), custom log file.
(mod_log_config) and filtering support (mod_include and.
Mod_ext_filter).Apache logs can be analyzed by using free scripts AWStats or Visitors through a web browser.
2.x version
The 2.x version of Apache has made important enhancements to the Apache 1.x version. This includes: threading, better support for non-UNIX platforms (such as Windows), new ApacheAPI and IPv6 support.
evaluate
In August 2004, PCMagazine》2004 selected 10 as the best software product in the past 30 years.
Some of them either have the most glorious history or are the most creative. Its evaluation of apache is: third place: Apache (introduced by 1995) Apache has evolved.
It becomes a "light", that is, a combination of Linux, Apache, MySQL and PHP. This is an open source software project, which has posed a serious threat to Microsoft. " NET "strategy.
Especially Apache web server, let users fully experience the stability, reliability and customization of developing source software.
When Apple.com evaluated Apache,
Apache is an important part of developing server software. It is free, but it is priceless. Street hooligans
It is an absolute treasure in the resource opening movement, because it is not a personal patent but is open to the public free of charge. Once you have the source code, programmers are free to do what they want-when other programmers take over, they can be given the same job.
Permission to change and modify your own source code.
To annotate ...
Although new vulnerabilities are constantly being discovered, they can always be fixed quickly because of their open source characteristics. So overall, its security is still quite high.
()AddHandlercgi-script.cgi
AddHandlerserver-parsed.shtml
Sethandlercgi-script
AddHandler defines which extension is described by which string.
SetHandler specifies that all files in the directory are described by this string.
The commands I mentioned here are closely related to their structure. The relationship between handlers and types will be described below. Many things can't be seen clearly from the outside. Next, let's look at it from the inside.
Basic structure of program
-
Apache is very cross-platform. In order to achieve this goal and simplify the burden of module writers, Apache has completed many basic functions, such as IO and memory allocation, which are independent of specific platforms. There are also some useful routines, such as Hashtable and Array. In the whole system, Apache has a basic point. Using simple structure and algorithm as much as possible is not only easy to understand and maintain, but also improves its stability.
exist
On UNIX system, Apache adopts multi-process model and multi-thread model on Window. In the multi-process model, its sub-processes handle customer requests,
The parent process is used to manage the child processes. When the system is overloaded, the parent process will start several more child processes, and when the system is idle, the parent process will kill several child processes.
The number of subprocesses is between "MinSpareServers" and "MaxSpareServers". In addition, the number of requests handled by each sub-process is also limited.
This can solve problems such as memory leakage. All process states are recorded in shared memory. Since the state of each process is recorded in a small piece of memory,
It usually only reads and writes this memory, so Apache does not use any synchronization mechanism.
Apache uses several multi-process server models mentioned in RichardSteve's book, and chooses to use different methods on different systems according to their characteristics:
1. Accepted:
Only when accept is implemented at the kernel level, it is possible to block when accept.
2. Choose:
Block when selecting.
3.mutex/lock_file:
Use mutex or lock_file to mutually exclude accpet.
three
Both methods need plugging, but the difference is that plugging is different. The first two methods will cause the so-called giant group problem: multiple processes blocked on the same resource will be awakened at the same time, which will lead to re-competition.
However, according to RichardSteve, the first method is the fastest, the second is the second, and the third is the slowest. In fact, the third method will also have a giant group problem on linux.
Although Apache does not emphasize performance, it does not mean that they do not attach importance to performance. On the contrary, Apache thinks realiable is the first server, but Apache's performance is still good.
30 requests redis or 30 request databases, which is faster?
Pure memory database, if it is only a simple key value, memory is not the bottleneck. Generally speaking, hash lookup can reach the order of millions of times per second. The bottleneck lies in the network IO.
According to your 10000/s measurement, the client and redis should be deployed on two different machines to request redis synchronously. Each request needs to be sent to the machine where redis is located through the network, and then wait for redis to return the data.
Most of the time is spent on network transmission.
If you put redis and the client on the same machine, the network delay will be smaller, and in general, it can hit 60 thousand times per second or even higher, depending on the performance of the machine.
Locks are not the main factor affecting performance.
The performance of thread lock (mutex_lock) will only decrease when encountering conflict, but in general, the probability of encountering conflict is very low.
If it is simply locking and unlocking, the speed is very fast, and there is no problem with tens of millions of times per second.
Memcache uses a lot of locks internally and does not see performance degradation.
Threads are not an important factor affecting throughput.
On the first point, generally speaking, the speed of the program processing memory data is much higher than that of the network card receiving.
The advantage of using threads is that multiple connections can be processed at the same time, and in extreme cases, the response speed may be improved.
Use epoll or libevent etc. Because asynchronous non-blocking IO programming can only do this.
Corresponding to this is synchronous blocking IO programming, which uses multi-process or multi-thread to realize the processing of multiple connections, such as apache.
Generally speaking, the performance of asynchronous non-blocking IO model is much higher than that of synchronous blocking IO model, which can be compared with nginx and apache.
Libervent is not slower than ae_event implemented by redis itself. The reason why there are many codes is that ae_event only implements the functions required by redis, while Libervent has more functions, such as a faster timer, a bufferevent model and even its own DNS and HTTP protocols.
While libevent is more general, redis only focuses on linux platform. Finally, what is the main question?
1, pure memory operation 2, asynchronous non-blocking IO
How to realize mutual exclusion and synchronization of processes by using semaphores provided by Linux?
Set the initial value of mutex as 1, and the process will be P (mutex) before the operation and V (mutex) after the operation. The p operation reduces the mutex by 1. If the mutex is mutually exclusive,
(I have heard an answer about photovoltaic operation before. Do you think it is useful? )