For Linux systems that improve performance, sendfile, splice, and tee are called.

Source: Internet
Author: User
Tags sendfile
In Linux, the system that improves performance calls sendfile. Splice and tee may be familiar with Linux kernel version 2.4: a static Web Page Server named khttpd is embedded in the kernel of version 2.4. At that time, it may be because of the efficiency factor that she was added. As to why the latest version 2.6 kernel removed this server, I think it may be because the Linux kernel "only provides a mechanism, and does not provide a policy ", of course, security factors cannot be excluded.

In fact, it is completely unnecessary to add a web server to the kernel, because the Linux Kernel provides a system call such as sendfile:

Reference:

# Include <sys/sendfile. h>

Ssize_t sendfile (INT out_fd, int in_fd, off_t * offset, size_t count );

She can send a specific block of a file starting from a specific part through a socket, thus avoiding the overhead of kernel context and user context switching that calls read and write multiple times, in addition, MMAP technology is used internally to reduce the overhead of memory replication. With her, is there any need for khttpd?

Splice and tee are first introduced in Linux kernel 2.6.17:

Reference:

# DEFINE _ gnu_source
# Include <fcntl. h>

Long Splice (INT fd_in, off_t * off_in, int fd_out,
Off_t * off_out, size_t Len, unsigned int flags );

Reference:

# DEFINE _ gnu_source
# Include <fcntl. h>

Long tee (INT fd_in, int fd_out, size_t Len, unsigned int flags );

The two are mainly used to reduce the number of Read and Write System calls when data is transferred between the pipeline and other descriptors. For detailed usage, see the man page, here, the man page of TEE also provides a tee Command Re-implemented using splice and tee as an example. If you are interested, you can check it.

Vmsplice was introduced with them:

Reference:

# DEFINE _ gnu_source
# Include <fcntl. h>
# Include <sys/uio. h>

Long vmsplice (int fd, const struct iovec * IOV,
Unsigned long nr_segs, unsigned int flags );

This system call maps the user space memory to the kernel space, thus avoiding actual memory write operations and improving the system efficiency.

However, I do not think that splice, tee and vmsplice are "useful" in actual code, but I think it is better to remove the restrictions on pipelines. Because of the tunneling proxy service program, after the connection is established, the main task is to relay data between two sockets. If we can splice them, it can improve efficiency to a certain extent. It's hard to make everyone speak!

I hope the above introduction will be helpful to you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.