libreoffice-online/test/UnitPrefork.cpp

59 lines
1.7 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <config.h>
#include <Unit.hpp>
#include <wsd/LOOLWSD.hpp>
const int NumToPrefork = 20;
2016-04-07 14:15:18 -05:00
2016-04-09 12:26:33 -05:00
// Inside the WSD process
class UnitPrefork : public UnitWSD
{
std::chrono::steady_clock::time_point _startTime = std::chrono::steady_clock::now();
std::atomic< int > _childSockets;
public:
UnitPrefork()
: _childSockets(0)
{
2016-12-03 17:02:11 -06:00
setTimeout(60 * 1000);
}
2017-03-30 15:55:33 -05:00
virtual void configure(Poco::Util::LayeredConfiguration& config) override
{
2017-03-30 15:55:33 -05:00
config.setInt("num_prespawn_children", NumToPrefork);
UnitWSD::configure(config);
}
virtual void newChild(WebSocketHandler &) override
{
_childSockets++;
LOG_INF("Unit-prefork: got new child, have " << _childSockets << " of " << NumToPrefork);
if (_childSockets >= NumToPrefork)
2016-04-07 14:15:18 -05:00
{
const auto duration = std::chrono::steady_clock::now() - _startTime;
const auto totalTime = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
2016-04-07 14:15:18 -05:00
LOG_INF("Launched " << _childSockets << " in " << totalTime);
std::cerr << "Launch time total " << totalTime << " ms" << std::endl;
std::cerr << "Launch time average " << (totalTime / _childSockets) << " ms" << std::endl;
exitTest(TestResult::Ok);
2016-04-07 14:15:18 -05:00
}
}
};
UnitBase *unit_create_wsd(void)
{
return new UnitPrefork();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */