Re: [Libevent-users] Integrate Windows I/O Completion Port into Libevent
On Sun, Jun 01, 2008 at 01:51:53PM +0800, liusifan wrote: [...] > Integrate Windows I/O Completion Port into Libevent > > IOCP is true async i/o model, and libevent is event-driven i/o model. > > 1. How to emulate event-driven recv/send ? > It is possible to use IOCP to emulate event-driven mode. When you > make read or write calls, pass in a zero-byte buffer (ie, you can > manage your i/o buffers using event driven semantics). So if you issue > a read passing in a zero-byte length buffer, your will get notified > when there is data to read. This seems pretty promising, and could wind up being a better short-term idea than our older plan to get IOCP support by making it a new backend for bufferevents. How well tested is this? Can you get the unit tests to pass, at least, to the extent that the unit tests in 1.4.4 currently pass on win32? I'd like people who use libevent on windows to try this code out; if it works well, we should integrate it. A useful but not-immediately-necessary followup benchmark would be to see how well this does against using IOCP in the "normal" (not "event-driven") way. If there's no big difference, we can defer bufferevents IOCP work for a while; but if there's still a significant amount of overhead here, we should try to apply this patch *and* get IOCP working with bufferevents. [...] > 6. Source code > http://spserver.googlecode.com/files/libevent-1.4.4-iocp.zip > diff file : libevent-1.4.4-iocp\libevent-iocp\diff.txt (For future reference, please use unified diffs (generated with diff -u) rather than old-style diffs. They're shorter and (usually) easier to read. This diff is small enough that there's not much worry about this one, though.) > add file : libevent-1.4.4-iocp\WIN32-Code\win32iocp.cpp You mean ".c"? Hm. This might be better applied against trunk (which will eventually become libevent 2.0) than against 1.4.4; the 1.4 series is supposed to be stable, and Big New Features are usually out there... ...but now that I look at the code, it looks like the only big change is to add a new backend file, which (as far as I can tell) doesn't require any big changes elsewhere in the code. I'd be curious to see what Niels thinks here, but I wouldn't be opposed to checking it into the stable branch. BTW: I haven't read the code fully yet, but it looks relatively clean and straightforward. I'd appreciate it if people who know Windows networking better than I do would check it out and comment. Finally: Thanks, Stephen! This looks like great work to me so far. peace, -- Nick ___ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users
Re: [Libevent-users] Integrate Windows I/O Completion Port into Libevent
On Mon, Jun 02, 2008 at 11:35:58AM -0400, Nick Mathewson wrote: > On Sun, Jun 01, 2008 at 01:51:53PM +0800, liusifan wrote: > [...] > > Integrate Windows I/O Completion Port into Libevent > > > > IOCP is true async i/o model, and libevent is event-driven i/o model. > I'm curious, how close are IOCP semantics to POSIX AIO? I'm read through most of the documentation, but not having actually used IOCP before I'm writing a kqueue(2) compat library, and AIO support is next on my list. ___ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users
Re: [Libevent-users] Integrate Windows I/O Completion Port into Libevent
Hi William, On Mon 02.06.2008 12:30, William Ahern wrote: I'm writing a kqueue(2) compat library, and AIO support is next on my list. http://software.schmorp.de/pkg/libeio.html what do you think about this lib, looks quite nice for me? Cheers Aleks ___ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users
Re: [Libevent-users] Integrate Windows I/O Completion Port into Libevent
2008/6/2, Nick Mathewson <[EMAIL PROTECTED]>: > > On Sun, Jun 01, 2008 at 01:51:53PM +0800, liusifan wrote: > [...] > > This seems pretty promising, and could wind up being a better > short-term idea than our older plan to get IOCP support by making it a > new backend for bufferevents. > > How well tested is this? Can you get the unit tests to pass, at > least, to the extent that the unit tests in 1.4.4 currently pass on > win32? I'd like people who use libevent on windows to try this code > out; if it works well, we should integrate it. Do you mean the uni tests in libevent/test directory ? I will try to get these unit tests to pass. > (For future reference, please use unified diffs (generated with diff -u) > rather than old-style diffs. They're shorter and (usually) easier > to read. This diff is small enough that there's not much worry > about this one, though.) OK, will use -u option. > add file : libevent-1.4.4-iocp\WIN32-Code\win32iocp.cpp > You mean ".c"? Yes. Just a type mistake. It's win32iocp.c . Hm. This might be better applied against trunk (which will eventually > become libevent 2.0) than against 1.4.4; the 1.4 series is supposed to > be stable, and Big New Features are usually out there... > > ...but now that I look at the code, it looks like the only big change > is to add a new backend file, which (as far as I can tell) doesn't > require any big changes elsewhere in the code. I'd be curious to see > what Niels thinks here, but I wouldn't be opposed to checking it into > the stable branch. These some thing i need to explain here. This patch requires to add a EV_ACCEPT macro to indicate the accept event. This is incompatible with the old code. The old code use EV_READ to indicate the accept event. Best Regards, Stephen Liu ___ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users
Re: [Libevent-users] Integrate Windows I/O Completion Port into Libevent
Mostly test cases of regress.c are passed. These are some changes since the libevent-1.4.4-iocp.zip Please check the diff file as attachment. The following test cases are failure or cann't be compiled. I will pay more time to get these test cases to pass. test_bufferevent_watermarks(); fail, block on WSAWaitForMultipleEvents test_multiple(); fail, block on WSAWaitForMultipleEvents test_persistent(); fail, block on WSAWaitForMultipleEvents http_suite();fail on http.c::name_from_addr , vc6 has't getnameinfo function rpc_suite(); it seem so complex to complile, give up rpc_test(); same as above dns_suite(); cannot compile evdns.c, because vc6's winsock2.h is too old Test result of regress.c evutil_stroll: OK Testing Priorities 1: OK Testing Priorities 2: OK Testing Priorities 3: OK Testing Evbuffer: OK Testing evbuffer_find 1: OK Testing evbuffer_find 2: OK Testing evbuffer_find 3: OK Bufferevent: OK Free active base: OK Event base new: OK Simple read: OK Simple write: OK Combined read/write: OK Simple timeout: OK Loop exit: OK Loop break: OK Loop Multiple exit: OK Multiple events for same fd: OK Want read only once: OK Testing Tagging: encoded 0x0af0 with 2 bytes encoded 0x1000 with 3 bytes encoded 0x0001 with 1 bytes encoded 0xdeadbeef with 5 bytes encoded 0x with 1 bytes encoded 0x00bef000 with 4 bytes ??: OK ??: OK encoded 0x0af0 with 2 bytes encoded 0x1000 with 2 bytes encoded 0x0001 with 1 bytes encoded 0xdeadbeef with 5 bytes encoded 0x with 1 bytes encoded 0x00bef000 with 4 bytes ??: OK OK diff.txt Description: Binary data ___ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users
Re: [Libevent-users] Integrate Windows I/O Completion Port into Libevent
Hi, >>3. How to integrate these two mechanism ? >>When we issue a WSARecv or WSASend, we need to pass a OVERLAPPED structure. >>This structure has a hEvent member. >>We could use one event for all WSARecv/WSASend. http://msdn.microsoft.com/en-us/library/ms686358(VS.85).aspx Synchronization and Overlapped Input and Output If an event is used, the hEvent member of the OVERLAPPED structure specifies a handle to the allocated event object. The system sets the state of the event object to nonsignaled when a call to the I/O function returns before the operation has been completed. The integrate strategy for IOCP and WSAEventSelect is not safe. Because WSARecv/WSASend will sets the state of the event object to nonsignaled. This can lead to a race condition: 1.the first WSARecv/WSASend operations have completed, hEvent is signaled 2.the second WSARecv/WSASend has been called, hEvent has been reseted 3.WSAWaitForMultipleEvents will block until the second operations have completed It need to try other way to integrate IOCP and WSAEventSelect. Best Regards, Stephen Liu ___ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users
Re: [Libevent-users] Integrate Windows I/O Completion Port into Libevent
Hi, >The integrate strategy for IOCP and WSAEventSelect is not safe. >Because WSARecv/WSASend will sets the state of the event object to nonsignaled. >This can lead to a race condition: >1.the first WSARecv/WSASend operations have completed, hEvent is signaled >2.the second WSARecv/WSASend has been called, hEvent has been reseted >3.WSAWaitForMultipleEvents will block until the second operations have >completed The following sequences can deal with the race condition: 1.the first WSARecv/WSASend operations have completed, hEvent is signaled 2.the second WSARecv/WSASend has been called, hEvent has been reseted 3.use GetQueuedCompletionStatus with zero timeout, try to process I/O completion event first if it has some I/O completion event, then don't need to call WSAWaitForMultipleEvents 4.if it has not I/O completion event, then calling WSAWaitForMultipleEvents It still has race condition: 1.the second WSARecv/WSASend operation has completed before calling GQCS 2.this completion event has been process by GQCS, but left the hEvent as signaled 3.the next time to call WSAWaitForMultipleEvents, it will success, but GQCS cannot get any completion event. But it don't lead to a logic error, it lead to do a unwanted GQCS call in the worst situation. The last source code: http://spserver.googlecode.com/files/libevent-1.4.4-iocp-1.zip A a echo_iocp.exe test program is also included. This program seen to work fine, it can easy to deal with 1000 simultaneous connections propriety. I hope someone can try this code, any and all comments are appreciated. = With this strategy, the following test cases are passed: test_bufferevent_watermarks(); test_multiple(); test_persistent(); The following test cases still fail, but it's enviroment problem, not buggy. http_suite();fail on http.c::name_from_addr , vc6 has't getnameinfo function rpc_suite(); it seem so complex to complile, give up rpc_test(); same as above dns_suite(); cannot compile evdns.c, because vc6's winsock2.h is too old Best Regards, Stephen Liu ___ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users