Where does the difference in running costs lie between Go and PHP on the same server that runs a content management system?
Comparing content management systems of Go and PHP on the same server, the main difference in running costs comes from the process model: on the Go side, it is usually a long-running process, holding the code and connection pool for a long time after the process starts, and processing requests directly within the existing process when requests arrive;PHP side is more common in the form that each request needs to reload the script, initialize dependencies and build objects, and release after the request is completed. The former spreads the one-time cost to the startup stage, while the latter charges the one-time cost repeatedly for each request.AnQiCMS developed based on GoLang, the technology stack is GoLang plus Iris framework and GORM, which determines that its memory and concurrency performance follows the resident process route.
The fundamental difference between two running models
The overhead of the long-term process model is concentrated in startup: loading the binary, establishing the database connection pool, preparing the routing and template related structures, and then each request only handles the business logic itself. Its memory is occupied for a long time, even if there is no traffic, it will maintain a baseline value. The benefit is that the request handling path is short, and there is no repeated loading cost.
The cost of rebuilding the model on request is distributed over each request: script parsing, automatic loading, and framework initialization all need to be run again. Its memory usage is peak, it falls back basically after the request ends, and it occupies very little when idle. The cost is more CPU and initialization time under the same business volume, and when concurrency increases, it usually relies on increasing the number of working processes to bear the load, and each working process needs to bear its own share of the initialization cost.
How to estimate the memory account
The official statement is: The memory usage is reduced by about 80% compared to PHP class CMS. This number should be used according to its specifications, as it is a non-quantitative comparative conclusion and not an exact multiple. It cannot be used to calculate how much memory a machine will save. The more reliable method of estimation is in three steps: first, deploy on the target machine after it is unloaded and record the resident baseline memory; then, use a page combination close to the real business for stress testing and observe the peak; finally, leave a margin for caching and other services, and decide the specification by floating a safety water level on the peak.
What truly affects the selection judgment is two things: one is whether there is still a high fixed occupation during idle time, and the other is whether the growth during peak time is controllable. The resident process type has a stable occupation during idle time, while the on-demand type seems to be more economical during idle time, but it will increase the total amount due to the parallel execution of multiple processes under continuous traffic.
Concurrency and single machine capacity口径
Regarding the carrying capacity, the official statement is that the page loading speed has a significant improvement compared to traditional PHP CMS, and a single machine can carry about 5 million PV. The 'significant' here is a qualitative description, without giving a specific multiplier, and writing this into a precise speedup ratio would be going beyond the wording of the source. 5 million PV should also retain the 'about', describing the magnitude of a single machine under appropriate configuration, rather than a committed SLA.
The concurrency performance also depends on where you deploy it. In production, it is usually not the case that the application process faces the public network traffic directly, in front of which there is a layer of reverse proxy to handle static resources and connection reuse, which will affect the shape of the curve you actually measure, and this layer should be taken into account during the selection test.
Calculation steps during selection
| Measurement item | Resident process type (Go stack) | Reconstruction on request type (PHP stack) |
|---|---|---|
| Idle baseline | Has fixed occupation, needs actual measurement record | Idle rollback is obvious, seems lighter |
| Single request cost | Short path, no repeated loading | Loading and framework initialization included |
| Concurrency expansion | Concurrency processing within the process | Increase working processes |
| Cold start | High cost at the start-up stage | A little each time the request |
| Spec judgment basis | No-load baseline plus peak floating safety water level | Peak process count multiplied by single process occupation |
Specific execution suggestions follow five steps: First, confirm the peak business access volume and average page complexity; second, deploy candidate systems on matching machines and run the same set of pages; third, record the curves of unloaded memory, peak memory, and response time; fourth, add reverse proxy, database, and cache layers to run another round to avoid only testing the application process; fifth, determine specifications with a margin based on the peak, not the average purchase.
The impact of deployment form on costs
The deployment method itself will also change the result. AnQiCMS supports one-click deployment via Baota panel and aaPanel, LNMP environment command deployment, and Docker image deployment, with the default listening port of 8001, forwarded by the front-end service to the outside. When selecting the containerized deployment, pay attention to two points: the container memory limit will amplify the baseline pressure of the resident process, and when testing pressure, judge according to the limit value rather than the host capacity; the image method makes the environment consistent, which is convenient for horizontal comparison and can eliminate the interference caused by dependency differences.
Common questions
Does Go definitely save memory compared to PHP?Under the same business and similar implementation quality, the resident process type usually saves the cost of repeated loading, but the specific amount saved needs to be measured, and the official only gave an approximate 80% qualitative description.
Can a low-end machine run?The key is to look at the baseline and page complexity under no load. It is recommended to measure the no-load memory on the target machine first, and then decide the specifications, rather than relying on calculation.
How will the traffic peak be?The peak growth of the resident process type is usually more gentle, and the request reconstruction type often relies on increasing the number of working processes to cope with it, and it is necessary to leave this part of the occupation for the host.
Should we change the technology stack for this?If the bottleneck is in cache strategy, database index, or template complexity, changing language won't solve it. First locate the bottleneck layer before discussing the choice.