Commit e5d50bf5 authored by Mathieu Stefani's avatar Mathieu Stefani

Do not call Request::associatePeer anymore until the mysterious lock...

Do not call Request::associatePeer anymore until the mysterious lock contention has been found and resolved
parent 2f3c5cd1
......@@ -32,12 +32,15 @@ class MyHandler : public Net::Http::Handler {
.add<Header::Server>("lys")
.add<Header::ContentType>(MIME(Text, Plain));
#if 0
auto stream = response.stream(Net::Http::Code::Ok);
stream << "PO";
stream << flush;
stream << "NG";
stream << ends;
#endif
response.send(Code::Ok, "PONG");
}
}
else if (req.resource() == "/echo") {
......@@ -63,18 +66,24 @@ class MyHandler : public Net::Http::Handler {
int main(int argc, char *argv[]) {
Net::Port port(9080);
if (argc == 2) {
int thr = 2;
if (argc >= 2) {
port = std::stol(argv[1]);
if (argc == 3)
thr = std::stol(argv[2]);
}
Net::Address addr(Net::Ipv4::any(), port);
static constexpr size_t Workers = 4;
cout << "Cores = " << hardware_concurrency() << endl;
cout << "Using " << thr << " threads" << endl;
Net::Http::Endpoint server(addr);
auto opts = Net::Http::Endpoint::options()
.threads(2)
.threads(thr)
.flags(Net::Tcp::Options::InstallSignalHandler);
server.init(opts);
server.setHandler(std::make_shared<MyHandler>());
......
......@@ -342,6 +342,7 @@ Request::query() const {
return query_;
}
#ifdef LIBSTDCPP_SMARTPTR_LOCK_FIXME
std::shared_ptr<Tcp::Peer>
Request::peer() const {
auto p = peer_.lock();
......@@ -350,6 +351,7 @@ Request::peer() const {
return p;
}
#endif
void
ResponseStream::writeStatusLine() {
......@@ -482,7 +484,9 @@ Handler::onInput(const char* buffer, size_t len, const std::shared_ptr<Tcp::Peer
Timeout timeout(io(), this, peer, parser.request);
#ifdef LIBSTDCPP_SMARTPTR_LOCK_FIXME
parser.request.associatePeer(peer);
#endif
onRequest(parser.request, std::move(response), std::move(timeout));
parser.reset();
}
......
......@@ -90,17 +90,29 @@ public:
const Header::Collection& headers() const;
const Uri::Query& query() const;
/* @Investigate: this is disabled because of a lock in the shared_ptr / weak_ptr
implementation of libstdc++. Under contention, we experience a performance
drop of 5x with that lock
If this turns out to be a problem, we might be able to replace the weak_ptr
trick to detect peer disconnection by a plain old "observer" pointer to a
tcp connection with a "stale" state
*/
#ifdef LIBSTDCPP_SMARTPTR_LOCK_FIXME
std::shared_ptr<Tcp::Peer> peer() const;
#endif
private:
Request();
#ifdef LIBSTDCPP_SMARTPTR_LOCK_FIXME
void associatePeer(const std::shared_ptr<Tcp::Peer>& peer) {
if (peer_.use_count() > 0)
throw std::runtime_error("A peer was already associated to the response");
peer_ = peer;
}
#endif
Method method_;
std::string resource_;
......
......@@ -108,6 +108,7 @@ IoWorker::armTimerMs(
void
IoWorker::disarmTimer()
{
if (!timer.isEmpty()) {
itimerspec spec;
spec.it_value.tv_sec = spec.it_value.tv_nsec = 0;
spec.it_interval.tv_sec = spec.it_interval.tv_nsec = 0;
......@@ -118,6 +119,7 @@ IoWorker::disarmTimer()
throw Error::system("Could not set timer time");
timer = None();
}
}
void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment