Re: Efficient scather-gather-copy
- From: Tim Roberts <spamtrap@xxxxxxxxxx>
- Date: Sat, 15 Apr 2006 03:09:37 GMT
Hynek Schlawack <spamtrap@xxxxxxxxxx> wrote:
It's UNIX and yet filtering is simply too slow. I'd rather use memcpy()
than external programs.
I'd just like to emphasize the "rather" part, because this is likely to be
a personal preference issue, rather than a proven performance problem.
Remember that Unix filters in a pipeline do not pass through the file
system.
Well, I'm getting it as a buffer and anything that remotely could
involve access to file systems is out of question.
Imagine dozens of mails per _second_ that want to be
processed. Probably, memcpy() might be fast enough on a decent machine,
however it would definitely be a bottleneck.
Have you done the math? The typical e-mail is about 20k bytes long. Dozens
of mails per second would make it hundreds of kilobytes per second, perhaps
up to a megabyte per second.
That's trivial for a file system, and nothing at all for memcpy.
However, the message cannot possibly increase by more than 2x. So, as a
worst case:
char * WindowizeMessage( char * InputBuffer, unsigned long Length )
{
char * newbfr = malloc( Length * 2 );
char * bfr = newbfr;
while( *InputBuffer )
{
if( *InputBuffer == '\n' )
*bfr++ = '\r';
*bfr++ = *InputBuffer++;
}
*bfr = 0;
return realloc( newbfr, bfr-newbfr );
}
I doubt you can do significantly better than that.
Only, that "pretty fast" ain't "fast enough" in this case. ;)
Can you prove that? As I said, have you actually DONE THE MATH? An
enormous amount of effort is wasted on unnecessary optimization.
And may I ask why you need to do this? Every major mail server on the
planet handles either \n or \r\n.
--
- Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.
.
- Follow-Ups:
- Re: Efficient scather-gather-copy
- From: Hynek Schlawack
- Re: Efficient scather-gather-copy
- References:
- Efficient scather-gather-copy
- From: Hynek Schlawack
- Re: Efficient scather-gather-copy
- From: Mark Whitlock
- Re: Efficient scather-gather-copy
- From: Hynek Schlawack
- Efficient scather-gather-copy
- Prev by Date: Re: view mbr grub
- Next by Date: Re: Why can OS kernel only use maximum 2GB memory?
- Previous by thread: Re: Efficient scather-gather-copy
- Next by thread: Re: Efficient scather-gather-copy
- Index(es):
Relevant Pages
|