X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org X-Eon-Dm: dm0213 X-Eon-Sig: AQMoEGNQbF1ZSFqTDAIAAAAB,e9f16e809afcc1d3f7af1eda08773007 From: bob To: cygwin AT cygwin DOT com Subject: Fifo blocking and performance issues - some test code snips Date: Wed, 03 Oct 2012 11:44:24 -0400 Message-ID: <122663406.srZGqP3Ccr@bob-kubuntu> User-Agent: KMail/4.8.5 (Linux/3.2.0-31-generic; KDE/4.8.5; x86_64; ; ) MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.7.7855,1.0.431,0.0.0000 definitions=2012-10-03_02:2012-10-03,2012-10-02,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=1 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1203120001 definitions=main-1210030159 Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com I'm on the mailing list in digest mode, so this response may not get threaded correctly. Here is some basic test code which illustrates all the things I spoke about in my previous note. The Cygwin machine and the Linux machine are identical (I have a harddrive swap system). Notice that the Cygwin is 2 orders of magnitude slower. Also notice the "Resource temporarily unavailable" error occurring throughout the Cygwin output but never in the Linux output. Thanks again in advance for all your help on this problem. bob =========== begin sender.c =========== #include #include #include #include #include #include #include #include #include #include int blocked_read(int, char *, int); int main(int argc, char *argv[]) { char command[80]; char fifoname[80]; int fd=-1; int rfd; int i; int j; int *r; int bytesToGo; int numBytes; char buf[5]; char *p; int rc; struct timeb before; struct timeb after; int msec; printf("fifo sender starting\n"); sprintf(fifoname,"/tmp/fsender"); mkfifo(fifoname, 0666); chmod(fifoname, 0666); printf("starting receiver\n"); sprintf(command,"./receiver&"); rc=system(command); printf("receiver started\n"); sleep(2); fd=open(fifoname, O_RDWR|O_NONBLOCK); //fd=open(fifoname, O_RDONLY|O_NONBLOCK); rfd=open("/tmp/freceiver", O_WRONLY); ftime(&before); for(j=1; j<100; j++) { printf("j=%d\n",j); write(rfd,&j,sizeof(int)); numBytes=0; memset(buf,0,4); p=buf; for(i=0; i< 10; i++) { bytesToGo=sizeof(int) - numBytes; printf("bytesToGo=%d numBytes=%d\n",bytesToGo,numBytes); if(bytesToGo <= 0) break; rc=blocked_read(fd,p,bytesToGo); printf("sender rc[%d]=%d\n",i,rc); if(rc == 0) { printf("got eof\n"); // close(fd); // fd=open(fifoname, O_RDONLY); } else if(rc == -1) { printf("%s\n",strerror(errno)); } else { numBytes+=rc; p+=rc; } } //end for i printf("buf: 0x%X-%X-%X-%X\n",buf[0],buf[1],buf[2],buf[3]); r=(int *)buf; printf("reply[%d]=%d\n",j,*r); } // end for j ftime(&after); msec=(after.time - before.time)*1000 + (after.millitm - before.millitm); printf("%d messages took %d ms\n",j, msec); sleep(1); unlink(fifoname); unlink("/tmp/freceiver"); exit(0); } // end sender int blocked_read(int fd, char *buff, int size) { int rc; fd_set inset; FD_ZERO(&inset); FD_SET(fd, &inset); printf("send: before select\n"); select(fd+1, &inset, NULL, NULL, NULL); printf("send: before read\n"); rc=read(fd,buff,size); printf("send: read rc=%d\n",rc); return(rc); } // end blocked_read =========== end sender.c ============= =========== begin receiver.c ========= #include #include #include #include #include #include #include #include int blocked_read(int, char *, int); int main(int argc, char *argv[]) { char command[80]; char fifoname[80]; int fd; int rfd; int dummy; int i; int j; int k; int *r; int bytesToGo; int numBytes; char buf[4]; char *p; int rc; printf("fifo receiver starting\n"); sprintf(fifoname,"/tmp/freceiver"); mkfifo(fifoname, 0666); chmod(fifoname, 0666); fd=open(fifoname, O_RDWR | O_NONBLOCK); //fd=open(fifoname, O_RDONLY | O_NONBLOCK); for(k=0; k<99; k++) { numBytes=0; p=buf; for(i=0; i< 10; i++) { bytesToGo=sizeof(int) - numBytes; if(bytesToGo <= 0) break; // rc=read(fd,p,bytesToGo); rc=blocked_read(fd,p,bytesToGo); printf("recv rc[%d]=%d\n",i,rc); if(rc == 0) { printf("recv eof\n"); } else if(rc == -1) { printf("%s\n",strerror(errno)); } else { numBytes+=rc; p+=rc; } } // end for i r=(int *)buf; j=*r; printf("received[%d]=%d\n",k,j); j++; // sleep(1); rfd=open("/tmp/fsender", O_WRONLY); write(rfd,&j,sizeof(int)); close(rfd); } // end for k unlink(fifoname); exit(0); } // end receiver int blocked_read(int fd, char *buff, int size) { int rc; fd_set inset; FD_ZERO(&inset); FD_SET(fd, &inset); printf("recv: before select\n"); select(fd+1, &inset, NULL, NULL, NULL); printf("recv: before read\n"); rc=read(fd,buff,size); printf("recv: read rc=%d\n",rc); return(rc); } // end blocked_read =========== end receiver.c =========== =========== begin linux.out ========== sender fifo sender starting starting receiver receiver started fifo receiver starting recv: before select j=1 bytesToGo=4 numBytes=0 send: before select recv: before read recv: read rc=4 recv rc[0]=4 received[0]=1 recv: before select send: before read send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x2-0-0-0 reply[1]=2 j=2 bytesToGo=4 numBytes=0 send: before select recv: before read recv: read rc=4 recv rc[0]=4 received[1]=2 recv: before select send: before read send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x3-0-0-0 reply[2]=3 j=3 bytesToGo=4 numBytes=0 send: before select recv: before read recv: read rc=4 recv rc[0]=4 received[2]=3 recv: before select send: before read send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x4-0-0-0 reply[3]=4 ... j=94 bytesToGo=4 numBytes=0 recv: before read recv: read rc=4 recv rc[0]=4 received[93]=94 recv: before select send: before select send: before read send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x5F-0-0-0 reply[94]=95 j=95 bytesToGo=4 numBytes=0 recv: before read recv: read rc=4 recv rc[0]=4 received[94]=95 recv: before select send: before select send: before read send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x60-0-0-0 reply[95]=96 j=96 bytesToGo=4 numBytes=0 recv: before read recv: read rc=4 recv rc[0]=4 received[95]=96 recv: before select send: before select send: before read send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x61-0-0-0 reply[96]=97 j=97 bytesToGo=4 numBytes=0 recv: before read recv: read rc=4 recv rc[0]=4 received[96]=97 recv: before select send: before select send: before read send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x62-0-0-0 reply[97]=98 j=98 bytesToGo=4 numBytes=0 recv: before read recv: read rc=4 recv rc[0]=4 received[97]=98 recv: before select send: before select send: before read send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x63-0-0-0 reply[98]=99 j=99 bytesToGo=4 numBytes=0 recv: before read recv: read rc=4 recv rc[0]=4 received[98]=99 send: before select send: before read send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x64-0-0-0 reply[99]=100 100 messages took 12 ms =========== end linux.out ============ =========== begin cygwin.out ========= $ sender fifo sender starting starting receiver receiver started fifo receiver starting recv: before select j=1 bytesToGo=4 numBytes=0 send: before select recv: before read recv: read rc=4 recv rc[0]=4 received[0]=1 recv: before select send: before read send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x2-0-0-0 reply[1]=2 j=2 bytesToGo=4 numBytes=0 send: before select send: before read recv: before read recv: read rc=4 recv rc[0]=4 received[1]=2 recv: before select send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x3-0-0-0 reply[2]=3 j=3 bytesToGo=4 numBytes=0 send: before select send: before read recv: before read recv: read rc=4 recv rc[0]=4 received[2]=3 send: read rc=-1 sender rc[0]=-1 Resource temporarily unavailable bytesToGo=4 numBytes=0 send: before select recv: before select send: before read send: read rc=4 sender rc[1]=4 bytesToGo=0 numBytes=4 buf: 0x4-0-0-0 reply[3]=4 j=4 bytesToGo=4 numBytes=0 send: before select send: before read recv: before read recv: read rc=4 recv rc[0]=4 received[3]=4 send: read rc=-1 sender rc[0]=-1 Resource temporarily unavailable bytesToGo=4 numBytes=0 send: before select recv: before select send: before read send: read rc=4 sender rc[1]=4 bytesToGo=0 numBytes=4 buf: 0x5-0-0-0 reply[4]=5 j=5 bytesToGo=4 numBytes=0 send: before select send: before read recv: before read recv: read rc=4 recv rc[0]=4 received[4]=5 recv: before select send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x6-0-0-0 reply[5]=6 j=6 bytesToGo=4 numBytes=0 send: before select send: before read recv: before read recv: read rc=4 recv rc[0]=4 received[5]=6 recv: before select send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x7-0-0-0 reply[6]=7 ... j=90 bytesToGo=4 numBytes=0 send: before select send: before read recv: before read recv: read rc=4 recv rc[0]=4 received[89]=90 recv: before select send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x5B-0-0-0 reply[90]=91 j=91 bytesToGo=4 numBytes=0 send: before select send: before read recv: before read recv: read rc=4 recv rc[0]=4 received[90]=91 send: read rc=-1 sender rc[0]=-1 Resource temporarily unavailable bytesToGo=4 numBytes=0 send: before select recv: before select send: before read send: read rc=4 sender rc[1]=4 bytesToGo=0 numBytes=4 buf: 0x5C-0-0-0 reply[91]=92 j=92 bytesToGo=4 numBytes=0 send: before select send: before read recv: before read recv: read rc=4 recv rc[0]=4 received[91]=92 recv: before select send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x5D-0-0-0 reply[92]=93 j=93 bytesToGo=4 numBytes=0 send: before select send: before read recv: before read recv: read rc=4 recv rc[0]=4 received[92]=93 recv: before select send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x5E-0-0-0 reply[93]=94 j=94 bytesToGo=4 numBytes=0 send: before select send: before read recv: before read recv: read rc=4 recv rc[0]=4 received[93]=94 send: read rc=-1 sender rc[0]=-1 Resource temporarily unavailable bytesToGo=4 numBytes=0 send: before select recv: before select send: before read send: read rc=4 sender rc[1]=4 bytesToGo=0 numBytes=4 buf: 0x5F-0-0-0 reply[94]=95 j=95 bytesToGo=4 numBytes=0 send: before select send: before read recv: before read recv: read rc=4 recv rc[0]=4 received[94]=95 recv: before select send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x60-0-0-0 reply[95]=96 j=96 bytesToGo=4 numBytes=0 send: before select send: before read recv: before read recv: read rc=4 recv rc[0]=4 received[95]=96 recv: before select send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x61-0-0-0 reply[96]=97 j=97 bytesToGo=4 numBytes=0 send: before select send: before read recv: before read recv: read rc=4 recv rc[0]=4 received[96]=97 send: read rc=-1 sender rc[0]=-1 Resource temporarily unavailable bytesToGo=4 numBytes=0 send: before select recv: before select send: before read send: read rc=4 sender rc[1]=4 bytesToGo=0 numBytes=4 buf: 0x62-0-0-0 reply[97]=98 j=98 bytesToGo=4 numBytes=0 send: before select send: before read recv: before read recv: read rc=4 recv rc[0]=4 received[97]=98 recv: before select send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x63-0-0-0 reply[98]=99 j=99 bytesToGo=4 numBytes=0 send: before select send: before read recv: before read recv: read rc=4 recv rc[0]=4 received[98]=99 send: read rc=4 sender rc[0]=4 bytesToGo=0 numBytes=4 buf: 0x64-0-0-0 reply[99]=100 100 messages took 967 ms done =========== end cygwin.out =========== -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple