5

Helping the Environment by Saving Two Centuries of Compute time

 2 years ago
source link: https://blog.nrwl.io/helping-the-environment-by-saving-two-centuries-of-compute-time-feea8e1ce22
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Helping the Environment by Saving Two Centuries of Compute time

1*FBQVoC9YXF7wlq3dhxfQMQ.png

Among the core features of Nx is the ability to save computation time by applying different strategies. Scroll to the end of the article for some more info, but first, how much time is actually being saved?

How much time is being saved?

This is how much got saved so far (data from August 16th, 2022). Pretty crazy!

1*pT5u_K51oZBHGll7lz5VzA.png

Here are the raw numbers:

  • Last 7 days: 5 years 4 months 2 days 2 hours 32 minutes 46 seconds
  • Last 30 days: 23 years 8 months 25 days 8 hours 57 minutes 19 seconds
  • Since the beginning of Nx Cloud: 200 years 10 months 13 days 19 hours 37 minutes 57 seconds

We’re soon having a page on nx.app where you can inspect the live numbers as they keep growing in a lightning-fast manner!! (no wonder, Nx is about to hit 2.5 million downloads / week)

The Effect on the Environment

Calculating the CO2 emissions can be tricky. It really depends on what machines are being used to run the computation saved by Nx Cloud. We gave it a try by using https://green-algorithms.org/.

Last 7-day savings correspond to:

0*wtlsJfqliTPK677u.png

See all the details

Last 30-day savings correspond to:

0*20CiOx5JE5Lr0zaU.png

See all the details

Since the beginning of Nx Cloud:

0*BvLzgEHLCJg9_isq.png

See all the details

Help me out! A Primer on how Nx saves computation

Nx has various strategies to help you reduce computation time, locally and on CI. Here’s a very short overview of the strategies Nx applies with some links for further reading.

Affected Commands

Example: Run tests only for changed projects in a given PR.

nx affected:test

Nx affected commands allow you to only run commands against projects that changed with respect to a baseline. Usually, this is applied in PRs processed by your CI system. Nx analyzes the Git commits and identifies all projects that got changed with respect to a base branch (usually main or master). It then makes sure to run the given command only for those projects as well as all projects depending on them since they might be affected by the change too.

This helps save computation by reducing the set of projects that need to be processed.

Local Computation Caching

Nx comes with a so-called computation caching feature. For every cacheable operation, Nx takes a set of input parameters, computes a hash and stores the result.

0*MusIEMCW5NlEtaaA.png

Whenever a hash matches, the computation is not run, but rather the previous result is restored. This can dramatically speed up things and avoid running any computation that has already been run previously.

Distributed Remote Caching (with Nx Cloud)

By default, the Nx computation cache is stored locally (usually within the node_modules/.cache/nx folder). The real benefits come from sharing it with others, that being your co-workers or CI agents.

Nx Cloud allows to distribute the Nx computation cache across machines.

0*0uisxJ76ycdSZdA1.png

Connecting an existing Nx workspace to Nx Cloud can be done with

nx connect-to-nx-cloud

More on the docs. Nx Cloud comes with 500 hours of computation time saved per month which is plenty for most workspaces. If you go over, you can buy more, or in the worst case, caching simply stops until the next month.

Bonus! Lerna can do this too!!

Nrwl, the company behind Nx, recently took over stewardship of Lerna. Meanwhile, Lerna 5.4 just got released which features a nice integration with Nx, allowing existing Lerna users to keep using the very same commands, but still benefit from the improved task scheduling and caching abilities Nx comes with.

How to enable it? Read more on the Lerna docs


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK