[nanomsg] Re: nanomsg rewrite - new API

  • From: "Martin \"eto\" Misuth" <et.code@xxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Wed, 14 Dec 2016 14:54:24 +0100

On Mon, 12 Dec 2016 12:42:17 -0800
"Garrett D'Amore" <garrett@xxxxxxxxxx> wrote:

If your threading library creates light weight processes (e.g. via clone()
on Linux), then yes, you’ll see them.  *Normally* with pthreads the
“process ID” is the same for all threads, as they belong to the same
“process”.

Some php runtimes are thread aware, but currently I am using normal php7
runtime, in "cli" mode. This doesn't know anything about threads. There is
extension module for php7 to enable pthreads, but I never used it.

POSIX threads (which is what Linux will use) have specific rules about
signals, and given that, its incredibly unlikely that your use of signals
will be in any way affected by the library.  In fact, libnanomsg *today*
creates threads (not very many), so this differs only in the number of
threads, not in the actual presence of them.

Thanks. For some time I experimented with POSIX AIO (which supposedly uses
(some kind of) threads on Linux, but later I scraped that experiment).
I think I also read somewhere, that current nanomsg uses threads (as in
pthreads) as well, before you confirmed that in previous email. 

What was extremely confusing to me, was the fact, even when listening on
nanomsg socket and traffic going on, I never saw any "thread" listed in ps
or htop.

However I saw some daemons and other software spawn these "subprocesses". 
These are visble in ps. I guess these are the "things", you called "light weight
processes" (let's call them LWPs - and I assume these are the ones created by
clone()). For me it was important to realise these are not(!) pthreads.

Just to be sure we understand each other, I will reiterate what I concluded
studying matter further:

  - these clone()ed LWP "things" are completely orthogonal to actual pthreads
    threads on Linux. 

  - LWPs are created by clone() call.
  - LWPs have distinct PID, can be sent signals selectively/accept signals and
    behave more like "subprocesses", but they share memory with leading
    ("parent") process.
  - LWPs can be observed by user/admin with ps.   

  - Real pthreads are created with pthread_create() call.
  - Real pthreads are "invisible" to most traditional process inspection
    tools.
  - Real pthreads have defined signal handling in such a way, that traditional
    handler as used in non-threading program, just works. This makes libraries
    like nanomsg possible.

  - Because nanomsg uses, and ng will use, only pthreads internally, it will
    always behave same way. I can effectively forget there are any pthreads
    going on in background.

Is this correct conclusion?

For your extant PHP code, you can definitely continue to use libnanomsg —
regardless of whether libnng exists or not.   Ideally in the future, libnng
will exist, and will offer a compatibility layer for legacy applications
like yours.

Thank you very much for assurance.

  eto

Other related posts: