Thread View: news.software.readers
2 messages
2 total messages
Started by Bryan T Dongray
Fri, 27 Aug 1993 20:56
tin 12x speed up
Author: Bryan T Dongray
Date: Fri, 27 Aug 1993 20:56
Date: Fri, 27 Aug 1993 20:56
179 lines
5090 bytes
5090 bytes
I thought tin was a bit slow too, especially in the indexing part,
so I used prof, and found tin to spend 36% in the open system call.
Using trace I saw tin basically for each article:
created a temporary
wrote the HEAD part in it
close it
opened temporary for reading
unlinked it - a UNIX common trick
read it into memory
parsed it
closed it
Seemed to me a bit of an overkill on file I/O.
My first attempt was a bit messy a still used a temporary, but kept it
open (for update) and used ftruncate(), which some system do not have.
I then realised why have a temporary at all, get it straight into memory!
After 30 minutes of recoding...
I did some timings on a group with 1 article 483 non-existant articles
then 600 real articles:
Version skipping 483 reading total
tin 1.2 4 84 88
first attempt 4 36 40
memory version 4 7 11
Times are in seconds, by my wristwatch.
NOTE: 84 to 7 = 12x faster!
I tried it on other groups without that large non-existant article
gap, and it was just amazing, it really was 12x faster!
I have tested it a bit, and it all seems ok, but you never know.
tin really should use NEXT to skip to the next article, but
at about 125 per second on my system, I suppose it is not too slow.
Here are the code changes to my version of tin (1.2 PL 1 [UNIX]):
In proto.h:
line 31 change:
extern int parse_headers(FILE *fp, struct article_t *h);
to
extern int parse_headers(char *memp, struct article_t *h);
line 242 change:
extern FILE *open_header_fp(long art);
to
extern char *open_header_fp(long art);
line 672 change:
extern FILE *open_header_fp();
to
extern char *open_header_fp();
In art.c
line 249 change:
FILE *fp;
to:
char *memp;
line 301 change:
if ((fp = open_header_fp (art)) == (FILE *) 0) {
to:
if ((memp = open_header_fp (art)) == (char *) 0) {
line 317 change:
if (! parse_headers (fp, &arts[top])) {
to:
if (! parse_headers (memp, &arts[top])) {
delete lines 320 and 324 each with:
fclose (fp);
line 460/461 change:
int parse_headers (fp, h)
FILE *fp;
to:
int parse_headers (buf, h)
char *buf;
delete line 464 with:
char buf[HEADER_LEN];
ie remove the above line.
and change lines 481 to 496 from:
while ((n = fread (buf, 1, sizeof (buf)-1, fp)) == 0) {
if (feof (fp)) {
break;
}
#ifdef EINTR
if (ferror (fp) && errno != EINTR) {
#else
if (ferror (fp)) {
#endif
break;
}
clearerr (fp);
}
to:
n = strlen(buf);
yes, a big change there!
In open.c
lines 504 to 532, the whole function open_header_fp() change to:
char *open_header_fp (art)
long art;
{
char buf[NNTP_STRLEN];
static char mem[HEADER_LEN];
char *p;
int fd, len;
if (read_news_via_nntp &&
active[my_group[cur_groupnum]].type == GROUP_TYPE_NEWS) {
#ifdef NNTP_ABLE
sprintf(buf, "head %ld", art);
debug_nntp ("open_header_fp", buf);
put_server (buf);
if (get_respcode () != OK_HEAD) {
debug_nntp ("open_header_fp", "NOT_OK_HEAD");
return (char *) 0;
}
debug_nntp ("open_header_fp", "OK_HEAD");
p=mem;
while (1) {
if (get_server (p, HEADER_LEN-(p-mem)-1) == -1) {
error_message (txt_connection_to_server_broken, "");
tin_done (1);
}
if (strcmp (p, ".") == 0) { /* end of text */
break;
}
if (p[0] == '.') { /* reduce leading .'s */
while (p[1]) {
p[0]=p[1];
p++;
}
} else {
while (*p)
p++;
}
*p++='\n';
*p='\0';
}
#else
return (char *) 0;
#endif
} else {
sprintf (buf, "%ld", art);
if ((fd=open (buf, 0)) == -1)
return (char *)0;
len=read(fd, mem, HEADER_LEN);
close(fd);
if (len < 1)
return (char *)0;
}
return mem;
}
Hopefully, some future PL of tin, will use this "memory" version
or get based on the concept.
Note this only does increase the speed of NNTP access, and I have
only tested it for a few hours, so don't blame me for bugs, just
tell me, and I'll fix them and repost.
Note I use:
SunOS 4.1.3
-DNNTP_ONLY
Hope this helps out lots of you out there.
Bryan Dongray
--
| _____ |
|-. | .-| <btd@uk.cray.com>
`-' | `-'
Re: tin 12x speed up
Author: Mitra
Date: Mon, 30 Aug 1993 17:41
Date: Mon, 30 Aug 1993 17:41
4 lines
725 bytes
725 bytes
It would be great if someone making these edits could post a patch file - - Mitra
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads