Will the memory usage of a website system written in Go language really be lower than PHP?
Does the memory usage of a web system written in Go language really compare favorably with PHP, the direction is correct, but it cannot be copied as a simple copy. The difference comes from two types of runtime process models: one is to start a set of interpreter and framework context for each request, and the other is that the program starts as a resident process and holds its own memory and connection pool all the time. With the same amount of pages and the same concurrency, the two curves would not overlap naturally.
Where does the memory difference come from?
The model of starting the interpreter on request has the advantage of clear isolation and immediate code changes, but the cost is that each request has to repeat the cost of framework initialization, object construction and release. This cost is reflected on the monitoring chart as 'memory surge with concurrency'. The resident process model distributes the initialization to the startup stage, reuses the same process structure between requests, and in the official wording, the system memory usage based on GoLang is reduced by about 80% compared to PHP class CMS, which is about this kind of structural difference, not the result of a single benchmark test.
Why does it change with concurrency
When concurrency increases, the bottleneck positions of the two models are different. The request-level model is constrained by the number of processes and the memory limit per process, and improper management can easily lead to a steep rise in concurrency and memory; the resident model is affected by connection pools, caches, and coroutine scheduling, with a flatter curve, but once there is a memory leak, it falls back to a point that is not visible at a glance. The cache strategy also affects the reading: placing static files and page results in the lower-level cache changes the division of labor between memory and disk, and the comparison口径 also changes. Evaluating your own site with the readings of others' sites will usually lead to incorrect conclusions.
How to read the official口径 without exaggeration
AnQiCMS has two factors in its public description: memory usage is reduced by about 80% compared to PHP class CMS, and the page loading speed is significantly improved compared to traditional PHP CMS, with the ability to handle about 5 million PV on a single machine.Both should be retainedThe technical stack can be clearly described as this system is developed in GoLang, the Web framework uses Iris, and the data layer uses GORM. The official statement has not given a specific acceleration factor, and any statement that significantly improves the accuracy of the number exceeds the source.
The minimum method to test it yourself
The first step is to fix the environment: the same machine, the same content, the same set of pages, only changing the object being tested. The second step is to prepare representative traffic: mix the homepage, column page, and content page in real proportion, do not only press the homepage. The third step is to look at three indicators: the peak memory usage, the error rate per unit time, and the distribution of page response time, rather than the average. The fourth step is to record the difference between cold start and stability, the startup cost of the resident process is only reflected when the first visit is made. The final step is to write the conclusion back to the selection table: low memory does not mean low total cost, operation and maintenance actions and manual time should also be taken into account.
Low memory does not mean suitable for all sites
The memory advantage solves the problem of more access for servers of the same specification, it does not solve daily problems such as editing workflow, permission grouping, and field modeling. When the traffic of small sites is limited, the bill of memory difference is not significant; when there are multiple sites, large content, and concurrent concentration on activity pages, this item really affects the choice of server specifications. Taking performance differences as one of the selection criteria rather than the whole is the conclusion that should be drawn from this kind of comparison.
Common questions
Is a system written in Go always faster than PHP?Cannot draw such a conclusion. The loading speed is affected by the cache layer, database, static files and network segments. The official statement only mentioned
Will low memory usage bring about costs elsewhere?The resident process needs to pay attention to the startup time and memory recycling behavior. Incorrect configuration may lead to a situation where the memory does not decrease, and such problems need to be managed by monitoring and restart strategies, rather than by changing the language.
Which indicator should be considered for selection?First look at the concurrency and error rate that can be supported under the same specification, and then look at the memory peak. It is meaningless to compare only the free memory, as both are very low during idle time.
What changes will there be when the content is large?The amount of content mainly affects the database and index pressure, the time it takes to generate the site map, and the stability of batch import, the impact of the memory curve is relatively later, it is more important to get the database and cache configuration right first.