Node.js

Node.js

Node.js

 View Only

IBM Open Enterprise SDK for Node.js 22.0 now includes support for zEDC acceleration

By Wayne Zhang posted Fri April 25, 2025 12:53 PM

  

With IBM® z15® or later, IBM Integrated Accelerator for zEnterprise® Data Compression (zEDC) is provided on each processor chip and uses industry-standard compression formats for file compression that can enable reduction in the size of data which can save storage space and increase data transfer rates. It can also reduce CPU consumption and costs associated with moving, processing, encrypting/decrypting, and otherwise manipulating smaller amounts of compressed data.

IBM Open Enterprise SDK for Node.js 22.0 includes support for zEDC acceleration to the Node.js for z/OS® ecosystem through the zlib Node.js module, which is used extensively for gzip compression and decompression. Users of gzip compression in Node.js may notice significant performance benefits after upgrading to Open Enterprise SDK for Node.js 22.0 and later versions.

The zEDC feature in Open Enterprise SDK for Node.js is designed to be transparent to Node.js developers, minimizing code changes required to take advantage of this feature. Here is one example of how you can leverage zEDC to compress and decompress a given file:

const zlib = require('node:zlib');
const fs = require('node:fs');

// Name of the input and output files.
const inputFile = 'input.jpg';
const compressedFile = 'input.jpg.gz';
const outputFile = 'output.jpg';

// Compress the input file.
const gzip = zlib.createGzip();
const inputReader = fs.createReadStream(inputFile);
const compressedWriter = fs.createWriteStream(compressedFile);

inputReader.on('data', (chunk) => gzip.write(chunk));
inputReader.on('end', () => gzip.end());

gzip.on('data', (chunk) => compressedWriter.write(chunk));
gzip.on('end', () => {
  compressedWriter.end();

  // Decompress the file again after it's been compressed.
  const gunzip = zlib.createGunzip();
  const compressedReader = fs.createReadStream(compressedFile);
  const outputWriter = fs.createWriteStream(outputFile);

  compressedReader.on('data', (chunk) => gunzip.write(chunk));
  compressedReader.on('end', () => gunzip.end());

  gunzip.on('data', (chunk) => outputWriter.write(chunk));
  gunzip.on('end', () => outputWriter.end());
});

You may have noticed that there are no special arguments or function calls needed to leverage zEDC. This is because whenever possible, Node.js will automatically attempt to use zEDC acceleration for compression and decompression operations. In situations where zEDC acceleration cannot be used, Node.js will also seamlessly fallback to using software implementations for compression and decompression.

If you wish to verify whether zEDC acceleration is being used, you can leverage hwCheck(), which is a function that takes no arguments, and can be used to check whether an existing zlib stream is currently using software or hardware. Here is how you can augment the above example to use the hwCheck() function:

const zlib = require('node:zlib');
const fs = require('node:fs');

// Name of the input and output files.
const inputFile = 'input.jpg';
const compressedFile = 'input.jpg.gz';
const outputFile = 'output.jpg';

// Compress the input file.
const gzip = zlib.createGzip();
const inputReader = fs.createReadStream(inputFile);
const compressedWriter = fs.createWriteStream(compressedFile);

inputReader.on('data', (chunk) => gzip.write(chunk));
inputReader.on('end', () => gzip.end());

gzip.on('data', (chunk) => { 
  compressedWriter.write(chunk);
  
  const hwCheck = gzip.hwCheck();
  if (hwCheck === zlib.constants.Z_HARDWARE_PENDING) {
    console.log('the gzip stream is trying to use hardware if possible');
  } else if (hwCheck === zlib.constants.Z_HARDWARE) {
    console.log('the gzip stream is currently using hardware');
  } else if (hwCheck === zlib.constants.Z_SOFTWARE) {
    console.log('the gzip stream is currently using software');
  }
});
gzip.on('end', () => {
  compressedWriter.end();

  // Decompress the file again after it's been compressed.
  const gunzip = zlib.createGunzip();
  const compressedReader = fs.createReadStream(compressedFile);
  const outputWriter = fs.createWriteStream(outputFile);

  compressedReader.on('data', (chunk) => gunzip.write(chunk));
  compressedReader.on('end', () => gunzip.end());

  gunzip.on('data', (chunk) => {
    outputWriter.write(chunk); 
    const hwCheck = gunzip.hwCheck();
    if (hwCheck === zlib.constants.Z_HARDWARE_PENDING) {
      console.log('the gunzip stream is trying to use hardware if possible');
    } else if (hwCheck === zlib.constants.Z_HARDWARE) {
      console.log('the gunzip stream is currently using hardware');
    } else if (hwCheck === zlib.constants.Z_SOFTWARE) {
      console.log('the gunzip stream is currently using software');
    }
  });
  gunzip.on('end', () => outputWriter.end());
});

For more information about data compression, see the official API document for zlib modules: https://nodejs.org/docs/latest-v22.x/api/zlib.html

To learn more about situations where zEDC acceleration cannot be used and other limitations, see our documentation: https://www.ibm.com/docs/en/sdk-nodejs-zos/22.0?topic=zenterprise-data-compressionzedc-support#env__title__3

0 comments
74 views

Permalink