OK, where were we and why we are here?
Quoting from my blog that started all these:
Back in my mind, I had always thought that Perl is slow, comparing to compiled languages, like C/C++. So it is always in my mind that I should rewrite my simple web server from Perl to a compiled language. Finally I did...
and the result was Perl performs better than Go, two times that I tried & blogged: 1 & 2.
The Go community was not very happy about it, and neither do I, as a matter of fact, because I do believe that Go should be faster than Perl. Many people have given good & valid inputs as where things might get
improved, and I did try out everyone's suggestion to see how things can improve, including avoiding regular expressions, or using the high performance web framework echo (including echo v4), but all are just marginally faster, or have no obvious benefit at all, in which case I didn't even log a version.
That was quite some hectic journey, but long story short, I finally made it, with helps I got from various sources -- I finally made Go faster than Perl!!!
And here are the test results from my machine (which I published here):
100 concurrency requests (the number of multiple requests to perform at a time):
From this we can see Go is on-par with Perl for the ballpack of the results. OK, then why I said Go is now faster than Perl?
Take a look at the Apache Bench's statistics first:
I.e., for the Requests per second (#/sec), Perl is
4450.18 while Go is
11675.42. That's 2.6 times of Perl's throughput, while not sacrificing individual's response time much.
Moreover, when the load is light (< 70), which is the most common situation for my specific case, Go is faster than Perl.
So I'm quite happy with the result now.
Top comments (3)
So in the words of Obi-Wan, Go is faster "from a certain point of view." (And only if you don't mind that, in exchange for that marginally faster light-load performance, the Go version handles higher load much less smoothly than the Perl server.)
Don't get me wrong, I agree that for most applications, that's preferable.
Yep, agree, that's pretty accurate description of the situation, and conclusion as well.
Hey, here's a question. (I just happened to wander past this again, no idea why. But something jumped out at me.)
In the Perl stats, we see:
But the Go stats show:
...Why is Go transferring so much more data? Especially for the same amount of HTML served?