Skip to content

Commit

Permalink
was/async/Control: add io_uring support
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Jan 16, 2025
1 parent 9618cca commit 5deb3ec
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 4 deletions.
1 change: 1 addition & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cm4all-beng-proxy (19.2) unstable; urgency=low

* http/local: fix crash bug (19.0 regression)
* was: reduce the number of epoll_ctl() system calls again
* was: receive from control channel using io_uring

--

Expand Down
2 changes: 1 addition & 1 deletion libcommon
10 changes: 9 additions & 1 deletion src/bp/Main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,15 @@ try {
new RemoteWasStock(instance.config.remote_was_stock_limit,
instance.config.remote_was_stock_max_idle,
instance.event_loop);
#endif

#ifdef HAVE_URING
if (instance.uring) {
instance.was_stock->EnableUring(*instance.uring);
instance.multi_was_stock->EnableUring(*instance.uring);
instance.remote_was_stock->EnableUring(*instance.uring);
}
#endif // HAVE_URING
#endif // HAVE_LIBWAS

instance.delegate_stock = delegate_stock_new(instance.event_loop,
*instance.spawn_service);
Expand Down
6 changes: 6 additions & 0 deletions src/was/IdleConnection.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public:
WasSocket &&_socket,
WasIdleConnectionHandler &_handler) noexcept;

#ifdef HAVE_URING
void EnableUring(Uring::Queue &uring_queue) {
control.EnableUring(uring_queue);
}
#endif

auto &GetEventLoop() const noexcept {
return control.GetEventLoop();
}
Expand Down
9 changes: 8 additions & 1 deletion src/was/MStock.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,14 @@ MultiWasStock::Create(CreateStockItem c, StockItem &shared_item)
{
auto &child = (MultiWasChild &)shared_item;

return new MultiWasConnection(c, child);
auto *connection = new MultiWasConnection(c, child);

#ifdef HAVE_URING
if (uring_queue != nullptr)
connection->EnableUring(*uring_queue);
#endif

return connection;
}

void
Expand Down
15 changes: 15 additions & 0 deletions src/was/MStock.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "spawn/ChildStock.hxx"
#include "stock/MultiStock.hxx"
#include "pool/Ptr.hxx"
#include "io/uring/config.h" // for HAVE_URING

#include <span>

Expand All @@ -18,11 +19,19 @@ class SocketDescriptor;
class EventLoop;
class SpawnService;

#ifdef HAVE_URING
namespace Uring { class Queue; }
#endif

class MultiWasStock final : MultiStockClass, ChildStockClass {
PoolPtr pool;
ChildStock child_stock;
MultiStock mchild_stock;

#ifdef HAVE_URING
Uring::Queue *uring_queue = nullptr;
#endif

public:
MultiWasStock(unsigned limit, unsigned max_idle,
EventLoop &event_loop, SpawnService &spawn_service,
Expand All @@ -33,6 +42,12 @@ public:
return mchild_stock.GetEventLoop();
}

#ifdef HAVE_URING
void EnableUring(Uring::Queue &_uring_queue) noexcept {
uring_queue = &_uring_queue;
}
#endif

std::size_t DiscardSome() noexcept {
return mchild_stock.DiscardOldestIdle(64);
}
Expand Down
9 changes: 8 additions & 1 deletion src/was/RStock.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@ RemoteWasStock::Create(CreateStockItem c, StockItem &shared_item)
{
auto &multi_connection = (RemoteMultiWasConnection &)shared_item;

return new WasStockConnection(c, multi_connection.Connect());
auto *connection = new WasStockConnection(c, multi_connection.Connect());

#ifdef HAVE_URING
if (uring_queue != nullptr)
connection->EnableUring(*uring_queue);
#endif

return connection;
}

void
Expand Down
15 changes: 15 additions & 0 deletions src/was/RStock.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@

#include "stock/Class.hxx"
#include "stock/MultiStock.hxx"
#include "io/uring/config.h" // for HAVE_URING

class AllocatorPtr;
class SocketAddress;

#ifdef HAVE_URING
namespace Uring { class Queue; }
#endif

class RemoteWasStock final : MultiStockClass {
class MultiClientStockClass final : public StockClass {
public:
Expand All @@ -23,6 +28,10 @@ class RemoteWasStock final : MultiStockClass {

MultiStock multi_stock;

#ifdef HAVE_URING
Uring::Queue *uring_queue = nullptr;
#endif

public:
RemoteWasStock(unsigned limit, unsigned max_idle,
EventLoop &event_loop) noexcept;
Expand All @@ -31,6 +40,12 @@ public:
return multi_stock.GetEventLoop();
}

#ifdef HAVE_URING
void EnableUring(Uring::Queue &_uring_queue) noexcept {
uring_queue = &_uring_queue;
}
#endif

void FadeAll() noexcept {
multi_stock.FadeAll();
}
Expand Down
6 changes: 6 additions & 0 deletions src/was/SConnection.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class WasStockConnection
public:
WasStockConnection(CreateStockItem c, WasSocket &&_socket) noexcept;

#ifdef HAVE_URING
void EnableUring(Uring::Queue &uring_queue) {
connection.EnableUring(uring_queue);
}
#endif

auto &GetEventLoop() const noexcept {
return connection.GetEventLoop();
}
Expand Down
5 changes: 5 additions & 0 deletions src/was/Stock.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ WasStock::Create(CreateStockItem c, StockRequest _request,
callback, because the latter may destroy the pool */
_request.reset();

#ifdef HAVE_URING
if (uring_queue != nullptr)
child->EnableUring(*uring_queue);
#endif

child->InvokeCreateSuccess(handler);
}

Expand Down
15 changes: 15 additions & 0 deletions src/was/Stock.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "stock/Class.hxx"
#include "stock/MapStock.hxx"
#include "net/SocketDescriptor.hxx"
#include "io/uring/config.h" // for HAVE_URING

#include <span>
#include <string_view>
Expand All @@ -19,6 +20,10 @@ struct WasSocket;
class SpawnService;
class ListenStreamStock;

#ifdef HAVE_URING
namespace Uring { class Queue; }
#endif

/**
* Launch and manage WAS child processes.
*/
Expand All @@ -39,6 +44,10 @@ class WasStock final : StockClass {

WasStockMap stock;

#ifdef HAVE_URING
Uring::Queue *uring_queue = nullptr;
#endif

public:
explicit WasStock(EventLoop &event_loop, SpawnService &_spawn_service,
ListenStreamStock *_listen_stream_stock,
Expand All @@ -55,6 +64,12 @@ public:
return stock.GetEventLoop();
}

#ifdef HAVE_URING
void EnableUring(Uring::Queue &_uring_queue) noexcept {
uring_queue = &_uring_queue;
}
#endif

void FadeAll() noexcept {
stock.FadeAll();
}
Expand Down

0 comments on commit 5deb3ec

Please sign in to comment.