In recent years, more and more website owners have begun to pay attention to CMS developed with Go language.As a developer transitioning from PHP to Go, I want to delve into the technical aspects: why can AnQiCMS and other Go language CMSs outperform traditional PHP solutions like WordPress, EmpireCMS, and others in terms of performance?

Performance differences at the language level

Fundamental differences in concurrency models

PHP's concurrency model is the "process/thread isolation" mode.Every HTTP request coming in, PHP-FPM creates a separate process to handle.The process creation requires allocating independent memory space, loading the PHP interpreter, and compiling PHP code.This means:

  • Memory overhead of each PHP requestApproximately 30-50MB (including PHP interpreter + framework + application code)
  • Handle 100 requests simultaneouslyApproximately 3-5GB of memory required
  • Performance drops under high concurrency: After the number of requests exceeds the process pool limit, new requests need to wait in line.

The concurrency model of the Go language is completely different. Go usesgoroutine(Coroutine), each goroutine only occupies a few KB of stack space, and a Go process can simultaneously run tens of thousands of goroutines.When a request comes in, Go creates a new goroutine to handle it within the process, without needing to create a new operating system process.

a simple analogy: PHP is like running a restaurant, every time a customer comes in, a new chef (process) has to be hired.Go is like a chef (process) who can handle multiple stove tops (goroutines) at the same time, flipping the pot when a dish is ready.The efficiency gap is evident.

The gap between compiled vs interpreted

PHP is an interpreted language, each request must go through the process of 'reading the PHP file → syntax parsing → compiling into opcode → execution'.Although there is OPcache (opcode cache), opcode is still the intermediate code of the Zend engine, not machine code.

Go is a compiled language, source code is directly compiled into machine code, no need for a parser or intermediate layer at runtime. This means:

  • No code parsing overhead: Code is executed directly as machine code
  • Instant **performance on startup: No need to warm up, no need for JIT (Just-In-Time) compilation
  • More efficient memory managementThe Go's GC (garbage collection) is more efficient than PHP's Zend engine memory management.

Design advantages at the framework level.

Routing and middleware.

The routing system of the mainstream PHP frameworks (such as Laravel, Symfony) is a regular expression matching mechanism - each request traverses the registered route table and matches the current URL with a regular expression.When the route table has 100 rules, it takes an average of 50 regular expression matches to find the correct route.

AnQiCMS uses the Iris framework adoptedPrefix Tree (Radix Tree) routingMechanism. All routing rules are compiled into a tree structure, and requests are matched layer by layer with the URL path. A tree with 100 routes only has 10 levels deep, ...Compare at most 10 times to find the matching routeThe time complexity has dropped from O(n) to O(log n).

Template rendering

The rendering process of PHP template engines (such as Blade, Smarty) is: read the template file→compile into PHP code→execute PHP code to output HTML.Even with caching enabled, compiled PHP code must be executed during each render.

The template rendering of AnQiCMS is completed in the Go layer,Do not generate intermediate code to execute. Template parsing, variable replacement, and function calls are all completed at the Go runtime, with rendering speed 5-10 times faster than the PHP template engine.

database-level optimization

connection management

The traditional database connection method in PHP is to create an independent MySQL connection for each process, and there will be 100 connections for 100 processes.The connection pooling requires additional middleware support (such as ProxySQL).

AnQiCMS uses Godatabase/sqlStandard library, built-in connection pool management.One process maintains a connection poolThe connection in the goroutine shared pool. On a 1-core 2G server, AnQiCMS can support thousands of concurrent requests with 20-30 database connections.The PHP solution needs to achieve the same concurrency capability, usually requiring 100+ processes and corresponding 100+ database connections.

Query Optimization

AnQiCMS's database query has been deeply optimized:

  1. Prevention of N+1 query: Batch loading associated data (Eager Loading), avoid circular queries
  2. Query cache: Common query result cache for 1-5 minutes, reducing database pressure
  3. Precompiled statement: Precompile SQL template, only pass parameters when executing, reducing SQL parsing overhead

In actual testing, websites with the same amount of content, WordPress handles an average of 35-50 SQL queries per page request (including plugin queries), while AnQiCMS only needs 8-12 times.

Caching mechanism

AnQiCMS built-in multi-level cache:

Cache layer Cache content Valid time Hit rate improvement
Memory Cache Hot Page HTML 5-15 minutes 50-70%
File Cache Template compilation result Permanent (until template modification) 100%
Query cache Database query result 1-5 minutes 30-50%

After three levels of cache stacking, actual page requests70% or more are returned directly from memory cacheIt does not require any template rendering or database query. This is why AnQiCMS can achieve a page loading time of 0.3 seconds on low-end servers.

Actual Performance Comparison Data

Benchmark test using Apache Bench, test environment: 1-core 2G cloud server, 100 test articles

Test Metrics WordPress AnQiCMS Gap Multiples
100 concurrent requests, total requests 5000
Requests per second 180 req/s 2100 req/s 11.7x
Average Response Time 550ms 47ms 11.7x
99% Response Time 1200ms 120ms 10x
Maximum memory usage 280MB 42MB 6.7x
500 concurrent requests, total requests 10000
Requests per second 50 req/s(overloaded) 1800 req/s 36x
Average Response Time 9200ms 280ms 32.8x

The data is very clear: AnQiCMS has more than 10 times the throughput of WordPress, and the gap is expanded to more than 30 times under high concurrency.This is the underlying reason why WordPress requires a starting configuration of 2 cores and 4G, while AnQiCMS can run smoothly on 1 core and 1G.

Summary

The performance advantage of Go language CMS is not brought by a single technology, but rather the result of the overall upgrade of the entire technology stack from language features, framework design, database optimization to caching mechanism. For small and medium-sized enterprises that pursue performance and want to save server costs,Migrating from PHP CMS to Go language CMS, performance can be improved by 10 times, and server costs can be reduced by more than half.

As the Chinese old saying goes: “To accomplish a task well, one must first sharpen his tools.”Choose the right technology stack, and building a website will be half done.