2016-04-05 11:41:10 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <config.h>
|
2017-03-08 10:38:22 -06:00
|
|
|
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <Unit.hpp>
|
|
|
|
#include <wsd/LOOLWSD.hpp>
|
2016-04-05 11:41:10 -05:00
|
|
|
|
2016-04-12 15:30:06 -05:00
|
|
|
const int NumToPrefork = 20;
|
2016-04-07 14:15:18 -05:00
|
|
|
|
2016-04-09 12:26:33 -05:00
|
|
|
// Inside the WSD process
|
2016-04-09 11:30:48 -05:00
|
|
|
class UnitPrefork : public UnitWSD
|
2016-04-06 13:50:55 -05:00
|
|
|
{
|
2016-04-12 15:30:06 -05:00
|
|
|
Poco::Timestamp _startTime;
|
2017-03-16 14:12:49 -05:00
|
|
|
std::atomic< int > _childSockets;
|
2016-04-10 21:29:49 -05:00
|
|
|
|
2016-04-05 11:41:10 -05:00
|
|
|
public:
|
|
|
|
UnitPrefork()
|
2017-03-16 14:12:49 -05:00
|
|
|
: _childSockets(0)
|
2016-04-05 11:41:10 -05:00
|
|
|
{
|
2016-12-03 17:02:11 -06:00
|
|
|
setTimeout(60 * 1000);
|
2016-04-05 11:41:10 -05:00
|
|
|
}
|
2016-04-10 21:29:49 -05:00
|
|
|
|
2017-03-30 15:55:33 -05:00
|
|
|
virtual void configure(Poco::Util::LayeredConfiguration& config) override
|
2016-04-05 11:41:10 -05:00
|
|
|
{
|
2017-03-30 15:55:33 -05:00
|
|
|
config.setInt("num_prespawn_children", NumToPrefork);
|
|
|
|
UnitWSD::configure(config);
|
2016-05-20 21:31:53 -05:00
|
|
|
}
|
|
|
|
|
2017-03-16 14:12:49 -05:00
|
|
|
virtual void newChild(WebSocketHandler &) override
|
2016-05-20 21:31:53 -05:00
|
|
|
{
|
2017-03-16 14:12:49 -05:00
|
|
|
_childSockets++;
|
|
|
|
LOG_INF("Unit-prefork: got new child, have " << _childSockets << " of " << NumToPrefork);
|
2016-05-20 21:31:53 -05:00
|
|
|
|
2017-03-16 14:12:49 -05:00
|
|
|
if (_childSockets >= NumToPrefork)
|
2016-04-07 14:15:18 -05:00
|
|
|
{
|
|
|
|
Poco::Timestamp::TimeDiff elapsed = _startTime.elapsed();
|
|
|
|
|
2016-10-22 12:41:44 -05:00
|
|
|
const auto totalTime = (1000. * elapsed)/Poco::Timestamp::resolution();
|
2017-03-16 14:12:49 -05:00
|
|
|
LOG_INF("Launched " << _childSockets << " in " << totalTime);
|
2016-10-05 17:17:33 -05:00
|
|
|
std::cerr << "Launch time total " << totalTime << " ms" << std::endl;
|
2017-03-16 14:12:49 -05:00
|
|
|
std::cerr << "Launch time average " << (totalTime / _childSockets) << " ms" << std::endl;
|
2016-05-20 21:52:55 -05:00
|
|
|
|
2017-03-16 14:12:49 -05:00
|
|
|
exitTest(TestResult::Ok);
|
2016-04-07 14:15:18 -05:00
|
|
|
}
|
2016-04-06 13:50:55 -05:00
|
|
|
}
|
2016-04-05 11:41:10 -05:00
|
|
|
};
|
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
UnitBase *unit_create_wsd(void)
|
2016-04-05 11:41:10 -05:00
|
|
|
{
|
|
|
|
return new UnitPrefork();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|