Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am frustrated about the latency of random reading from a non-ssd disk. Based on results from following test program, it speeds ~16 ms for a random read of just 512 bytes without help of os cache.

I tried changing 512 to larger values, such as 25k, and the latency did not increase as much. I guess it is because the disk seek dominates the time.

I understand that random reading is inherently slow, but just want to be sure that ~16ms is reasonable, even for non-ssd disk.

#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/unistd.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char** argv) {
  int fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "Failed open %s\n", argv[1]);
    return -1;
  const size_t count = 512;
  const off_t offset = 25990611 / 2;
  char buffer[count] = { '\0' };
  struct timeval start_time;
  gettimeofday(&start_time, NULL);
  off_t ret = lseek(fd, offset, SEEK_SET);
  if (ret != offset) {
    perror("lseek error");
    return -1;
  ret = read(fd, buffer, count);
  if (ret != count) {
    fprintf(stderr, "Failed reading all: %ld\n", ret);
    return -1;
  struct timeval end_time;
  gettimeofday(&end_time, NULL);
  printf("tv_sec: %ld, tv_usec: %ld\n",
         end_time.tv_sec - start_time.tv_sec,
         end_time.tv_usec - start_time.tv_usec);
  return 0;
share|improve this question
What OS distribution, kernel and version? – ewwhite Nov 28 '12 at 3:08
What hard drive? – Michael Hampton Nov 28 '12 at 3:15
up vote 5 down vote accepted

Sure - you'll want to take a look at your drive's seek time specification, but 16ms is well within the realm of "normal" for spinning magnetic media.

share|improve this answer

If you're doing anything that will end up in production, there should be a layer of caching, a real RAID controller and other factors in play. What are you running on? What is the point of this exercise? Can you elaborate on the details of this setup?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.