I have indeed considered function pointers. I rejected that for several
reasons:
a) platforms are “full ports”, where the functionality is determined at
compile time
b) I do not desire nor intend to expose low level “platform” functionality
to library consumers.
c) Using a port should not require modifying application source code.
d) These functions are going to be called so much that I’d rather not have
to chase a function pointer.
The idea here is that only a small handful of people (those porting nng to
a new platform altogether) need to worry about this. I’m trying to make it
easy for those people, without impacting application consumers.
- Garrett
On Mon, Dec 12, 2016 at 10:23 AM, Karan, Cem F CIV USARMY RDECOM ARL (US) <
cem.f.karan.civ@xxxxxxxx> wrote:
OK, I just quickly looked at everything the platform directory; it appears
that you're defining the functions directly, correct? That would mean
you'd have to rewrite the functions directly to change how they are
implemented. Instead of that, have you considered defining function
pointers instead, so that library users can easily pass in different
implementations? E.g.:
typedef int (*nni_mutex_create_t)(nni_mutex_t *mp)
<< Lots more typedefs >>
typedef struct nni_thread_functions_t
{
nni_mutex_create_t nni_mutex_create;
<< Lots more stuff >>
} nni_thread_functions_t;
int void nni_set_threading_model(const nni_thread_functions_t* model)
{
<< Store it somewhere >>
}
It would require some more work under the hood to ensure that there aren't
any live threads when someone tries to call nni_set_threading_model() (so
you don't accidentally destroy active data structures), but with some work
it could be done. You could then ship the library with an initial set of
functions that support the C11 standard.
Thanks,
Cem Karan
-----Original Message-----On Behalf Of Garrett D'Amore
From: nanomsg-bounce@xxxxxxxxxxxxx [mailto:nanomsg-bounce@xxxxxxxxxxxxx]
Sent: Monday, December 12, 2016 12:05 PMthe identity of the sender, and confirm the authenticity of all links
To: nanomsg@xxxxxxxxxxxxx
Subject: [nanomsg] Re: [Non-DoD Source] Re: nanomsg rewrite - new API
All active links contained in this email were disabled. Please verify
contained within the message prior to copying and pasting the address toa Web browser.
the “platform” implements is “nni_thread_create()”. This creates a
________________________________
Yes. there is a platform porting layer, and one of the functions that
thread, or coroutine, or whatever. Not every platform has pthreads.synchronization objects at some point.
I actually intend to build a version of this that uses C11 threads and
<cem.f.karan.civ@xxxxxxxx < Caution-
On Mon, Dec 12, 2016 at 8:55 AM, Karan, Cem F CIV USARMY RDECOM ARL (US)
mailto:cem.f.karan.civ@xxxxxxxx ;> > wrote:something where all your code calls through a small set of well-
Are you going to create your own thread/process API? That is,
known POSIX thread-like functions that can be easily replaced bysomething else? That will make it much easier to test out green threads
vs. regular threads vs. full processes.nanomsg-bounce@xxxxxxxxxxxxx > [Caution-mailto:nanomsg-
Thanks,
Cem Karan
> -----Original Message-----
> From: nanomsg-bounce@xxxxxxxxxxxxx < Caution-mailto:
bounce@xxxxxxxxxxxxx < Caution-mailto:nanomsg-bounce@xxxxxxxxxxxxx ;> ]On Behalf Of Garrett D'Amore
> Sent: Monday, December 12, 2016 11:19 AMverify the identity of the sender, and confirm the authenticity of all
> To: nanomsg@xxxxxxxxxxxxx < Caution-mailto:nanomsg@xxxxxxxxxxxxx
> Subject: [Non-DoD Source] [nanomsg] Re: nanomsg rewrite - new API
>
> All active links contained in this email were disabled. Please
linksaddress to a Web browser.
> contained within the message prior to copying and pasting the
>endpoint. Plus one per socket at large. This allows me to use
>
> ________________________________
>
>
>
> Yes, I plan to use a single (or even two) threads per connection
simplevagaries of async I/O.
> blocking system calls, without having to worry about the
>implementations) can generally scale to huge numbers of threads. Recall
> Modern operating systems (or rather modern thread
that aspace. To get to 100k+ threads you’re going to need adequate RAM
> thread is really just a scheduling context with some stack
to hold theis just under a GB). It’s not hard to build meaningful systems that
> stacks (probably several GB in this case — e.g. 100k 8k stacks
have vastsame data (this is very important to scalability). You’re still
> numbers of threads, especially when they don’t contend on the
going to runthreads and make everything an event loop is “correct” — the
> out of ephemeral TCP ports before you hit this number.
>
> I don’t necessarily believe the current hype to turn away from
problem isApache) uses really heavy weight processes (where context
> that most of the threaded code that people look at (like say
switching requirescontend on shared resources (which is the situation where many
> changing MMU tables which is really really expensive), or
threadsinefficient. (This used to the situation long ago. These days
> perform worse than one), or where the threading framework is
threaddesign to support porting to different platforms, and will be able to
> libraries are *very* efficient.)
>
> Now, all that said, the code is being built with a very open
acceptthing that is *required* is that the implementation provide
> solutions that make use of coroutines or green threads. The only
high levelsynchronization primitives. (mutexes and condition variables).
> blocking calls for I/O, and thread creation, and a few
>< Caution-mailto:crest@xxxxxxxxx ;> < Caution-Caution-
> - Garrett
>
>
> On Mon, Dec 12, 2016 at 6:33 AM, Jan Bramkamp <crest@xxxxxxxxx
mailto:crest@xxxxxxxxx ;< Caution-mailto:crest@xxxxxxxxx ;> > > wrote:rewrite of nanomsg. This
>
>
>
>
> On 10/12/2016 08:25, Garrett D'Amore wrote:
>
>
> I have embarked on the creation of a complete
> rewrite utilizes threads to obtain concurrency.(In theory “green”
> threads or coroutines could be used as well, ifthe underlying platform
> supports the necessary I/O primitives. I’m notinterested in discussion
> of these internal details at this point, as Istrongly believe that it
> is possible to make a very performant library thatuses threading for
> asynchronous I/O and to engage with greater levelsof concurrency.)
>concurrency as you have proper threads that can block on everything and
>
>
> In some ways using kernel threads simplifies the
aren'tTargeting more than one platform increases the the burden even
> restricted to operations which are available as non-blocking.
furtherdifferent set of non-blocking operations e.g. FreeBSD offers
> because each platform (Linux, *BSD, OSX, Windows) offers a
working POSIXfor most applications.
> AIO on local file systems, but Linux AIO isn't worth the effort
>revised API for your
>
>
> The reason for my message here is to present a
> consideration. This API is quite different inmany respects from
> nanomsg — in particular it presents a more “objectoriented” API that
> uses “natural” objects rather than attempting tostrictly follow POSIX
> file descriptor semantics. (So for example,sockets are actual pointers
> to structures rather than integers, and you canobtain information about
> the sockets using pointers to opaque structuresinstead of trying to use
> the CMSG API. There is no attempt to provide a“file descriptor” type
> API as a first class citizen, although for thosethat need to use
> select() or poll() there will be a way to obtainnotification file
> descriptors. (Under the hood, those descriptorswill be lazy allocated,
> and not used at all unless someone demands this.I believe this will
> have a dramatic performance benefit for thelibrary, greatly reducing
> the total number of system calls required to sendand receive messages.
>abilities, like the ability to
> The API will also open up some new richer
> introspect into pipes, and to obtain informationabout where a message
> came from, or set different options for differentendpoints. Much of
> this is modeled on work I’ve done in mangos, whereI’ve been able to add
> functionality that folks have requested fornanomsg, but which I cannot
> easily add to nanomsg.API. (Again, let’s not
>
> Anyway, I’m opening this for discussion on the
> get bogged down in *how* I’m building this — I’mnot interested in the
> various eventing frameworks or async I/O engines —I’m doing this using
> threads.)would be a real scalability problem. Do know any up to date
>
>
>
> Do you really plan to use one thread per endpoint? This
> documentation how far which kernel can scale in this regard? Idoubt Linux or FreeBSD can handle 100k threads as well as they
can handlebe written in C (not
> just 100k sockets.
>
>
>
> Oh, and just to be clear, the new code will still
> C++), and retain the MIT license.because its ABI is the lowest common denominator in *nix systems and the
>
>
>
> Pleased to hear that. C is a lot more suitable this
MITapplication.
> license should allow anyone to integrate nanomsg into their
>with respect to adding
>
>
> This rewrite will facilitate a number of changes
> new protocols, and adding new transports. I lookforward to being able
> to add ZeroTier, UDP, TLS, and Websocket/HTTPS tothis implementation —
> something that is *extraordinarily* difficult todo in the existing
> implementation.libraries in nanomsg transports.
>
>
>
> Utilizing threads also simplifies reusing existing
>defines the nng.h API
>
>
> Without further ado, here’s the header that
> (nanomsgNG):applications. Will the objects be thread-safe or does the application
>
> [truncated]
>
>
>
> The API looks clean and easy to use without constraining
haveZeroMQ API without locking makes it very hard to provide sane
> to provide its own locking around the API like in ZeroMQ? The
bindings to
> some languages.
>
>
>