Re: "ls -l" command and performance of sftp

This is a discussion on Re: "ls -l" command and performance of sftp within the OpenSSH Development forums, part of the Networking and Network Related category; This is a multi-part message in MIME format. ------=_NextPart_000_007B_01C675BA.F519E680 Content-Type: text/plain; format=flowed; charset="iso-...


Go Back   Usenet Forums > Networking and Network Related > OpenSSH Development

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-12-2006
ponraj
 
Posts: n/a
Default Re: "ls -l" command and performance of sftp

This is a multi-part message in MIME format.

------=_NextPart_000_007B_01C675BA.F519E680
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
reply-type=original
Content-Transfer-Encoding: 7bit

Hi all,

Patch to cache group and userids is attched along with this mail. The patch
looks up the cache first before proceeding with getgrgid,getpwuid calls and
thus reduces the amount of lookups and increases preformance in environments
such as LDAP database.

--
M.P

----- Original Message -----
From: ponraj
To: openssh-unix-dev@mindrot.org
Sent: Saturday, May 06, 2006 10:01 AM
Subject: "ls -l" command and performance of sftp


Hi all,

I am using OpenSSH4.3p2. User database is stored in LDAP server.When I tried
to list about 400 files using "ls -l" command in ftp and sftp, I observed
that sftp took considerable amount of time greater than ftp. I suspect sftp
does not cache the username and groupname lookups and makes fresh calls to
getpwuid(), getgrgid() functions for each file that makes its performance
worse. Any comments ?

--
M.P

------=_NextPart_000_007B_01C675BA.F519E680
Content-Type: text/plain; format=flowed; name="sftp_ls.txt";
reply-type=original
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="sftp_ls.txt"

--- sftp-common.c 2006-05-11 22:36:23.000000000 -0700
+++ sftp-common.c_cache 2006-05-11 22:52:54.000000000 -0700
@@ -34,6 +34,9 @@
#include "sftp.h"
#include "sftp-common.h"

+#define GROUP_CACHE_SIZE 5
+#define PW_CACHE_SIZE 5
+
/* Clear contents of attributes structure */
void
attrib_clear(Attrib *a)
@@ -170,6 +173,65 @@
/* NOTREACHED */
}

+struct group* getgrgid_cached(gid_t gid)
+{
+ static struct group *groupcache =3D NULL;
+ struct group *result;
+ int i;
+
+ if (groupcache =3D=3D NULL) {
+ groupcache =3D (struct group *)calloc(GROUP_CACHE_SIZE, =
sizeof(struct group));
+ }
+
+ for (i =3D 0; i < GROUP_CACHE_SIZE; i++) {
+ if (groupcache[i].gr_gid =3D=3D gid && =
groupcache[i].gr_name !=3D NULL) {
+ return &(groupcache[i]);
+ }
+ }
+
+ result =3D getgrgid(gid);
+ if (result !=3D NULL && result->gr_name !=3D NULL) {
+ for (i =3D 0; i < GROUP_CACHE_SIZE; i++) {
+ if (groupcache[i].gr_name =3D=3D NULL) {
+ groupcache[i].gr_gid =3D gid;
+ groupcache[i].gr_name =3D =
strdup(result->gr_name);
+ }
+ }
+ }
+ return result;
+}
+
+struct passwd* getpwuid_cached(uid_t uid)
+{
+ static struct passwd *pwcache =3D NULL;
+ struct passwd *result;
+ int i;
+
+ if (pwcache =3D=3D NULL) {
+ pwcache =3D (struct passwd *)calloc(PW_CACHE_SIZE, =
sizeof(struct passwd));
+ }
+
+ for (i =3D 0; i < PW_CACHE_SIZE; i++) {
+ if (pwcache[i].pw_name !=3D NULL && pwcache[i].pw_uid =
=3D=3D uid) {
+ return &(pwcache[i]);
+ }
+ }
+
+ result =3D getpwuid(uid);
+ if (result !=3D NULL && result->pw_name !=3D NULL) {
+ for (i =3D 0; i < PW_CACHE_SIZE; i++) {
+ if (pwcache[i].pw_name =3D=3D NULL) {
+ pwcache[i].pw_uid =3D uid;
+ pwcache[i].pw_name =3D =
strdup(result->pw_name);
+ }
+ }
+ }
+ return result;
+}
+
+
/*
* drwxr-xr-x 5 markus markus 1024 Jan 13 18:39 .ssh
*/
@@ -184,13 +246,13 @@
char buf[1024], mode[11+1], tbuf[12+1], ubuf[11+1], gbuf[11+1];

strmode(st->st_mode, mode);
- if (!remote && (pw =3D getpwuid(st->st_uid)) !=3D NULL) {
+ if (!remote && (pw =3D getpwuid_cached(st->st_uid)) !=3D NULL) {
user =3D pw->pw_name;
} else {
snprintf(ubuf, sizeof ubuf, "%u", (u_int)st->st_uid);
user =3D ubuf;
}
- if (!remote && (gr =3D getgrgid(st->st_gid)) !=3D NULL) {
+ if (!remote && (gr =3D getgrgid_cached(st->st_gid)) !=3D NULL) {
group =3D gr->gr_name;
} else {
snprintf(gbuf, sizeof gbuf, "%u", (u_int)st->st_gid);

------=_NextPart_000_007B_01C675BA.F519E680
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
http://www.mindrot.org/mailman/listi...enssh-unix-dev

------=_NextPart_000_007B_01C675BA.F519E680--

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:09 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0