Tech Tip #37: Don't block on a hot path

Your server is burning power just waiting.

Video created by explainapaper.com

The problem

Synchronous calls to slow services on busy paths hold threads and whole machines while nothing happens. To keep up, teams add servers that also mostly wait.

The fix you can use today

  • Use async I/O for network and disk calls on busy paths.
  • Move slow, non-urgent work to a queue and a background worker.
  • Match the concurrency model to the work: async for I/O-bound, processes for CPU-bound.

GreenCode researchers list blocking calls on busy code paths as an energy waste to fix.

Tools that help

  • GreenCode Constitution skill (GreenCode researchers): open-source energy principles and a catalogue of 37 energy anti-patterns that an AI coding agent can follow to find and fix waste like this
  • Scaphandre: measures the power drawn by each process on a Linux server and exports it to Prometheus and other monitoring stacks

How GreenCode helps

GreenCode helps tackle this by generating a load test from your system's own endpoints. It records energy as well as speed while it runs, and ranks the hotspots by the energy they use. More on this.

Tags

#performance#networking

Sources

Transcript

Your server is burning power just waiting. On busy code paths, some calls wait for a slow service to answer. While they wait, they hold a thread, and the machine around it. Nothing useful happens. To keep up, teams add more servers. And those servers mostly wait too. Here is the fix you can use today. Use async calls for network and disk work on busy paths. Move slow work that is not urgent to a queue and a background worker. Match the model to the work: async for waiting, processes for heavy sums. GreenCode researchers list blocking calls on busy code paths as an energy waste to fix. GreenCode's Constitution skill can guide an AI coding agent to fix these calls. Then check each program's power draw, using tools like Scaphandre. GreenCode helps tackle this by load testing your system through its own endpoints. It records energy as well as speed, and ranks hotspots by energy. That was GreenCode Tech Tip number thirty-seven. Follow for the next tip, and find more on greencode.ai/tech-tips.

All GreenCode Tech Tips · All GreenCode videos

  • Tip #37
  • For Developers
  • Length 1:08
  • Category Code efficiency
GreenCode

Want this checked on your own system? Talk to the GreenCode team.

Get in touch