24#include <unordered_set>
26#include <seastar/core/sharded.hh>
27#include <seastar/core/internal/pollable_fd.hh>
28#include <seastar/net/stack.hh>
29#include <seastar/core/polymorphic_temporary_buffer.hh>
30#include <seastar/core/internal/buffer_allocator.hh>
31#include <seastar/util/program-options.hh>
33#include <unordered_set>
48 std::vector<unsigned> _cpu_load;
50 load_balancer() : _cpu_load(
size_t(smp::count), 0) {}
51 void closed_cpu(shard_id cpu) {
58 auto min_el = std::min_element(_cpu_load.begin(), _cpu_load.end());
59 auto cpu = shard_id(std::distance(_cpu_load.begin(), min_el));
63 shard_id force_cpu(shard_id cpu) {
70 void closed_cpu(shard_id cpu) {
83 , _lb(make_foreign(std::move(lb))) {}
92 (void)
smp::submit_to(_host_cpu, [cpu = _target_cpu, lb = std::move(_lb)] {
102 conntrack() : _lb(make_lw_shared<load_balancer>()) {}
103 handle get_handle() {
104 return handle(_lb->next_cpu(), _lb);
106 handle get_handle(shard_id cpu) {
107 return handle(_lb->force_cpu(cpu), _lb);
112 std::pmr::polymorphic_allocator<char>* _buffer_allocator;
119 std::pmr::polymorphic_allocator<char>* allocator=memory::malloc_allocator)
120 : _buffer_allocator(allocator), _fd(std::move(fd)), _config(config) {
131 using data_sink_impl::put;
135 bool can_batch_flushes()
const noexcept override {
return true; }
136 void on_batch_flush_error()
noexcept override;
140 using protocol_and_socket_address = std::tuple<int, socket_address>;
147 using port_map_t = std::unordered_set<protocol_and_socket_address>;
148 using sockets_map_t = std::unordered_map<protocol_and_socket_address, promise<accept_result>>;
149 using conn_map_t = std::unordered_multimap<protocol_and_socket_address, connection>;
150 static thread_local port_map_t ports;
151 static thread_local sockets_map_t sockets;
152 static thread_local conn_map_t conn_q;
155 std::pmr::polymorphic_allocator<char>* _allocator;
160 virtual void abort_accept()
override;
166 template <
typename T>
167 friend class std::hash;
175 server_socket::load_balancing_algorithm _lba;
177 std::pmr::polymorphic_allocator<char>* _allocator;
180 server_socket::load_balancing_algorithm lba, shard_id fixed_cpu,
181 std::pmr::polymorphic_allocator<char>* allocator=memory::malloc_allocator) : _sa(sa), _protocol(protocol), _lfd(std::move(lfd)), _lba(lba), _fixed_cpu(fixed_cpu), _allocator(allocator) {}
183 virtual void abort_accept()
override;
191 std::pmr::polymorphic_allocator<char>* _allocator;
194 std::pmr::polymorphic_allocator<char>* allocator=memory::malloc_allocator) : _sa(sa), _protocol(protocol), _lfd(std::move(lfd)), _allocator(allocator) {}
196 virtual void abort_accept()
override;
202 const bool _reuseport;
204 std::pmr::polymorphic_allocator<char>* _allocator;
208 virtual ::seastar::socket
socket()
override;
213 return make_ready_future<std::unique_ptr<network_stack>>(std::unique_ptr<network_stack>(
new posix_network_stack(opts, allocator)));
215 virtual bool has_per_core_namespace()
override {
return _reuseport; };
216 bool supports_ipv6()
const override;
222 const bool _reuseport;
227 return make_ready_future<std::unique_ptr<network_stack>>(std::unique_ptr<network_stack>(
new posix_ap_network_stack(opts, allocator)));
Definition: iostream.hh:104
Definition: iostream.hh:61
Definition: sharded.hh:945
A representation of a possibly not-yet-computed value.
Definition: future.hh:1240
Definition: posix-stack.hh:74
Definition: posix-stack.hh:46
Definition: posix-stack.hh:220
Definition: posix-stack.hh:139
Definition: posix-stack.hh:126
Definition: posix-stack.hh:111
Definition: posix-stack.hh:200
std::vector< network_interface > network_interfaces() override
Definition: posix-stack.hh:187
Definition: posix-stack.hh:170
Definition: pollable_fd.hh:136
Definition: program-options.hh:293
A listening socket, waiting to accept incoming network connections.
Definition: api.hh:326
static futurize_t< std::invoke_result_t< Func > > submit_to(unsigned t, smp_submit_to_options options, Func &&func) noexcept
Definition: smp.hh:354
Definition: socket_defs.hh:47
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
shard_id this_shard_id() noexcept
Returns shard_id of the of the current shard.
Definition: shard_id.hh:52