binakot / Abstract-Rest-Service-Benchmark

A set of template services in different languages and frameworks. An abstract performance comparison based on the endpoint throughput. There are no objective benefits, just an elementary comparison of primitive RESTful API services. :shipit:
MIT License
16 stars 14 forks source link

Avoid response encoding #1

Closed TyVik closed 6 years ago

TyVik commented 6 years ago

https://github.com/binakot/Abstract-Rest-Service-Benchmark/blob/3608c5837d532a09e4d8a00010f0deb5c9b18c50/go-rest-service/main.go#L12

I think the test will be more accurate if you avoid encoding to json.

tetafro commented 6 years ago

Or maybe more complicated logic should be used? Like parsing query params and encoding them to json.

Also this looks strange - Encode("Hello, World!"). The result will be just []byte("Hello, World!").

TyVik commented 6 years ago

I think more complicated behavior should be regulated by command line arguments.

binakot commented 6 years ago

JSON encoding is the most typical operation in REST services. I sure it should be here. And more: 1) .NET Core do it by default, i don't know how to disable that 🤣 2) I don't know how to do JSON encoding in Go in right way. Can u help me?

Atm I don't wanna add something more complicated like query params, arguments and so on. One request /api/test, one JSON encoded answer with single string Hello, World!. Do you disagree with me? For now we have 3 projects only, it's not a problem to change these structures.

TyVik commented 6 years ago

I'm not familiar with java, but is it manual encoding? return "[\"Hello, World!\"]";

By the way, json processing is additional task, which can may affect the main result. For example: http://artem.krylysov.com/blog/2015/09/29/benchmark-python-json-libraries/. There are 4 libraries for parsing json and results are very different.

tetafro commented 6 years ago

I don't know how to do JSON encoding in Go in right way. Can u help me?

I mean, you should use an input that looks like json (map for example). Otherwise it doesn't make sense.

 json.NewEncoder(w).Encode(map[string]string{"message": "Hello, World!"})
tetafro commented 6 years ago

One more thing about json encoding: since encoding constant into json will always give the same result, isn't it possible that some smart enough compilers will do it only once at compile time?

binakot commented 6 years ago

I see. Okay, I'll remove JSON processing from all of projects. 👍

binakot commented 6 years ago

Done ☕️