Seastar
High performance C++ framework for concurrent servers
Classes | Typedefs | Functions | Variables
Multicore

Support for exploiting multiple cores on a server. More...

Classes

class  seastar::sharded< Service >
 
class  seastar::foreign_ptr< PtrType >
 
struct  seastar::is_smart_ptr< foreign_ptr< T > >
 

Typedefs

using seastar::foreign_ptr< PtrType >::element_type = typename std::pointer_traits< PtrType >::element_type
 

Functions

virtual const char * seastar::no_sharded_instance_exception::what () const noexcept override
 
 seastar::sharded< Service >::sharded ()
 
 seastar::sharded< Service >::sharded (const sharded &other)=delete
 
 seastar::sharded< Service >::sharded (sharded &&other)=default
 Moves a sharded object.
 
shardedseastar::sharded< Service >::operator= (const sharded &other)=delete
 
shardedseastar::sharded< Service >::operator= (sharded &&other)=default
 Moves a sharded object.
 
 seastar::sharded< Service >::~sharded ()
 Destroyes a sharded object. Must not be in a started state.
 
template<typename... Args>
future seastar::sharded< Service >::start (Args &&... args)
 
template<typename... Args>
future seastar::sharded< Service >::start_single (Args &&... args)
 
future seastar::sharded< Service >::stop ()
 
template<typename... Args>
future seastar::sharded< Service >::invoke_on_all (future<>(Service::*func)(Args...), Args... args)
 
template<typename... Args>
future seastar::sharded< Service >::invoke_on_all (void(Service::*func)(Args...), Args... args)
 
template<typename Func >
future seastar::sharded< Service >::invoke_on_all (Func &&func)
 
template<typename Reducer , typename Ret , typename... FuncArgs, typename... Args>
auto seastar::sharded< Service >::map_reduce (Reducer &&r, Ret(Service::*func)(FuncArgs...), Args &&... args) -> typename reducer_traits< Reducer >::future_type
 
template<typename Reducer , typename Func >
auto seastar::sharded< Service >::map_reduce (Reducer &&r, Func &&func) -> typename reducer_traits< Reducer >::future_type
 
template<typename Mapper , typename Initial , typename Reduce >
future< Initial > seastar::sharded< Service >::map_reduce0 (Mapper map, Initial initial, Reduce reduce)
 
template<typename Mapper , typename return_type = std::result_of_t<Mapper(Service&)>>
future< std::vector< return_type > > seastar::sharded< Service >::map (Mapper mapper)
 
template<typename Ret , typename... FuncArgs, typename... Args, typename FutureRet = futurize_t<Ret>>
FutureRet seastar::sharded< Service >::invoke_on (unsigned id, Ret(Service::*func)(FuncArgs...), Args &&... args)
 
template<typename Func , typename Ret = futurize_t<std::result_of_t<Func(Service&)>>>
Ret seastar::sharded< Service >::invoke_on (unsigned id, Func &&func)
 
Service & seastar::sharded< Service >::local ()
 Gets a reference to the local instance.
 
shared_ptr< Service > seastar::sharded< Service >::local_shared ()
 Gets a shared pointer to the local instance.
 
bool seastar::sharded< Service >::local_is_initialized ()
 Checks whether the local instance has been initialized.
 
 seastar::foreign_ptr< PtrType >::foreign_ptr ()
 Constructs a null foreign_ptr<>.
 
 seastar::foreign_ptr< PtrType >::foreign_ptr (std::nullptr_t)
 Constructs a null foreign_ptr<>.
 
 seastar::foreign_ptr< PtrType >::foreign_ptr (PtrType value)
 Wraps a pointer object and remembers the current core.
 
 seastar::foreign_ptr< PtrType >::foreign_ptr (const foreign_ptr &)=delete
 
 seastar::foreign_ptr< PtrType >::foreign_ptr (foreign_ptr &&other)=default
 Moves a foreign_ptr<> to another object.
 
 seastar::foreign_ptr< PtrType >::~foreign_ptr ()
 Destroys the wrapped object on its original cpu.
 
future< foreign_ptrseastar::foreign_ptr< PtrType >::copy () const
 Creates a copy of this foreign ptr. Only works if the stored ptr is copyable.
 
element_type & seastar::foreign_ptr< PtrType >::operator* () const
 Accesses the wrapped object.
 
element_type * seastar::foreign_ptr< PtrType >::operator-> () const
 Accesses the wrapped object.
 
 seastar::foreign_ptr< PtrType >::operator bool () const
 Checks whether the wrapped pointer is non-null.
 
foreign_ptrseastar::foreign_ptr< PtrType >::operator= (foreign_ptr &&other)=default
 Move-assigns a foreign_ptr<>.
 
template<typename T >
foreign_ptr< T > make_foreign (T ptr)
 

Variables

std::function< void()> seastar::async_sharded_service< T >::_delete_cb
 
shared_ptr< Service > seastar::sharded< Service >::entry::service
 
promise seastar::sharded< Service >::entry::freed
 

Detailed Description

Support for exploiting multiple cores on a server.

Seastar supports multicore servers by using sharding. Each logical core (lcore) runs a separate event loop, with its own memory allocator, TCP/IP stack, and other services. Shards communicate by explicit message passing, rather than using locks and condition variables as with traditional threaded programming.

Function Documentation

◆ invoke_on() [1/2]

