Re: NNTPC: halfsies working remoteIdleTimeout, beta-ish

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Tue, 4 Aug 1998, Aaron Nabil wrote:

> Here are some patches to get remoteIdleTimeout working.  Don't bother

  Funny... I've been working on this problem for a couple of days...

> with them unless you are using multiple servers, as nntpc just blocks
> on user input and will never notice the timeout with only one server.  So

  Not quite.  The timeout is still useful with one server, because 
sucessive commands may not send data to the server.  For example, if
sucessive commands happen to be served from cache, which is actually very
common.  For example, GROUP data expires relatively quickly so often this
is the first thing nntpcache asks the remote server for.  But chances are
the user will request articles that have already been read by someone
else, so these will come out cache.  While processing these sucessive
ARTICLE commands, the connection to the remote server will be dropped.

> at the moment it will only timeout the "other" servers, assuming
> the user is still active.
> 
> You'd be interested in this, say, if your upstream charges you for
> incoming connections and you want to timeout remote connections 
> quickly.
> 
> I'm working on non-blocking I/O for the user reads, but don't have
> time to finish it today.  This will make it work properly even with
> one server.

  I've got rough code for this too.  It is a partial solution, and even
then only gives you an approximation, especially when the remote server is
very fast, and your client very slow.

  My ultimate goal is connection re-use.  Lots of the connection state
handling code is done, but control of all server connections need to be
handled by one process, and that will be tough.  Perhaps the remote
connections can even be pre-opened for faster access by clients (as often
remote servers are slow to accept connections).

> Consider this "beta" quality only.  I'm not quite sure I am resetting the
> idle time in enough places (or maybe too many places).
> 
> (the blank lines are other, local changes)
> 
> diff -c -r nntpcache-2.3.3b2/src/nntpcache.c nntpcache-2.3.3b2-local/src/nntpcache.c
> ***************
> *** 825,830 ****
> --- 836,852 ----
>   		list->article_timeout = article_timeout;
>   		list->overview_fmt_timeout = con->overviewFmtTimeout;
>   		list->fd=-1;
> + 		list->last_active_time = 0;		/* -an */
> + 		list->group = NULL;			/* -an */
> + 		list->group_actual = NULL;		/* -an */

  This isn't necessary as the entire structure is zeroed before use.

> +
> +
> +
> +
> +
> +
> +
> +
>   	}
>   	if (ferror(fp))
>   	{
> ***************
> *** 902,914 ****
>   	time_t ti = time(NULL);
>   	for (p=ServerList; p; p=p->next)
>   		if (p->last_active_time &&
> ! 		    ti - p->last_active_time > con->remoteIdleTimeout)
>   			detachServer(p);
>   }
>   
>   static void emit_banner(bool post_ok)
>   {
>   	emitf ("%d %s NNTPcache server V%s [see www.nntpcache.org] (c) 1996-1998 Julian Assange <proff@iq.org> %s ready (posting %s).\r\n", post_ok? NNTP_POSTOK_VAL: NNTP_NOPOSTOK_VAL, Host, VERSION, __DATE__, post_ok? "ok": "not permitted");
>   }
>   
>   static bool relay_unknown (char *buf)
> --- 924,942 ----
>   	time_t ti = time(NULL);
>   	for (p=ServerList; p; p=p->next)
>   		if (p->last_active_time &&
> ! 		    ti - p->last_active_time > con->remoteIdleTimeout) {
> ! 			logd (("dropping idle server %s after %d seconds idle (limit %d)", p->host, ti - p->last_active_time, con->remoteIdleTimeout));
>   			detachServer(p);
> + 		    }
>   }
>   
>   static void emit_banner(bool post_ok)
>   {
> +
>   	emitf ("%d %s NNTPcache server V%s [see www.nntpcache.org] (c) 1996-1998 Julian Assange <proff@iq.org> %s ready (posting %s).\r\n", post_ok? NNTP_POSTOK_VAL: NNTP_NOPOSTOK_VAL, Host, VERSION, __DATE__, post_ok? "ok": "not permitted");
> +
> +
> +
>   }
>   
>   static bool relay_unknown (char *buf)
> diff -c -r nntpcache-2.3.3b2/src/sockets.c nntpcache-2.3.3b2-local/src/sockets.c
> *** nntpcache-2.3.3b2/src/sockets.c	Sun Aug 02 13:35:03 1998
> --- nntpcache-2.3.3b2-local/src/sockets.c	Tue Aug 04 13:49:05 1998
> ***************
> *** 95,100 ****
> --- 95,104 ----
>   	{
>   		fclose(scfg->fh);
>   		scfg->fd = -1;
> + #ifdef 0
> + 		/* don't need to do either of these here, both
> + 		   will get free'd before they are re-used. Also scfg->group
> + 		   needs to be set for the re-connect to work after a timeout.  -an  */

  I think scfg_actual should be free'ed.  This ensures that further
functions don't think the server is still bound to that group.

>   		if (scfg->group_actual)
>   		{
>   			free(scfg->group_actual);
> ***************
> *** 105,110 ****
> --- 109,115 ----
>   			free(scfg->group);
>   			scfg->group= NULL;
>   		}
> + #endif
>   	}
>   }
>   
> ***************
> *** 114,119 ****
> --- 119,125 ----
>   	char buf[MAX_LINE];
>   	time_t now;
>   	assert(scfg);
> + 	scfg->last_active_time = time(NULL);		/* -an */
>   	/*
>   	 * see if we are already attached
>   	 */
> ***************
> *** 250,255 ****
> --- 279,285 ----
>   			return 0;
>   	}
>   	buf[cc] = '\0';
> + 	scfg->last_active_time = time(NULL);		/* -an */
>   	server_up (scfg);
>   	scfg->share->bytes_from += cc;
>   	if (con->statistics)
> 
> 
> 

  Hmm... I'd put updating of scfg->last_active_time into server_up
instead.

  There is also a bug in here.  You need to set last_active_time to zero
in detachServer or drop_idle_servers() will keep trying to detach the same
servers over and over again.

  I'll post my patches for my solution a little later.  I'll make sure
they apply to 2.3.3b3.  They don't include any local stuff, so the diff is
very small.  However, I've done quite extensive testing with patches, and
see occasional bogus "no such group" errors.  I suspect that something,
somewhere is not restoring state.

Tom
  


[Index of Archives]     [Yosemite]     [Yosemite Campsites]     [Bugtraq]     [Linux]     [Trn]

Powered by Linux