All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vivek Trivedi <vtrivedi018@gmail.com>
To: "Myklebust, Trond" <Trond.Myklebust@netapp.com>,
	linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	Namjae Jeon <linkinjeon@gmail.com>
Cc: vtrivedi018@gmail.com, amit.sahrawat83@gmail.com
Subject: NFS: low read/stat performance on small files
Date: Fri, 23 Mar 2012 16:47:04 +0530	[thread overview]
Message-ID: <CAKX=r8A90b25VKXC1qtAota9DqDrj37xFT511DuvrZ=1Eux6Xw@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1604 bytes --]

Hi,
we are facing below 2 performance issue on NFS:

1. Read speed is low for small files
==========================

[ Log on NFS Client]

$ echo 3 > /proc/sys/vm/drop_caches
$ dd if=200KBfile.txt of=/dev/null
400+0 records in
400+0 records out
204800 bytes (200.0KB) copied, 0.027074 seconds, 7.2MB/s


Read speed for 200KB file is 7.2 MB


[ Log on NFS Client]

$ echo 3 > /proc/sys/vm/drop_caches
$ dd if=100MBfile.txt of=/dev/null
204800+0 records in
204800+0 records out
104857600 bytes (100.0MB) copied, 9.351221 seconds, 10.7MB/s

Read speed for 100MB file is 10.7 MB

As you see read speed for 200KB file is only 7.2MB/sec while it is
10.7 MB/sec when we read 100MB file.
Why there is so much difference in read performance ?
Is there any way to achieve high read speed for small files ?


2. Read/stat for a directory tree is slow on NFS than local
==========================================

we have lot of *.jpg files in a directory. If we try to "stat" and
"read" from this directory,
 performannce is very slow on NFS Client compared to Local(NFS server)
"stat" and "read"


[ Log on Local (NFS Server) ]

$ echo 3 > /proc/sys/vm/drop_caches
$ ./stat_read_files_test ./lot_of_jpg_files/
 Time Taken : 9288 msec


[ Log on NFS Client]

$ echo 3 > /proc/sys/vm/drop_caches
$ ./stat_read_files_test ./lot_of_jpg_files/
 Time Taken : 19966 msec

As you see, on NFS client time taken is almost *double* than that of
local(NFS server)
We are using UDP with rsize,wsize=32k on 100MB ethernet link.
I am attaching read/stat testcase.

Is there any way to improve this performance ?


Thanks,
Vivek

[-- Attachment #2: traversepath.c --]
[-- Type: text/x-csrc, Size: 2188 bytes --]

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

#define BUFFERSIZE 4096
char READBUFFER[BUFFERSIZE];

#include <dirent.h>
int TraversePath(char *path)
{
	struct dirent *d = NULL;
	DIR *dir = NULL; /* pointer to directory head*/
	char buf[255]={0}; /* buffer to store the complete file/dir name*/
	struct stat statbuf; /* to obtain the statistics of file/dir */
	int retval =0; /* to hold the return value*/
	int fd = 0;

	memset(&statbuf,0,sizeof(struct stat)); 

	retval = stat(path,&statbuf);

	/* if the stat returned success and path provided is of valid directory*/
	if(S_ISDIR(statbuf.st_mode) && (retval==0))
	{
		dir = opendir(path); /* open the directory*/	
		/* reads entry one by one*/
		while((d = readdir(dir)) != NULL)
		{
			if((strcmp(d->d_name,".")!=0) && (strcmp(d->d_name,"..")!=0))
			{
				sprintf(buf,"%s/%s",path,d->d_name);
				retval = stat(buf,&statbuf);
				if(retval == 0)
				{
					if(!S_ISDIR(statbuf.st_mode))
					{		
						/* This is file - read from this, Since read ahead 
						 * will itself bring 128KB, so we can just read 4KB
						 * to start with */
						fd = open(buf,O_RDONLY,(mode_t)777);
						if(fd) {
							read(fd, READBUFFER, BUFFERSIZE);
							close(fd);	
						}
					}
					else
					{
						/*
						   This is a directory, recursive search in it
						   once all files are read
						 */
						TraversePath(buf);
					}
				}
				else
				{
					perror("stat failed\n");
				}
			}
		}
	}
	else
	{
		perror("Failed");
	}	
	return retval;
}

int main(int argc, char **argv)	
{
	struct timeval rv;
	struct timeval rv1;

	int stat_time = 0;

	if(argc < 2) {
		printf("./TraversePath <path> \n");
		return 0;
	}	

	//Traverse the complete path inside timing unit
	gettimeofday(&rv, 0);
	TraversePath(argv[1]);
	gettimeofday(&rv1, 0);

	stat_time = (rv1.tv_sec * 1000 + rv1.tv_usec / 1000) - (rv.tv_sec * 1000 + rv.tv_usec / 1000);

	printf(" Traversed Path : %s \n", argv[1]);
	printf(" Time Taken : %d msec \n",stat_time);

	return 0;
}

             reply	other threads:[~2012-03-23 11:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-23 11:17 Vivek Trivedi [this message]
2012-03-23 11:49 ` NFS: low read/stat performance on small files Jim Rees
2012-03-23 12:16   ` Myklebust, Trond
2012-03-23 12:16     ` Myklebust, Trond
2012-03-24  7:02     ` Namjae Jeon
2012-03-29 15:52     ` Kevin Graham
2012-03-29 16:16       ` Myklebust, Trond

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKX=r8A90b25VKXC1qtAota9DqDrj37xFT511DuvrZ=1Eux6Xw@mail.gmail.com' \
    --to=vtrivedi018@gmail.com \
    --cc=Trond.Myklebust@netapp.com \
    --cc=amit.sahrawat83@gmail.com \
    --cc=linkinjeon@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.