fix(lighthouse): preserve checker capacity
This commit is contained in:
1 parent
c9bf189f09
commit
f4738419eb
3 files changed
+15
-5
No files matched your search
@@ -5,6 +5,7 @@
|
||||
#include "util.hpp"
|
||||
#include <wasmtime.h>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
@@ -20,18 +21,27 @@ struct Busy : std::runtime_error { Busy() : std::runtime_error("filter worker bu
|
||||
|
||||
class Slots {
|
||||
std::mutex lock_;
|
||||
std::condition_variable room_;
|
||||
int held_ = 0;
|
||||
int waiting_ = 0;
|
||||
int limit_;
|
||||
public:
|
||||
explicit Slots(int limit) : limit_(limit) {}
|
||||
void acquire() {
|
||||
std::lock_guard guard(lock_);
|
||||
if (held_ >= limit_) throw Busy();
|
||||
std::unique_lock guard(lock_);
|
||||
if (held_ >= limit_) {
|
||||
if (waiting_ >= 8) throw Busy();
|
||||
++waiting_;
|
||||
bool available = room_.wait_for(guard, std::chrono::seconds(5), [&] { return held_ < limit_; });
|
||||
--waiting_;
|
||||
if (!available) throw Busy();
|
||||
}
|
||||
++held_;
|
||||
}
|
||||
void release() {
|
||||
std::lock_guard guard(lock_);
|
||||
--held_;
|
||||
room_.notify_one();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -137,7 +147,7 @@ public:
|
||||
};
|
||||
|
||||
inline Artifact compile(const std::string& source) {
|
||||
static Slots slots(4);
|
||||
static Slots slots(2);
|
||||
Slot slot(slots);
|
||||
Build build(source);
|
||||
recipe::run(recipe::filter, build);
|
||||
|
||||
@@ -344,7 +344,7 @@ int main() {
|
||||
try {
|
||||
initialize();
|
||||
httplib::Server server;
|
||||
server.new_task_queue = [] { return new httplib::ThreadPool(8, 16, 32); };
|
||||
server.new_task_queue = [] { return new httplib::ThreadPool(32, 64, 256); };
|
||||
server.set_keep_alive_max_count(8);
|
||||
server.set_keep_alive_timeout(2);
|
||||
server.set_read_timeout(3, 0);
|
||||
|
||||
Reference in new issue
Block a user