In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
I. I _ paw _ o
One Icano, two processes (waiting, data relocation [all performed by yourself]).
II. Icano model-there are five Icano models under Unix.
Synchronization and asynchronism are concerned with message communication mechanism in IPUBO.
Synchronization: the caller actively waits for the result of this call.
Async: when an asynchronous procedure call is made, the caller does not get the result immediately. Instead, after the call is made, the callee notifies the caller through status, notification, or handles the call through a callback function, so no result is returned.
(1) Type
1. Blocking Ipaw O model
The application calls an IO function, causing the application to block and wait for the data to be ready.
If the data is not ready, wait. The data is ready to be copied from the kernel to user space.
two。 Non-blocking Ipaw O model
Setting a socket to non-blocking tells the kernel not to sleep the process but to return an error when the requested Imax O operation cannot be completed. In this way, our Iwhite O operation function will continue to test whether the data is ready, and if not, continue to test until the data is ready. In this continuous testing process, it will take up a lot of CPU time.
3. I use O reuse model
(1) select or poll functions will be used in the Imax O reuse model, which will also block the process, but unlike blocking Imax O, these two functions can block multiple Imax O operations at the same time. Moreover, multiple read operations and multiple write operations can be detected at the same time, and the Icano operation function is not really called until there is data to read or write.
(2) correlation function
# include
Int select (int nfds, fd_set * readfds, fd_set * writefds
Fd_set * exceptfds, struct timeval * timeout)
/ / Parameter timeout is structural timeval, which is used to set the waiting time of select ()
/ / timeout: specific time value: if no event occurs within the specified time period, select will return a timeout
NULL:select () without timeout,select will be blocked until an event occurs on a file descriptor.
0: only detects the status of the descriptor collection and returns immediately without waiting for an external event to occur.
Return value:
Successful execution returns the number of file descriptors whose status has changed.
If 0 is returned, it means that the timeout time has elapsed before the state of the descriptor is changed.
When an error occurs,-1 is returned. The cause of the error is stored in errno, and the values of the parameters readfds,writefds,exceptfds and timeout become unpredictable.
Void FD_CLR (int fd, fd_set * set); / / clear the related fd bits in the descriptive phrase set
Int FD_ISSET (int fd, fd_set * set); / / Test whether the bit of relevant fd in the descriptive phrase set is true
Void FD_SET (int fd, fd_set * set); / / set the bit of the related fd in the descriptive phrase set
Void FD_ZERO (fd_set * set); / / clear the whole part of the descriptive phrase set
Int pselect (int nfds, fd_set * readfds, fd_set * writefds,fd_set * exceptfds
Const struct timespec * timeout,const sigset_t * sigmask)
4. Signal-driven Icano model
First of all, the socket is allowed to make a signal-driven Ihand O, and a signal handler is installed, so that the process continues to run without blocking. When the data is ready, the process receives a SIGIO signal, which can be called in the signal processing function to process the data.
5. Asynchronous Ipaw O model
(1) call the aio_read function, tell the kernel the description word, buffer pointer, buffer size, file offset and notification method, and return immediately. When the kernel copies the data to the buffer, it notifies the application.
(2) correlation function
# include
Int aio_read (struct aiocb * aiocbp); Link with-lrt
Return value: success 0, failure-1
(2) comparison
Synchronize Icano:
Blocking Icano model: always waiting
Non-blocking Imax O model: other processes / threads can be executed while waiting
[the above two: only the way of waiting is different, the other is the same]
Signal-driven Icano model: waiting mode is signal-driven
Icano reuse model: a process waits for multiple threads
Asynchronous IPUBO:
Asynchronous Igamo model: waits and data relocations are performed by other threads, focusing only on the results
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.