template<typename Service>
template<typename Ret , typename... FuncArgs, typename... Args, typename FutureRet = futurize_t<Ret>>
FutureRet seastar::sharded< Service >::invoke_on ( unsigned  id,
Ret(Service::*)(FuncArgs...)  func,
Args &&...  args 
)
inline

Invoke a method on a specific instance of Service.

Parameters
idshard id to call
funca method of Service
argsarguments to be passed to func
Returns
result of calling func(args) on the designated instance

◆ invoke_on() [2/2]

template<typename Service>
template<typename Func , typename Ret = futurize_t<std::result_of_t<Func(Service&)>>>
Ret seastar::sharded< Service >::invoke_on ( unsigned  id,
Func &&  func 
)
inline

Invoke a callable on a specific instance of Service.

Parameters
idshard id to call
funca callable with signature Value (Service&) or future<Value> (Service&) (for some Value type)
Returns
result of calling func(instance) on the designated instance

◆ invoke_on_all() [1/2]

template<typename Service>
template<typename... Args>
future seastar::sharded< Service >::invoke_on_all ( void(Service::*)(Args...)  func,
Args...  args 
)
inline

Invoke a method on all Service instances in parallel.

Parameters
funcmember function to be called. Must return void or future<>.
argsarguments to be passed to func.
Returns
future that becomes ready when the method has been invoked on all instances.

◆ invoke_on_all() [2/2]

template<typename Service>
template<typename Func>
future seastar::sharded< Service >::invoke_on_all ( Func &&  func)
inline

Invoke a callable on all instances of Service.

Parameters
funca callable with the signature void (Service&) or future<> (Service&), to be called on each core with the local instance as an argument.
Returns
a future<> that becomes ready when all cores have processed the message.

◆ make_foreign()

template<typename T >
foreign_ptr< T > make_foreign ( ptr)
related

Wraps a raw or smart pointer object in a foreign_ptr<>.

◆ map()

template<typename Service>
template<typename Mapper , typename return_type = std::result_of_t<Mapper(Service&)>>
future<std::vector<return_type> > seastar::sharded< Service >::map ( Mapper  mapper)
inline

Applies a map function to all shards, and return a vector of the result.

Parameters
mappercallable with the signature Value (Service&) or future<Value> (Service&) (for some Value type).

Each map invocation runs on the shard associated with the service.

Template Parameters
Mapperunary function taking Service& and producing some result.
Returns
Result vector of applying map to each instance in parallel

◆ map_reduce() [1/2]

template<typename Service>
template<typename Reducer , typename Ret , typename... FuncArgs, typename... Args>
auto seastar::sharded< Service >::map_reduce ( Reducer &&  r,
Ret(Service::*)(FuncArgs...)  func,
Args &&...  args 
) -> typename reducer_traits<Reducer>::future_type
inline

Invoke a method on all instances of Service and reduce the results using Reducer.

See also
map_reduce(Iterator begin, Iterator end, Mapper&& mapper, Reducer&& r)

◆ map_reduce() [2/2]

template<typename Service>
template<typename Reducer , typename Func >
auto seastar::sharded< Service >::map_reduce ( Reducer &&  r,
Func &&  func 
) -> typename reducer_traits<Reducer>::future_type
inline

Invoke a callable on all instances of Service and reduce the results using Reducer.

See also
map_reduce(Iterator begin, Iterator end, Mapper&& mapper, Reducer&& r)

◆ map_reduce0()

template<typename Service>
template<typename Mapper , typename Initial , typename Reduce >
future<Initial> seastar::sharded< Service >::map_reduce0 ( Mapper  map,
Initial  initial,
Reduce  reduce 
)
inline

Applies a map function to all shards, then reduces the output by calling a reducer function.

Parameters
mapcallable with the signature Value (Service&) or future<Value> (Service&) (for some Value type). used as the second input to reduce
initialinitial value used as the first input to reduce.
reducebinary function used to left-fold the return values of map into initial .

Each map invocation runs on the shard associated with the service.

Template Parameters
Mapperunary function taking Service& and producing some result.
Initialany value type
Reducea binary function taking two Initial values and returning an Initial
Returns
Result of applying map to each instance in parallel, reduced by calling reduce() on each adjacent pair of results.

◆ sharded()

template<typename Service>
seastar::sharded< Service >::sharded ( )
inline

Constructs an empty sharded object. No instances of the service are created.

◆ start()

template<typename Service >
template<typename... Args>
future seastar::sharded< Service >::start ( Args &&...  args)

Starts Service by constructing an instance on every logical core with a copy of args passed to the constructor.

Parameters
argsArguments to be forwarded to Service constructor
Returns
a future<> that becomes ready when all instances have been constructed.

◆ start_single()

template<typename Service >
template<typename... Args>
future seastar::sharded< Service >::start_single ( Args &&...  args)

Starts Service by constructing an instance on a single logical core with a copy of args passed to the constructor.

Parameters
argsArguments to be forwarded to Service constructor
Returns
a future<> that becomes ready when the instance has been constructed.

◆ stop()

template<typename Service >
future seastar::sharded< Service >::stop ( )

Stops all started instances and destroys them.

For every started instance, its stop() method is called, and then it is destroyed.

Variable Documentation

◆ freed

template<typename Service>
promise seastar::sharded< Service >::entry::freed

◆ service

template<typename Service>
shared_ptr<Service> seastar::sharded< Service >::entry::service