I just read the above and wondering how this can be done, how can I measure electricity consumption of my code? Any example of a code that container high electricity, then be rewritten to consume less energy?
IMHO it is a bit harder to reduce, reuse and recycle using Go. At least I have some difficulties to understand how. For example sqlx (Postgresql) can reduce code a lot - compared to other drivers, but is not considered generate statically typed code. And therefore not “idiomatic”.
But one way to achieve better code (at least on the web) is to measure and fix problems repeatedly. I myself use https://pagespeed.web.dev often to find ways to increase speed and as a result reduce overall impact. Not only the electricity. But the web has some other challenges as it is complex. (hosting, caching, decrease traffic etc)
I read somewhere that only about 10 percent of Go developers use Go for web development. Anybody can confirm this?
Sir, you are correct. But look at the practicality of your statement: you have a machine that has already been built, and you run your code on it. For the needs of your code, that machine is static, it will not change.
As long as your code is not designed for a specific machine, optimized to make use of its particular specifications, having more efficient code helps, even when you upgrade your machine.
Codes are merely instructions. At best, we can optimise algorithm to perform better with less cycles but the effect is minuscule. It’s like in layman terms:
We need to do food rationing (staying green).
I can work in English, Mandarin, etc languages (codes).
I eat 2x more foods than ordinary people (needs 2x energy).
At max is you can tell to me in your language that we are low in food, or point to my belly to start reducing my consumption (tells me to use 1x energy for the same output instead).
It’s not the speaking or belly-pointing that are not helping; the output it generated is very small (for the fact that I still need ~2x energy just to stay up or I will die of hunger). In this case, I will rather tackle the problem from other angles like:
hire another person that eats <2x of foods but do better job than me (hardware replacement).
look into self-sustainable indoor-farming sources (renewable energy powering).
optimising my work schedules with another person that eats 1x food for mundane tasks and only calls me for big tasks. (scheduling optimisation, energy+performance co-processors).
The argument is mainly about tackling the problem from the correct angle.
Site-note: Don’t feel down. We (as in active maintainers) are always refactor and optimise our codes for maintainability regardless (e.g. performance optimisations, etc) so you still get better codes.
That’s where the deploy only what you consume comes in. If your machine haven’t achieve its ROI timeline (usually 6 years), continue using it. Till then, you can consider optimising using VM or containers (dockers, etc) to consolidates your computing services to a minimum of active hardware as possible. If you can do something like Google Container Engine’s autopilot feature, the better.
On the next hardware refresh, consider greener hardware like ARM-based or RISC-V servers and endpoints.
Why do you claim that the effect is minuscule ? How do you know that, what proof do you have ?
I strongly disagree. The greenest hardware you can use is the one that you have now, much greener than to build a new one. In the same way, and second hand car is much greener than a new electric car, simply because the electric car needs to be built first.