diff --git a/server/core/messagequeue.cc b/server/core/messagequeue.cc index 8d52c798e..967e2c620 100644 --- a/server/core/messagequeue.cc +++ b/server/core/messagequeue.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include "internal/worker.hh" @@ -26,11 +27,25 @@ namespace static struct { bool initialized; + int pipe_max_size; } this_unit = { false }; +int get_pipe_max_size() +{ + int size = 65536; // Default value from pipe(7) + std::ifstream file("/proc/sys/fs/pipe-max-size"); + + if (file.good()) + { + file >> size; + } + + return size; +} + } namespace maxscale @@ -65,6 +80,7 @@ bool MessageQueue::init() ss_dassert(!this_unit.initialized); this_unit.initialized = true; + this_unit.pipe_max_size = get_pipe_max_size(); return this_unit.initialized; } @@ -123,7 +139,17 @@ MessageQueue* MessageQueue::create(Handler* pHandler) { int read_fd = fds[0]; int write_fd = fds[1]; - +#ifdef F_SETPIPE_SZ + /** + * Increase the pipe buffer size on systems that support it. Modifying + * the buffer size of one fd will also increase it for the other. + */ + if (fcntl(fds[0], F_SETPIPE_SZ, this_unit.pipe_max_size) == -1) + { + MXS_WARNING("Failed to increase pipe buffer size to '%d': %d, %s", + this_unit.pipe_max_size, errno, mxs_strerror(errno)); + } +#endif pThis = new (std::nothrow) MessageQueue(pHandler, read_fd, write_fd); if (!pThis)