Libev vs libevent

Hi,
as a long time user of the libcouchbase2-libev backend, I took a look at the latest SDK doc and found a recommendation for the use of libevent:

https://developer.couchbase.com/documentation/server/4.5/sdk/c/start-using-sdk.html

“Pluggable non-blocking event loops such as libevent and libuv- integrate with your own non-blocking application, or use lcb_wait in blocking code”

“Note:
You should install the libcouchbase2-libevent plugin in case your application will use more than 1024 file descriptors. The default select() based event loop only supports 1024 file descriptors.”

libev is only mentioned way down. Is libev deprecated?
Is there any advantage of the one over the other?

Nothing wrong with libev, but libev is not as common/known as libevent. libuv is a good choice for other reasons (e.g. Windows). Where did you see this in the docs?

mentioned it in the message:

I’ve created a pull request to address that.

Hi @bateau020 @mnunberg, my application generates many “COUCHBASE: too many FDs. Cannot have socket > FD_SETSIZE. Use other I/O plugin.” in the log. I used normal sync network IO and lcb_wait for waiting operation to be completed. This doc https://github.com/couchbase/libcouchbase/blob/master/plugins/io/select/plugin-select.c#L376 shows that the log is printed when the socket size exceeds FD_SETSIZE. And FD_SETSIZE is hardcoded and can not be changed. I also saw that “Note:
You should install the libcouchbase2-libevent plugin in case your application will use more than 1024 file descriptors. The default select() based event loop only supports 1024 file descriptors.” Now I have installed libcouchbase2-libevent on my machine, what do I need to do next? Do I need to change to use libevent instead of normal event_loop based on select? If yes, can I still use the libevent in sync mode since my application is developed in sync mode.

Hi,
There are a number of advantages of using the async method, one being that when using the async methods, your application will be much more capable of supporting concurrent loads.

For an example of libevent, see http://docs.couchbase.com/sdk-api/couchbase-c-client-2.6.2/example_2libeventdirect_2main_8c-example.html

Note that when using libevent, libev or libuv you can no longer use lcb_wait. That will probably mean (depending on how you wrote your program), that your application no longer works. In that case, you should migrate to async methods. It is some work, but can be done by a good programer that understands async programming and threads synchronisation techniques for example. I could give you some pointers on how to do it. But if you think that that is too complicated, there is always the possibility to use a ‘lighter’ API, like the JavaRx or Node.JS API. Those are usually simpler to use than the rather hardcore C API.

if you have installed libcouchbase2-libevent, the libcouchbase wll pick it up automatically

@avsej I have installed libcouchbase2-libevent. Could you explain more about the “libcouchbase wll pick it up automatically”? Since there are multiple “COUCHBASE: too many FDs. Cannot have socket > FD_SETSIZE. Use other I/O plugin.” in my log, it seems libevent is not picked up.

Since my app is a plugin installed in Apache Traffic Server, which is also an event-driven framework. However, it is not based on libevent, libev, or libuv. So I chose to use sync mode here. But the number of file descriptors > 1024 here, can I use event_base_loop(evbase, 0) to simulate the lcb_wait(instance) here as sync mode?

By the way, using libevent in async mode, could you enforce the first-come-first-serve rule for all events registered in the event loop?