Skip to content

Commit 8db0bcf

Browse files
committed
spawn: keep new FastCGI, WAS, LHTTP processes on cancellation
Implement the virtual method ShouldContinueOnCancel(). This reduces pressure and overhead for spawning new child processes that get canceled quickly. Instead of killing the not-yet spawned process right away, it waits for the spawner to complete and then keeps the process in the "idle" list, because it might be used very soon. This is most important during initial server boot when many requests are slow, but killing and respawning the processes over and over just leads to an avalanche. This is similar to commit 7eb75a4 but for child processes instead of outgoing HTTPS connections.
1 parent 635c8e5 commit 8db0bcf

9 files changed

Lines changed: 36 additions & 0 deletions

File tree

debian/changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
cm4all-beng-proxy (21.20) unstable; urgency=low
22

3+
* spawn: keep new FastCGI, WAS, LHTTP processes on cancellation
34
* spawn: do not log spawn errors of killed processes
45

56
--

src/fcgi/Stock.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ FcgiStock::PrepareChild(const void *info, PreparedChildProcess &p,
121121
params.CopyTo(p, close_fds);
122122
}
123123

124+
bool
125+
FcgiStock::ShouldContinueOnCancel(const void *request) const noexcept
126+
{
127+
const auto &params = *static_cast<const CgiChildParams *>(request);
128+
return !params.disposable;
129+
}
130+
124131
void
125132
FcgiStock::PrepareListenChild(const void *, UniqueSocketDescriptor fd,
126133
PreparedChildProcess &p,

src/fcgi/Stock.hxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ private:
8484
std::string_view GetChildTag(const void *info) const noexcept override;
8585
void PrepareChild(const void *info, PreparedChildProcess &p,
8686
FdHolder &close_fds) override;
87+
bool ShouldContinueOnCancel(const void *request) const noexcept override;
8788

8889
/* virtual methods from class ChildStockMapClass */
8990
StockOptions GetChildOptions(const void *request,

src/spawn/ChildStock.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ ChildStock::Create(CreateStockItem c, StockRequest request,
125125
queue_item->Start(spawn_service);
126126
}
127127

128+
bool
129+
ChildStock::ShouldContinueOnCancel(const void *request) const noexcept
130+
{
131+
return cls.ShouldContinueOnCancel(request);
132+
}
133+
128134
/*
129135
* interface
130136
*

src/spawn/ChildStock.hxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ public:
6666
*/
6767
virtual void PrepareChild(const void *info, PreparedChildProcess &p,
6868
FdHolder &close_fds) = 0;
69+
70+
virtual bool ShouldContinueOnCancel([[maybe_unused]] const void *request) const noexcept {
71+
return false;
72+
}
6973
};
7074

7175
class ChildStockMapClass : public ChildStockClass {
@@ -159,6 +163,7 @@ private:
159163
void Create(CreateStockItem c, StockRequest request,
160164
StockGetHandler &handler,
161165
CancellablePointer &cancel_ptr) override;
166+
bool ShouldContinueOnCancel(const void *request) const noexcept override;
162167
};
163168

164169
/**

src/was/MStock.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ MultiWasStock::PrepareChild(const void *info, PreparedChildProcess &p,
177177
params.CopyTo(p, close_fds);
178178
}
179179

180+
bool
181+
MultiWasStock::ShouldContinueOnCancel(const void *request) const noexcept
182+
{
183+
const auto &params = *static_cast<const CgiChildParams *>(request);
184+
return !params.disposable;
185+
}
186+
180187
StockItem *
181188
MultiWasStock::Create(CreateStockItem c, StockItem &shared_item)
182189
{

src/was/MStock.hxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,5 @@ private:
100100
ChildStock &child_stock) override;
101101
void PrepareChild(const void *info, PreparedChildProcess &p,
102102
FdHolder &close_fds) override;
103+
bool ShouldContinueOnCancel(const void *request) const noexcept override;
103104
};

src/was/Stock.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ WasStock::Create(CreateStockItem c, StockRequest _request,
128128
child->InvokeCreateSuccess(handler);
129129
}
130130

131+
bool
132+
WasStock::ShouldContinueOnCancel(const void *request) const noexcept
133+
{
134+
const auto &params = *static_cast<const CgiChildParams *>(request);
135+
return !params.disposable;
136+
}
137+
131138
WasChild::~WasChild() noexcept = default;
132139

133140
/*

src/was/Stock.hxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,5 @@ private:
105105
void Create(CreateStockItem c, StockRequest request,
106106
StockGetHandler &handler,
107107
CancellablePointer &cancel_ptr) override;
108+
bool ShouldContinueOnCancel(const void *request) const noexcept override;
108109
};

0 commit comments

Comments
 (0)