Skip to content

Incorrect elapsed time reported on Docker #80

Closed
@filipesilva

Description

@filipesilva

Heya, I've noticed some odd elapsed time reported on Docker images. I'm not too sure if it's docker or linux or generally, but my machine is Windows and I see the issue when using Docker. I also see it happening on CircleCI, and they use docker images for their CI machines.

Here's repro: https://github.com/filipesilva/pidusage-docker. It's just a test script that print stats three times on npm test:

var pidusage = require('pidusage')

// Compute statistics every second:
const interval = setInterval(function () {
  pidusage(process.pid, { maxage: 1000 }, function (err, stats) {
    console.log(stats)
    // => {
    //   cpu: 10.0,            // percentage (from 0 to 100*vcore)
    //   memory: 357306368,    // bytes
    //   ppid: 312,            // PPID
    //   pid: 727,             // PID
    //   ctime: 867000,        // ms user + system time
    //   elapsed: 6650000,     // ms since the start of the process
    //   timestamp: 864000000  // ms since epoch
    // }
  })
}, 1000);

setTimeout(() => clearInterval(interval), 3500);

On my Windows machine I see something like this:

{ cpu: 0,
  memory: 23441408,
  ppid: 4512,
  pid: 14228,
  ctime: 265,
  elapsed: 1554,
  timestamp: 1535623344931 }
{ cpu: 3.2,
  memory: 23777280,
  ppid: 4512,
  pid: 14228,
  ctime: 297,
  elapsed: 2388,
  timestamp: 1535623345765 }
{ cpu: 0,
  memory: 23781376,
  ppid: 4512,
  pid: 14228,
  ctime: 297,
  elapsed: 3659,
  timestamp: 1535623347036 }

Using one of CircleCI's docker images, for instance circleci/node:8.11-browsers, I see the following

$ docker run -v d:/sandbox:/sandbox -it circleci/node:8.11-browsers
$ cd /sandbox/pidusage-docker
$ npm test

> [email protected] test /sandbox/pidusage-docker
> node test

{ cpu: 0,
  memory: 30306304,
  ctime: 0.08,
  elapsed: 1535540503719,
  timestamp: 83190970,
  pid: 24,
  ppid: 23 }
{ cpu: 0,
  memory: 30547968,
  ctime: 0.08,
  elapsed: 1535540504713,
  timestamp: 83190970,
  pid: 24,
  ppid: 23 }
{ cpu: 1,
  memory: 30547968,
  ctime: 0.09,
  elapsed: 1535540505714,
  timestamp: 83190970,
  pid: 24,
  ppid: 23 }

(NB: d:/sandbox:/sandbox is just mounting my local folder so I don't have to git clone the repro)

The difference between each elapsed seems correct, but they are reporting something like 48 years of elapsed time.

I guess it's related with the extremely low timestamp though, since elapsed is calculated from it:

https://github.com/soyuka/pidusage/blob/master/lib/procfile.js#L115-L116

I tried adding some logging to the relevant computations for the timestamp:

      console.log('parseFloat(infos[19])', parseFloat(infos[19]))
      console.log('cpuInfo.clockTick', cpuInfo.clockTick)
      console.log('stat.start', stat.start)
parseFloat(infos[19]) 8421548
cpuInfo.clockTick 100
stat.start 84215.48
{ cpu: 0,
  memory: 30195712,
  ctime: 0.07,
  elapsed: 1535540503698,
  timestamp: 84215480,
  pid: 52,
  ppid: 51 }

parseFloat(infos[19]) 8421548
cpuInfo.clockTick 100
stat.start 84215.48
{ cpu: 0,
  memory: 30461952,
  ctime: 0.07,
  elapsed: 1535540504692,
  timestamp: 84215480,
  pid: 52,
  ppid: 51 }

parseFloat(infos[19]) 8421548
cpuInfo.clockTick 100
stat.start 84215.48
{ cpu: 0,
  memory: 30461952,
  ctime: 0.07,
  elapsed: 1535540505694,
  timestamp: 84215480,
  pid: 52,
  ppid: 51 }

Looking at the calculated numbers it doesn't seem like anything is going wrong, just that starttime from the procfile looks really small.

Happy to try and fix this, do you have any ideas on how to proceed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions