0

Apparently on EC2, the gettimeofday syscall can't use the vDSO mechanism as it would on bare metal.

https://blog.packagecloud.io/eng/2017/03/08/system-calls-are-much-slower-on-ec2/

In my application, I'm using gettimeofday to measure time elapsed for runtime metrics. The application is otherwise quite optimized, and these syscalls are adding up to a significant cost.

Given that it's not necessary to get an actual time but just an elapsed time delta, is there some other mechanism by which the elapsed time could be obtained which does not require a syscall? And preferably, one which does not involve changing a system-wide setting which may compromise the time source for the rest of the system?

Phil Frost
  • 3,668
  • 21
  • 29
  • I would suggest to use `rdtsc` instruction, but [Stack Overflow disadvises against it](https://stackoverflow.com/a/42190077/2709018). But `gettimeofday` is a wall clock function, to measure elapsed times, `clock_gettime()` with `CLOCK_MONOTONIC` should be enough – myaut Sep 08 '17 at 16:35
  • 1
    In [an official video from 2016](https://youtu.be/agQMFIWr2h4) (beginning at ~14:35) AWS seems to actually recommend switching the instance to use tsc. – Michael - sqlbot Sep 08 '17 at 18:37

0 Answers0