ASP. NET core VS Goang web[correction Article]
Previously wrote an article: Http://www.cnblogs.com/gengzhe/p/5557789.html, is also the ASP. NET core and Golang Web comparison, enthusiastic friends raised a few questions, as follows:
1, need to join sleep to simulate the actual business, so as to test the co-scheduling ability.
2, Golang is good at multi-core environment.
So I fixed it today and tested it again.
Cpu:e1230-v2
Memory: 16GB
Operating system: CentOS 7 (3 core 2GB memory)
Here's the code:
Go
1234567891011121314151617181920212223242526272829 |
package
main
import
(
"fmt"
"net/http"
"time"
)
func
main() {
fmt.Println(
"This is webserver base!"
)
//第一个参数为客户端发起http请求时的接口名,第二个参数是一个func,负责处理这个请求。
http.HandleFunc(
"/login"
, loginTask)
//服务器要监听的主机地址和端口号
err := http.ListenAndServe(
"192.168.199.236:8081"
, nil)
if
err != nil {
fmt.Println(
"ListenAndServe error: "
, err.Error())
}
}
func
loginTask(w http.ResponseWriter, req *http.Request) {
//获取客户端通过GET/POST方式传递的参数
time.Sleep(time.Millisecond*300)
req.ParseForm()
fmt.Fprint(w,
"Hello Word!"
)
}
|
C#
1234567891011121314151617181920212223242526272829303132 |
public
class
MyHandlerMiddleware
{
// Must have constructor with this signature, otherwise exception at run time
public
MyHandlerMiddleware(RequestDelegate next)
{
// This is an HTTP Handler, so no need to store next
}
public
async Task Invoke(HttpContext context)
{
await Task.Delay(1*300);
await context.Response.WriteAsync(
"Hello World!"
);
}
// ...
}
public
class
Startup
{
public
void ConfigureServices(IServiceCollection services)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public
void
Configure(IApplicationBuilder app)
{
app.MapWhen(context => {
return
context.Request.Path.ToString().EndsWith(
"jjj.go"
); }, ap =>
{
ap.UseMiddleware<MyHandlerMiddleware>();
});
}
}
|
Test results (1000 user concurrency)
Go
C#
The test results are really golang a little bit better.
Personal summary of the gap has 2 points
1, Go is static compilation, running speed should be faster.
2.. NET MVC is better packaged, and requests require a lot of processing before entering the business logic.
These are only personal points of view.
NET core VS Goang Web