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 { ...@@ -32,12 +32,15 @@ class MyHandler : public Net::Http::Handler {
.add<Header::Server>("lys") .add<Header::Server>("lys")
.add<Header::ContentType>(MIME(Text, Plain)); .add<Header::ContentType>(MIME(Text, Plain));
#if 0
auto stream = response.stream(Net::Http::Code::Ok); auto stream = response.stream(Net::Http::Code::Ok);
stream << "PO"; stream << "PO";
stream << flush; stream << flush;
stream << "NG"; stream << "NG";
stream << ends; stream << ends;
#endif
response.send(Code::Ok, "PONG");
} }
} }
else if (req.resource() == "/echo") { else if (req.resource() == "/echo") {
...@@ -63,18 +66,24 @@ class MyHandler : public Net::Http::Handler { ...@@ -63,18 +66,24 @@ class MyHandler : public Net::Http::Handler {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
Net::Port port(9080); Net::Port port(9080);
if (argc == 2) { int thr = 2;
if (argc >= 2) {
port = std::stol(argv[1]); port = std::stol(argv[1]);
if (argc == 3)
thr = std::stol(argv[2]);
} }
Net::Address addr(Net::Ipv4::any(), port); Net::Address addr(Net::Ipv4::any(), port);
static constexpr size_t Workers = 4; static constexpr size_t Workers = 4;
cout << "Cores = " << hardware_concurrency() << endl; cout << "Cores = " << hardware_concurrency() << endl;
cout << "Using " << thr << " threads" << endl;
Net::Http::Endpoint server(addr); Net::Http::Endpoint server(addr);
auto opts = Net::Http::Endpoint::options() auto opts = Net::Http::Endpoint::options()
.threads(2) .threads(thr)
.flags(Net::Tcp::Options::InstallSignalHandler); .flags(Net::Tcp::Options::InstallSignalHandler);
server.init(opts); server.init(opts);
server.setHandler(std::make_shared<MyHandler>()); server.setHandler(std::make_shared<MyHandler>());
......
...@@ -342,6 +342,7 @@ Request::query() const { ...@@ -342,6 +342,7 @@ Request::query() const {
return query_; return query_;
} }
#ifdef LIBSTDCPP_SMARTPTR_LOCK_FIXME
std::shared_ptr<Tcp::Peer> std::shared_ptr<Tcp::Peer>
Request::peer() const { Request::peer() const {
auto p = peer_.lock(); auto p = peer_.lock();
...@@ -350,6 +351,7 @@ Request::peer() const { ...@@ -350,6 +351,7 @@ Request::peer() const {
return p; return p;
} }
#endif
void void
ResponseStream::writeStatusLine() { ResponseStream::writeStatusLine() {
...@@ -482,7 +484,9 @@ Handler::onInput(const char* buffer, size_t len, const std::shared_ptr<Tcp::Peer ...@@ -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); Timeout timeout(io(), this, peer, parser.request);
#ifdef LIBSTDCPP_SMARTPTR_LOCK_FIXME
parser.request.associatePeer(peer); parser.request.associatePeer(peer);
#endif
onRequest(parser.request, std::move(response), std::move(timeout)); onRequest(parser.request, std::move(response), std::move(timeout));
parser.reset(); parser.reset();
} }
......
...@@ -90,17 +90,29 @@ public: ...@@ -90,17 +90,29 @@ public:
const Header::Collection& headers() const; const Header::Collection& headers() const;
const Uri::Query& query() 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; std::shared_ptr<Tcp::Peer> peer() const;
#endif
private: private:
Request(); Request();
#ifdef LIBSTDCPP_SMARTPTR_LOCK_FIXME
void associatePeer(const std::shared_ptr<Tcp::Peer>& peer) { void associatePeer(const std::shared_ptr<Tcp::Peer>& peer) {
if (peer_.use_count() > 0) if (peer_.use_count() > 0)
throw std::runtime_error("A peer was already associated to the response"); throw std::runtime_error("A peer was already associated to the response");
peer_ = peer; peer_ = peer;
} }
#endif
Method method_; Method method_;
std::string resource_; std::string resource_;
......
...@@ -108,16 +108,18 @@ IoWorker::armTimerMs( ...@@ -108,16 +108,18 @@ IoWorker::armTimerMs(
void void
IoWorker::disarmTimer() IoWorker::disarmTimer()
{ {
itimerspec spec; if (!timer.isEmpty()) {
spec.it_value.tv_sec = spec.it_value.tv_nsec = 0; itimerspec spec;
spec.it_interval.tv_sec = spec.it_interval.tv_nsec = 0; spec.it_value.tv_sec = spec.it_value.tv_nsec = 0;
spec.it_interval.tv_sec = spec.it_interval.tv_nsec = 0;
int res = timerfd_settime(timerFd, 0, &spec, 0); int res = timerfd_settime(timerFd, 0, &spec, 0);
if (res == -1) if (res == -1)
throw Error::system("Could not set timer time"); throw Error::system("Could not set timer time");
timer = None(); timer = None();
}
} }
void 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