Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
127 user(s) are online (68 user(s) are browsing Forums)

Members: 0
Guests: 127

more...

Headlines

 
  Register To Post  

Two network coding problems: Roadshow / WaitSelect delays.
Home away from home
Home away from home


See User information
I'm coding a network utility to share the mouse and keyboard between two Amiga OS4 machines.

As such I need to send messages back and forth between the machines in a timely fashion and in fact it's working rather well *most* of the time, but I'm seeing two issues.

1. If I have to interupt and restart the server, the I see that the listen socket hangs arround arround for more than a minute after I closed it down. Is this normal? It means the server can't be restarted, as it can't bind to the port number. This is largely only a problem when testing as when running for real the server would rarely need a restart, but I want to be sure that I'm not missing something in the shutdown procedure. I'm closing the socket with ISocket->CloseSocket() and ofcourse I close bsdsocket.library at prpgram exit. (Note this is not an inetd style server so it';s not the inted thing holding the scocket open).

2. This is the more complex one I think:

90% or more of the time the return trip of the server sending a command to and getting a response from the client takes at most 50ms most oftem much less. This allows quite smooth operation of the mouse on the remote (client) machine. Every now and again though I'm getting amassive delay of more than 1300 ms this causes quite a stutter in the mouse as you might imagine.

I'm trying work out why this is happening, and have added lots of timing debug, it seems to me to be that the delay is at the network level.

My packets of info are short eg "RAWMOUSE %hu %hu %hd %hd" but it seems occasionaly the client has to wait up a second to recieve the packet (and this is across the LAN ).

Some simplified code:

Server SendMsg() code:
struct TimeVal tv;

        
tv.Seconds 2;
        
tv.Microseconds  0;
        
int n 0;
        if((
ISocket->WaitSelect(FD_SETSIZE,NULL,&writefds,NULL,&tv,NULL)) != -1)
        {

                if(
0)
                {
                        if(     
ISocket->send(sock,(APTR)msg,strlen(msg) + 1,0) == -1)
                        {
                                
DropClient(server,sock);
                                return 
FALSE;
                        }
                }
                else
                {
                        
/* Timeout increment dropped packets */
                        
printf("Send Timeout\n");
                        
DropClient(serversock);
                        return 
FALSE;
                }
        }
        else
        {
                
printf("WaitSelect error %s %d\n",__FUNCTION__,__LINE__);
                return 
FALSE;
        }

        
/* autodoc says not to assume timevalue unchnaged so reset */
        
tv.Seconds 2;
        
tv.Microseconds  0;

        if((
ISocket->WaitSelect(FD_SETSIZE,&readfds,NULL,NULL,&tv,NULL)) != -1)
        {

                if(
0)
                {
                        
TEXT buffer[512];
                        if(     
ISocket->recv(sock,buffer,sizeof(buffer),0) == -1)
                        {
                                
DropClient(server,sock);
                                return 
FALSE;
                        }
                        
enum Protocols ID IdentifyProtocol(buffer);

                        switch(
ID)
                        {

                        ...
                        ...
                        ...
                        
Code Handleing response here
                        
...
                        ...
                        ...

                        }
                }
                else
                {
                        
/* Timeout increment dropped packets */
                        
printf("Receive Timeout respoe to %s\n",msg);
                        
DropClient(server,sock);
                        return 
FALSE;
                }
        }
        else
        {
                
printf("WaitSelect error %s %d\n",__FUNCTION__,__LINE__);
                return 
FALSE;
        }
       return 
TRUE;

}


Client loop:
while(alive)
{
   
fd_set readfds;
   
FD_ZERO(&readfds);
   
FD_SET(sock,&readfds);
   
struct TimeVal tv;
   
tv.Seconds 4;
   
tv.Microseconds 0;

   
int n 0;
   if((
ISocket->WaitSelect(1,&readfds,NULL,NULL,&tv,NULL)) != -1)
   {

           if(
0)
           {
                   
int len;
                   if((
len ISocket->recv(sock,buffer,sizeof(buffer) -1,0)) > 0)
                   {


                           
buffer[len] = 0;
                           
enum Protocols ID IdentifyProtocol(buffer);
                           switch(
ID)
                           {
                                   case 
RAWKEY:
                                   {
                                           
SendResponse(sock,(APTR)RECEIVED_MSG,strlen(RECEIVED_MSG) + 1);

                                           
/* Do stuff include input.device IO */
                                           
break
                                   }
                                   ...
                                   ...
                                   ...
                                   ...
                                   
Handle Other stuff
                                   
...
                                   ...
                                   ...
                           }
                   }
                   else
                   {
                           
/*Could be Socket error or shutdown we don't care */
                           
printf("sock error %ld\n",ISocket->Errno());
                           
alive 0;
                           
reconnect 1;
                   }
           }
           else
           {
                   
/* Timeout */
                    
printf("Connection time out\n");
                    
alive 0;
                    
reconnect 1;
           }
   }


Where SendResponse() in the client is thin wrapper for ISocket->send() lik so:

static VOID SendResponse(int sockAPTR responsesize_t length)
{
        if(
sendbye)
        {
                
TEXT buffer[24];
                
sprintf(buffer,BYECLIENT_MSG,name?name:"");
                
ISocket->send(sock,buffer,strlen(buffer) + 1,0);
                
alive FALSE;
                
sendbye 0;
        }
        else
        {
                
ISocket->send(sock,response,length,0);
        }
}


From my timing tests (with alot of unshown dbeug printouts inserted into the above code, it seems the delay occurs in Server at the second Wait slect and in the client at the first, which suggest the dealy is after te send() in the server, but that function returns promptly (typically 1 ms or less)

Timeing was done with ReadEClock calls.

I can't see any reason to get these stalls in the data flow, perhaps I'm not setting some options that would help? I'm just the using sockets 'as they come'.

Go to top
Re: Two network coding problems: Roadshow / WaitSelect delays.
Just can't stay away
Just can't stay away


See User information
It might not be anything to do with that at all, the X1000 stalls like that even when copying or moving files. it's more noticable in dopus 4 or 5, copy a few thousand files and it'll copy a few hundred, puase, copy a few hundred, pause etc. not tried filer to see if it does it too.
Runnig batch scripts from cli does it. no idea if it's drive access, memory control or something else, sheduler maybe but there is something that causes a regular pause.

Amiga user since 1985
AOS4, A-EON, IBrowse & Alinea Betatester

Ps. I hate the new amigans website. <shudder>
Go to top
Re: Two network coding problems: Roadshow / WaitSelect delays.
Home away from home
Home away from home


See User information
@Severin

Hmm, well it doesn't matter which way round the server and client are I get the same behaviour. Maybe I need a tester with two SAMs (or any two machines without an X1000 involved).



Go to top
Re: Two network coding problems: Roadshow / WaitSelect delays.
Just can't stay away
Just can't stay away


See User information
I don't know much about network programming so I can only offer a few novice suggestions. Does the server shutdown delay occur even if the client has never connected to the server. If not, maybe there is some message not being responded at the client or server end. Does your server have plenty of stack space?

There is TFTPserver written by Olaf Barthel at OS4Depot which includes the sources that might offer some hints. Maybe you could check if that server also has a shutdown delay to confirm it's not a problem in your code.

I copied the contents of TBImages: to ram: (5000+ files) and can't confirm the file copying delay with Dopus4 that Severin mentions. However, that might depend on how many programs etc. that are running concurently on an X1000 system. Have you tried your server by booting with a minimal startup-sequence to rule out interference from other software?

Amiga X1000 with 2GB memory & OS 4.1FE + Radeon HD 5450

Go to top
Re: Two network coding problems: Roadshow / WaitSelect delays.
Just can't stay away
Just can't stay away


See User information
@broadblues

Quote:
Maybe I need a tester with two SAMs (or any two machines without an X1000 involved).
/me raises hand.

I've got, on one LAN, a Sam 460ex, a Sam 440ep, an A1 XE G4, an A1 XE G3, and an A1200 BPPC/BVision - apart from the X1000.

Guess I could run a few test shots for you on various pairs of those.

Best regards,

Niels

Go to top
Re: Two network coding problems: Roadshow / WaitSelect delays.
Home away from home
Home away from home


See User information
@broadblues



I've added extra debug to track the individual events and so can see the pause occurs between the send() on the server side and the unblocking od WaitSelect() on the client side.

Server side:
Timer is reset before first waitselect()

<pre>
SendMsg sock 1 RAWMOUSE 255 32768 3 3 1327 7154928447481
line 140 1 (after writefd waitslect)
line 150 2 (after send() )
line 173 5 (after readfd waitslect)
leaving SendMsg sock 1 RAWMOUSE 255 32768 3 3 1327 7154932925036 6
SendMsg sock 1 RAWMOUSE 255 32768 4 2 1328 7154933511591
line 140 1 (after writefd waitselect)
line 150 2 (after send) **********
line 173 1127 (after readfd waitselect)
leaving SendMsg sock 1 RAWMOUSE 255 32768 4 2 1328 7155760415231 1127

</pre>

On client:

Timer is reset just before incoming WaitSelect()

<pre>

line 278 10 (after readfds WaitSelect)
line 285 10 RAWMOUSE 255 32768 3 3 1327 (after recv)
line 337 11 RAWMOUSE 255 32768 3 3 1327 (after input devce io)
line 358 12 RAWMOUSE 255 32768 3 3 1327 (after send resposnse)
line 278 1126 (after readfs waitSelect) *******
line 285 1126 RAWMOUSE 255 32768 4 2 1328 (after recv)
line 337 1127 RAWMOUSE 255 32768 4 2 1328 (after input device io)
line 358 1128 RAWMOUSE 255 32768 4 2 1328 (after send response)

</pre>

Based on where those ****** lines are the client is clearly waiting a second orso for the data sent.

As you can see from the event numbers 1000s of events (1327 + othe event types in this case) go through normally before the spurious delay.

I don't know if this helps any give me assistance but it helps me think through what happening....

Go to top
Re: Two network coding problems: Roadshow / WaitSelect delays.
Home away from home
Home away from home


See User information
@broadblues
After checking further, I realised that when the server sent the BYE messeage to th client, the client was sending an aknowledgement that the sever didn't read, resulting in left over data on the socket. Tidied that up and both server and client exit cleanly.

So Issue 1 solved.

Go to top
Re: Two network coding problems: Roadshow / WaitSelect delays.
Home away from home
Home away from home


See User information
@broadblues

Found tcpdump, comes as standard with roadshow, did some logging at both ends and I see that the delay is caused a dropped packet and a TCP retry, which reties after 1.5 secs or so, I caught one in each direction.

Can this be configured to a shorter interval? (Is that a good idea any way? )

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project