AgustinCB / docker-api

Docker Remote API driver for node.js. It uses the same modem than dockerode, but the interface is promisified and with a fancier syntax.
GNU General Public License v3.0
306 stars 50 forks source link

Open Files Docker process #66

Open jhonatansabadi opened 5 years ago

jhonatansabadi commented 5 years ago

I'm using it to collect data from containers by minute. But it's increase docker open files, the limit is 65556, and in one the the limit went from 3000 to 28000 open files... Theres a way to collect data once? not by stream? or close the open file after read it ?

here is the code

const containers = await docker.container.list();
containers.map(async (container) => {
    const stats = await getStats(container);
    return stats;
});

const getStats = container => new Promise(async (resolve, reject) => {
  try {
    const stats = await container.stats();

    if (!stats) reject();

    stats.on('data', (stat) => {
      if (stat instanceof Buffer) {
        try {
          const statString = stat.toString();
          const json = JSON.parse(statString);
          resolve(json);
        } catch (err) {
          reject();
        }
      } else {
        reject();
      }
    });
  } catch (err) {
    reject();
    error(err);
  }
});
AgustinCB commented 3 years ago

Sorry for not coming back earlier. I have been taking a break from the project for a while and never expected it other people to actually use it :).

Is this still a problem? Can you give me more information on how is this code being run? How many containers are we talking about?