Boost Asio On Linux Not Using Epoll
Asked Answered
S

1

5

I was under the impression that boost::asio would use an epoll setup by default instead of a select implementation, but after running some tests it looks like my setup is using select.

OS: RHEL 4
Kernel:2.6
GCC:3.4.6

I wrote a little test program to verify which reactor header was being used, and it looks like its using the select reactor rather than the epoll reactor.

#include <boost/asio.hpp>

#include <string>
#include <iostream>

std::string output;

#if defined(BOOST_ASIO_EPOLL_REACTOR_HPP)

int main(void)
{
    std::cout << "you have epoll enabled." << std::endl;
}

#elif defined(BOOST_ASIO_DETAIL_SELECT_REACTOR_HPP)

int main(void)
{
    std::cout << "you have select enabled." << std::endl;
}

#else

int main(void)
{
    std::cout << "this shit is confusing." << std::endl;
}


#endif

What could I be doing wrong?

Squish answered 23/6, 2010 at 23:31 Comment(0)
S
5

Your program says "select" for me too, yet asio is using epoll_wait(), as ps -Teo tid,wchan:25,comm reports.

How about

#include <iostream>
#include <string>
#include <boost/asio.hpp>
int main()
{
std::string output;
#if defined(BOOST_ASIO_HAS_IOCP)
  output = "iocp" ;
#elif defined(BOOST_ASIO_HAS_EPOLL)
  output = "epoll" ;
#elif defined(BOOST_ASIO_HAS_KQUEUE)
  output = "kqueue" ;
#elif defined(BOOST_ASIO_HAS_DEV_POLL)
  output = "/dev/poll" ;
#else
  output = "select" ;
#endif
    std::cout << output << std::endl;
}

(the ladder of ifdefs grabbed from /usr/include/boost/asio/serial_port_service.hpp)

Schriever answered 24/6, 2010 at 0:12 Comment(5)
This code printed "select" for me. After some digging in epoll_reactor_fwd.hpp and some more testing, the LINUX_VERSION_CODE is returning a version less that 2.4.45 (which is required to use epoll, apparently). uname -r returns the following: $uname -r 2.6.9-78.0.13.ELsmp If fool with the required kernel in epoll_reactor_fwd.hpp I can get your program to output "epoll". Is this some sort of server configuration error?Squish
Indeed seems so. My dev system outputs LINUX_VERSION_CODE as 132639 or KERNEL_VERSION (2,6,31) (and it was shipped with 2.6.31.5 - it's an OpenSUSE). What would happen if you rebuild boost from source?Schriever
Boost.Asio is header only, I doubt rebuilding boost will help.Wakeen
Took another look: LINUX_VERSION_CODE is defined in /usr/include/linux/version.h -- perhaps the server simply has wrong kernel headers installed.Schriever
After changing the appropriate values in /usr/include/linux/version.h asio appears to be using epoll. I'm a little worried that adjusting these values will have other side effects but its okay for the time being. I might rebuild boost despite asio being header-only. It does require the boost::system lib, and there may be something bad lurking as a result. Thanks all for help.Squish

© 2022 - 2024 — McMap. All rights reserved.