summaryrefslogtreecommitdiffstats
path: root/fnet
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@yahooinc.com>2023-02-22 12:54:31 +0000
committerHåvard Pettersen <havardpe@yahooinc.com>2023-02-22 14:46:14 +0000
commitb6073079e7d0d09fb7f13606d3fe3f1798337d66 (patch)
tree70998a611bdb7af626e8f480e34062db7783c2ea /fnet
parent890e0ac9e795ca1c95e459f98a54593ac151051c (diff)
untangle fnet from fastos
Diffstat (limited to 'fnet')
-rw-r--r--fnet/CMakeLists.txt1
-rw-r--r--fnet/INSTALL22
-rw-r--r--fnet/README26
-rw-r--r--fnet/src/examples/ping/pingclient.cpp5
-rw-r--r--fnet/src/examples/timeout/timeout.cpp5
-rw-r--r--fnet/src/tests/connect/connect_test.cpp14
-rw-r--r--fnet/src/tests/connection_spread/connection_spread_test.cpp9
-rw-r--r--fnet/src/tests/frt/detach_supervisor/detach_supervisor_test.cpp7
-rw-r--r--fnet/src/tests/frt/parallel_rpc/parallel_rpc_test.cpp7
-rw-r--r--fnet/src/tests/sync_execute/sync_execute.cpp5
-rw-r--r--fnet/src/vespa/fnet/frt/supervisor.cpp6
-rw-r--r--fnet/src/vespa/fnet/frt/supervisor.h2
-rw-r--r--fnet/src/vespa/fnet/transport.cpp13
-rw-r--r--fnet/src/vespa/fnet/transport.h6
-rw-r--r--fnet/src/vespa/fnet/transport_thread.cpp12
-rw-r--r--fnet/src/vespa/fnet/transport_thread.h10
16 files changed, 40 insertions, 110 deletions
diff --git a/fnet/CMakeLists.txt b/fnet/CMakeLists.txt
index eeef7f63876..6d8836817e0 100644
--- a/fnet/CMakeLists.txt
+++ b/fnet/CMakeLists.txt
@@ -1,7 +1,6 @@
# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
vespa_define_module(
DEPENDS
- fastos
vespalog
vespalib
diff --git a/fnet/INSTALL b/fnet/INSTALL
deleted file mode 100644
index 9bb6c6152a4..00000000000
--- a/fnet/INSTALL
+++ /dev/null
@@ -1,22 +0,0 @@
-*********************************
-* Compiling and Installing fnet *
-*********************************
-
-'fnet' uses 'FastOS'.
-In the following instructions, let %FASTOS_DIR% denote the install
-directory for FastOS. A reasonable install directory would be:
- %FASTOS_DIR% = '/usr/fastsearch/fastos'
-
-Install FastOS:
-- checkout the fastos CVS module
-- go to fastos/src/fastos
-- ./configure --install-dir %FASTOS_DIR% [<config parameters>]
- (run ./configure --help for help)
-- make install
-
-Install fnet:
-- checkout the fnet CVS module
-- go to fnet/src
-- ./configure --fastos-dir %FASTOS_DIR% [<config parameters>]
- (run ./configure --fastos-dir %FASTOS_DIR% --help for help)
-- make install
diff --git a/fnet/README b/fnet/README
deleted file mode 100644
index dab36e5b120..00000000000
--- a/fnet/README
+++ /dev/null
@@ -1,26 +0,0 @@
-This cvs module contains the code for FNET and FRT
-FNET currently stands for 'FuNET'
-FRT currently stands for 'FNET Remote Tools'
-
-FNET is a multi-threaded object-oriented networking library based on
-FastOS. FRT implements a proprietary RPC protocol on top of FNET.
-
-For how to compile and install, read the INSTALL file.
-For release information, read the RELEASEINFO file.
-
-The maintainer of this module is [havardpe@yahoo-inc.com]
-
-Notes from the maintainer:
-
-This library is work in progress. This means that some APIs may change
-in new versions. I will try to keep these changes to a minimum and
-also document them in the RELEASEINFO file.
-
-No extra effort has been added to hide things from the users of this
-library. This means that you can use components like the scheduler to
-implement a scheduler thread that has nothing to do with
-networking. It also means that you have to expect to handle more API
-changes if you are using classes not intended for direct use. It also
-means that you will have access to methods you were never meant to
-invoke. If this becomes a problem, I will start making things private
-and the classes more 'friendly'.
diff --git a/fnet/src/examples/ping/pingclient.cpp b/fnet/src/examples/ping/pingclient.cpp
index 9b32e40ac83..43296df7e57 100644
--- a/fnet/src/examples/ping/pingclient.cpp
+++ b/fnet/src/examples/ping/pingclient.cpp
@@ -6,7 +6,6 @@
#include <vespa/fnet/connection.h>
#include <examples/ping/packets.h>
#include <vespa/vespalib/util/signalhandler.h>
-#include <vespa/fastos/thread.h>
#include <vespa/log/log.h>
LOG_SETUP("pingclient");
@@ -28,7 +27,6 @@ PingClient::main(int argc, char **argv)
}
FNET_PacketQueue queue;
- FastOS_ThreadPool pool;
PingPacketFactory factory;
FNET_SimplePacketStreamer streamer(&factory);
FNET_Transport transport;
@@ -39,7 +37,7 @@ PingClient::main(int argc, char **argv)
if (argc == 3) {
timeout_ms = atof(argv[2]) * 1000;
}
- transport.Start(&pool);
+ transport.Start();
uint32_t channelCnt = 0;
for (uint32_t i = 0; i < 10; i++) {
@@ -90,7 +88,6 @@ PingClient::main(int argc, char **argv)
if (conn != nullptr)
conn->SubRef();
transport.ShutDown(true);
- pool.Close();
return 0;
}
diff --git a/fnet/src/examples/timeout/timeout.cpp b/fnet/src/examples/timeout/timeout.cpp
index 41de852d48c..e0830c7cde1 100644
--- a/fnet/src/examples/timeout/timeout.cpp
+++ b/fnet/src/examples/timeout/timeout.cpp
@@ -5,7 +5,6 @@
#include <vespa/fnet/packetqueue.h>
#include <vespa/fnet/controlpacket.h>
#include <vespa/vespalib/util/signalhandler.h>
-#include <vespa/fastos/thread.h>
#include <vespa/vespalib/util/time.h>
#include <thread>
@@ -54,10 +53,9 @@ MyApp::main(int, char **)
ms_double ms;
clock::time_point t;
FNET_PacketQueue queue;
- FastOS_ThreadPool pool;
FNET_Transport transport;
Timeout timeout(transport.GetScheduler(), &queue);
- transport.Start(&pool);
+ transport.Start();
// stable-state operation
std::this_thread::sleep_for(100ms);
@@ -90,7 +88,6 @@ MyApp::main(int, char **)
fprintf(stderr, "time since timeout was scheduled: %f ms\n", ms.count());
transport.ShutDown(true);
- pool.Close();
return 0;
}
diff --git a/fnet/src/tests/connect/connect_test.cpp b/fnet/src/tests/connect/connect_test.cpp
index 681c3b7676a..9d566cf37a7 100644
--- a/fnet/src/tests/connect/connect_test.cpp
+++ b/fnet/src/tests/connect/connect_test.cpp
@@ -88,26 +88,25 @@ struct BlockingCryptoEngine : public CryptoEngine {
struct TransportFixture : FNET_IPacketHandler, FNET_IConnectionCleanupHandler {
FNET_SimplePacketStreamer streamer;
- FastOS_ThreadPool pool;
FNET_Transport transport;
Gate conn_lost;
Gate conn_deleted;
- TransportFixture() : streamer(nullptr), pool(), transport(),
+ TransportFixture() : streamer(nullptr), transport(),
conn_lost(), conn_deleted()
{
- transport.Start(&pool);
+ transport.Start();
}
TransportFixture(AsyncResolver::HostResolver::SP host_resolver)
- : streamer(nullptr), pool(), transport(fnet::TransportConfig().resolver(make_resolver(std::move(host_resolver)))),
+ : streamer(nullptr), transport(fnet::TransportConfig().resolver(make_resolver(std::move(host_resolver)))),
conn_lost(), conn_deleted()
{
- transport.Start(&pool);
+ transport.Start();
}
TransportFixture(CryptoEngine::SP crypto)
- : streamer(nullptr), pool(), transport(fnet::TransportConfig().crypto(std::move(crypto))),
+ : streamer(nullptr), transport(fnet::TransportConfig().crypto(std::move(crypto))),
conn_lost(), conn_deleted()
{
- transport.Start(&pool);
+ transport.Start();
}
HP_RetCode HandlePacket(FNET_Packet *packet, FNET_Context) override {
ASSERT_TRUE(packet->GetCommand() == FNET_ControlPacket::FNET_CMD_CHANNEL_LOST);
@@ -127,7 +126,6 @@ struct TransportFixture : FNET_IPacketHandler, FNET_IConnectionCleanupHandler {
}
~TransportFixture() override {
transport.ShutDown(true);
- pool.Close();
}
};
diff --git a/fnet/src/tests/connection_spread/connection_spread_test.cpp b/fnet/src/tests/connection_spread/connection_spread_test.cpp
index d65e4fb70fe..6286ce65657 100644
--- a/fnet/src/tests/connection_spread/connection_spread_test.cpp
+++ b/fnet/src/tests/connection_spread/connection_spread_test.cpp
@@ -6,7 +6,6 @@
#include <vespa/fnet/ipacketstreamer.h>
#include <vespa/fnet/connector.h>
#include <vespa/fnet/connection.h>
-#include <vespa/fastos/thread.h>
#include <vespa/vespalib/util/size_literals.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <thread>
@@ -28,13 +27,12 @@ struct DummyStreamer : FNET_IPacketStreamer {
struct Fixture {
DummyStreamer streamer;
DummyAdapter adapter;
- FastOS_ThreadPool thread_pool;
FNET_Transport client;
FNET_Transport server;
- Fixture() : streamer(), adapter(), thread_pool(), client(8), server(8)
+ Fixture() : streamer(), adapter(), client(8), server(8)
{
- ASSERT_TRUE(client.Start(&thread_pool));
- ASSERT_TRUE(server.Start(&thread_pool));
+ ASSERT_TRUE(client.Start());
+ ASSERT_TRUE(server.Start());
}
void wait_for_components(size_t client_cnt, size_t server_cnt) {
bool ok = false;
@@ -49,7 +47,6 @@ struct Fixture {
~Fixture() {
server.ShutDown(true);
client.ShutDown(true);
- thread_pool.Close();
}
};
diff --git a/fnet/src/tests/frt/detach_supervisor/detach_supervisor_test.cpp b/fnet/src/tests/frt/detach_supervisor/detach_supervisor_test.cpp
index 716c433ff61..6325c60413a 100644
--- a/fnet/src/tests/frt/detach_supervisor/detach_supervisor_test.cpp
+++ b/fnet/src/tests/frt/detach_supervisor/detach_supervisor_test.cpp
@@ -10,7 +10,6 @@
#include <vespa/vespalib/util/size_literals.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/util/time.h>
-#include <vespa/fastos/thread.h>
#include <thread>
using namespace vespalib;
@@ -19,14 +18,12 @@ using vespalib::make_string_short::fmt;
CryptoEngine::SP null_crypto = std::make_shared<NullCryptoEngine>();
struct BasicFixture {
- FastOS_ThreadPool thread_pool;
FNET_Transport transport;
- BasicFixture() : thread_pool(), transport(fnet::TransportConfig(4).crypto(null_crypto)) {
- ASSERT_TRUE(transport.Start(&thread_pool));
+ BasicFixture() : transport(fnet::TransportConfig(4).crypto(null_crypto)) {
+ ASSERT_TRUE(transport.Start());
}
~BasicFixture() {
transport.ShutDown(true);
- thread_pool.Close();
}
};
diff --git a/fnet/src/tests/frt/parallel_rpc/parallel_rpc_test.cpp b/fnet/src/tests/frt/parallel_rpc/parallel_rpc_test.cpp
index 624f5a73ae6..41bfb7d06a6 100644
--- a/fnet/src/tests/frt/parallel_rpc/parallel_rpc_test.cpp
+++ b/fnet/src/tests/frt/parallel_rpc/parallel_rpc_test.cpp
@@ -4,7 +4,6 @@
#include <vespa/fnet/frt/rpcrequest.h>
#include <vespa/fnet/frt/target.h>
#include <vespa/fnet/transport.h>
-#include <vespa/fastos/thread.h>
#include <vespa/vespalib/util/benchmark_timer.h>
#include <vespa/vespalib/net/crypto_engine.h>
#include <vespa/vespalib/net/tls/tls_crypto_engine.h>
@@ -15,13 +14,12 @@
using namespace vespalib;
struct Rpc : FRT_Invokable {
- FastOS_ThreadPool thread_pool;
FNET_Transport transport;
FRT_Supervisor orb;
Rpc(CryptoEngine::SP crypto, size_t num_threads, bool drop_empty)
- : thread_pool(), transport(fnet::TransportConfig(num_threads).crypto(std::move(crypto)).drop_empty_buffers(drop_empty)), orb(&transport) {}
+ : transport(fnet::TransportConfig(num_threads).crypto(std::move(crypto)).drop_empty_buffers(drop_empty)), orb(&transport) {}
void start() {
- ASSERT_TRUE(transport.Start(&thread_pool));
+ ASSERT_TRUE(transport.Start());
}
uint32_t listen() {
ASSERT_TRUE(orb.Listen(0));
@@ -32,7 +30,6 @@ struct Rpc : FRT_Invokable {
}
~Rpc() override {
transport.ShutDown(true);
- thread_pool.Close();
}
};
diff --git a/fnet/src/tests/sync_execute/sync_execute.cpp b/fnet/src/tests/sync_execute/sync_execute.cpp
index b8fa21cf147..5d2f4097ab4 100644
--- a/fnet/src/tests/sync_execute/sync_execute.cpp
+++ b/fnet/src/tests/sync_execute/sync_execute.cpp
@@ -4,7 +4,6 @@
#include <vespa/vespalib/util/size_literals.h>
#include <vespa/fnet/transport.h>
#include <vespa/fnet/iexecutable.h>
-#include <vespa/fastos/thread.h>
struct DoIt : public FNET_IExecutable {
vespalib::Gate gate;
@@ -18,10 +17,9 @@ TEST("sync execute") {
DoIt exe2;
DoIt exe3;
DoIt exe4;
- FastOS_ThreadPool pool;
FNET_Transport transport;
ASSERT_TRUE(transport.execute(&exe1));
- ASSERT_TRUE(transport.Start(&pool));
+ ASSERT_TRUE(transport.Start());
exe1.gate.await();
ASSERT_TRUE(transport.execute(&exe2));
transport.sync();
@@ -32,7 +30,6 @@ TEST("sync execute") {
transport.sync();
transport.WaitFinished();
transport.sync();
- pool.Close();
ASSERT_TRUE(exe1.gate.getCount() == 0u);
ASSERT_TRUE(exe2.gate.getCount() == 0u);
ASSERT_TRUE(exe3.gate.getCount() == 0u);
diff --git a/fnet/src/vespa/fnet/frt/supervisor.cpp b/fnet/src/vespa/fnet/frt/supervisor.cpp
index b08516c5009..966c606bf97 100644
--- a/fnet/src/vespa/fnet/frt/supervisor.cpp
+++ b/fnet/src/vespa/fnet/frt/supervisor.cpp
@@ -7,7 +7,6 @@
#include <vespa/fnet/transport.h>
#include <vespa/fnet/transport_thread.h>
#include <vespa/fnet/connector.h>
-#include <vespa/fastos/thread.h>
#include <vespa/vespalib/util/require.h>
FNET_IPacketStreamer *
@@ -291,11 +290,10 @@ FRT_Supervisor::SchedulerPtr::SchedulerPtr(FNET_TransportThread *transport_threa
namespace fnet::frt {
StandaloneFRT::StandaloneFRT(const TransportConfig &config)
- : _threadPool(std::make_unique<FastOS_ThreadPool>()),
- _transport(std::make_unique<FNET_Transport>(config)),
+ : _transport(std::make_unique<FNET_Transport>(config)),
_supervisor(std::make_unique<FRT_Supervisor>(_transport.get()))
{
- REQUIRE(_transport->Start(_threadPool.get()));
+ REQUIRE(_transport->Start());
}
StandaloneFRT::StandaloneFRT()
diff --git a/fnet/src/vespa/fnet/frt/supervisor.h b/fnet/src/vespa/fnet/frt/supervisor.h
index 93272e93b4a..0261c7863b9 100644
--- a/fnet/src/vespa/fnet/frt/supervisor.h
+++ b/fnet/src/vespa/fnet/frt/supervisor.h
@@ -13,7 +13,6 @@
namespace fnet { class TransportConfig; }
class FNET_Transport;
class FRT_Target;
-class FastOS_ThreadPool;
class FNET_Scheduler;
class FRT_RPCInvoker;
class FRT_IRequestWait;
@@ -106,7 +105,6 @@ public:
const FRT_Supervisor &supervisor() const { return *_supervisor; }
void shutdown();
private:
- std::unique_ptr<FastOS_ThreadPool> _threadPool;
std::unique_ptr<FNET_Transport> _transport;
std::unique_ptr<FRT_Supervisor> _supervisor;
};
diff --git a/fnet/src/vespa/fnet/transport.cpp b/fnet/src/vespa/fnet/transport.cpp
index ae864ea0821..1553fc010c0 100644
--- a/fnet/src/vespa/fnet/transport.cpp
+++ b/fnet/src/vespa/fnet/transport.cpp
@@ -136,6 +136,7 @@ FNET_Transport::FNET_Transport(const fnet::TransportConfig &cfg)
_time_tools(cfg.time_tools()),
_work_pool(std::make_unique<vespalib::ThreadStackExecutor>(1, fnet_work_pool, 1024)),
_threads(),
+ _pool(),
_config(cfg.config())
{
// TODO Temporary logging to track down overspend
@@ -146,7 +147,10 @@ FNET_Transport::FNET_Transport(const fnet::TransportConfig &cfg)
}
}
-FNET_Transport::~FNET_Transport() = default;
+FNET_Transport::~FNET_Transport()
+{
+ _pool.join();
+}
void
FNET_Transport::post_or_perform(vespalib::Executor::Task::UP task)
@@ -266,13 +270,12 @@ FNET_Transport::WaitFinished()
}
bool
-FNET_Transport::Start(FastOS_ThreadPool *pool)
+FNET_Transport::Start()
{
- bool result = true;
for (const auto &thread: _threads) {
- result &= thread->Start(pool);
+ thread->Start(_pool);
}
- return result;
+ return true;
}
void
diff --git a/fnet/src/vespa/fnet/transport.h b/fnet/src/vespa/fnet/transport.h
index 3f9328296d6..d658059f0bb 100644
--- a/fnet/src/vespa/fnet/transport.h
+++ b/fnet/src/vespa/fnet/transport.h
@@ -7,9 +7,9 @@
#include <vespa/vespalib/net/async_resolver.h>
#include <vespa/vespalib/net/crypto_engine.h>
#include <vespa/vespalib/util/time.h>
+#include <vespa/vespalib/util/thread.h>
class FNET_TransportThread;
-class FastOS_ThreadPool;
class FNET_Connector;
class FNET_IPacketStreamer;
class FNET_IServerAdapter;
@@ -111,6 +111,7 @@ private:
fnet::TimeTools::SP _time_tools;
std::unique_ptr<vespalib::SyncableThreadExecutor> _work_pool;
Threads _threads;
+ vespalib::ThreadPool _pool;
const FNET_Config _config;
/**
@@ -317,9 +318,8 @@ public:
* ok.
*
* @return thread create status.
- * @param pool threadpool that may be used to spawn new threads.
**/
- bool Start(FastOS_ThreadPool *pool);
+ bool Start();
/**
* Capture transport threads. Used for testing purposes,
diff --git a/fnet/src/vespa/fnet/transport_thread.cpp b/fnet/src/vespa/fnet/transport_thread.cpp
index 262cdaec190..970dc40150f 100644
--- a/fnet/src/vespa/fnet/transport_thread.cpp
+++ b/fnet/src/vespa/fnet/transport_thread.cpp
@@ -598,28 +598,28 @@ FNET_TransportThread::endEventLoop() {
bool
-FNET_TransportThread::Start(FastOS_ThreadPool *pool)
+FNET_TransportThread::Start(vespalib::ThreadPool &pool)
{
- return (pool != nullptr && pool->NewThread(this));
+ pool.start([this](){run();});
+ return true;
}
void
FNET_TransportThread::Main()
{
- Run(nullptr, nullptr);
+ run();
}
void
-FNET_TransportThread::Run(FastOS_ThreadInterface *thisThread, void *)
+FNET_TransportThread::run()
{
if (!InitEventLoop()) {
LOG(warning, "Transport: Run: Could not init event loop");
return;
}
while (EventLoopIteration()) {
- if (thisThread != nullptr && thisThread->GetBreakFlag())
- ShutDown(false);
+ // event loop must be stopped from the outside
}
}
diff --git a/fnet/src/vespa/fnet/transport_thread.h b/fnet/src/vespa/fnet/transport_thread.h
index 1911b11a81c..1744a3d60e5 100644
--- a/fnet/src/vespa/fnet/transport_thread.h
+++ b/fnet/src/vespa/fnet/transport_thread.h
@@ -6,9 +6,9 @@
#include "config.h"
#include "task.h"
#include "packetqueue.h"
-#include <vespa/fastos/thread.h>
#include <vespa/vespalib/net/socket_handle.h>
#include <vespa/vespalib/net/selector.h>
+#include <vespa/vespalib/util/thread.h>
#include <atomic>
#include <mutex>
#include <condition_variable>
@@ -26,7 +26,7 @@ class FNET_IServerAdapter;
* the network related work for the application in both client and
* server aspects.
**/
-class FNET_TransportThread : public FastOS_Runnable
+class FNET_TransportThread
{
friend class FNET_IOComponent;
@@ -195,7 +195,7 @@ public:
* Destruct object. This should NOT be done before the transport
* thread has completed it's work and raised the finished flag.
**/
- ~FNET_TransportThread() override;
+ ~FNET_TransportThread();
/**
@@ -425,7 +425,7 @@ public:
* @return thread create status.
* @param pool threadpool that may be used to spawn a new thread.
**/
- bool Start(FastOS_ThreadPool *pool);
+ bool Start(vespalib::ThreadPool &pool);
/**
@@ -440,5 +440,5 @@ public:
* This is where the transport thread lives, when started by
* invoking one of the @ref Main or @ref Start methods.
**/
- void Run(FastOS_ThreadInterface *thisThread, void *args) override;
+ void run();
};