[nanomsg] Re: where could get the detail design docment ?

  • From: yuanzhi <yuanzhisoft@xxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Sat, 18 May 2013 15:26:31 +0800 (CST)

Hi, Martin


Thanks for your reply, it's very kind of you:-)


>> 3. the transport msg format
>> +---+----+-------+----------
>> | tag| size | etc ... | payload...
>> +---+----+-------+----------
>
>I guess you are asking about TCP transport:
>
>8 byte protocol header followed by messages. Each message starts with 8 
>byte size in network byte order followed by the payload.
>
>On top of that, there's a messaging-pattern specific protocol (pub/sub, 
>req/rep etc.)
yes, you are right, what i mean is how protocol header orgnized, I know nanomsg 
has something to do with ZMQ, and ZMQ has it's own protocol called The ZeroMQ 
Message Transport Protocol (ZMTP), whether nanomsg has the same description 
about the procotol?
 
>> and also i've got an explicit question on REQREP
>> Dose the REQREP support asynchronous msg? I wanna send many request
>> through the same socket at the same time in a message loop, and when
>> replies come back i should deal with it and find the related request.
>> eg.
>> switch (event)
>> {
>> case event_req:
>> send_req();
>> append_req_to_list();
>> break;
>> case event_reply:
>> req = get_req_by_reply_from_list(reply);
>> process(req, reply);
>> break;
>> }
>
>You can do that using raw REQ and REP sockets. Use AF_SP_RAW address 
>family when creating the sockets.
>
Sorry, i didn't explain myself clearly, and i don't kown how AF_SP_RAW really 
means, and how does it works, i'll show my question again, with the following 
description


when I'm reading the code tests/reqrep.c, I find when writting a server, it's 
architecture is:
s = nn_socket() ; -> nn_bind();
and the relevant client's architecture is:
c = nn_socket(); -> nn_connect(SRV_ADDR); 
on server side, i wanna know where is the listen(), accept()?


if client's code written like this:
Client1:
c1 = nn_socket(AF_SP, NN_REQ);
nn_connect(c1, SOCKET_ADDRESS);
nn_send(c1, "ABC", 3, 0);


Client2:
c2 = nn_socket(AF_SP, NN_REQ);
nn_connect(c2, SOCKET_ADDRESS);

nn_send(c2, "DEF", 3, 0);


and server-side code written like this
Server:
nn_connect(c1)
if server code written like this:
s = nn_socket(AF_SP, NN_REP);
nn_bind(s, SOCKET_ADDRESS);
nn_send(s, "ABC", 3, 0); // will this send to all the client connected to the 
server?
nn_recv(s, buf, sizeof(buf), 0); // how could i know which client it is now(the 
s is bind() socket, but not accept() socket)


the other question is when i'm writting a client with multi-thread


MainThread:


c = nn_soket()
nn_connect(c, SOCKET_ADDRESS);


Thread-send:
while(1)
{
     nn_send(c, "ABC", 3, 0); // here the question is the function 
nn_req_send() seems could only send one request until the reply has came back. 
because, if it is not in STATE_IDLE, it will be cancled.
}


Thread-recv:
while(1)
{
    nn_recv(c, buf, sizeof(buf), 0); // how can i tell the reply to which 
request?
    proc(buf);
}


or maybe the reqrep is the stop-and-wait protocol, we couldn't use it as a 
pipeline interact.


Do i have some thinking completely wrong on the reqrep protocol?


I think i should read the source code  carefully and correctly before asking 
all the questions. thx again!

Yuanzhi


At 2013-05-18 00:52:03,"Martin Sustrik" <sustrik@xxxxxxxxxx> wrote:
>Hi Yuanzhi,
>
>> I wanna know how to find the design document which could tell:
>
>The project is in early stage so there are no detailed design documents. 
>There are few relevant blog posts here: 250bpm.com/blog though.
>
>> 1. the workflow
>> how the data encapsulate and send to the wire?
>
>nn_send (socket, buffer, buffer_size, flags);
>
>see nn_send(3) manual page
>
>> 2. the communication shceme
>> is the socket synchronous or asynchronous?
>
>It's asynchronous, i.e. when nn_send() exits it means the message was 
>sent, not that it was received by the peer.
>
>> 3. the transport msg format
>> +---+----+-------+----------
>> | tag| size | etc ... | payload...
>> +---+----+-------+----------
>
>I guess you are asking about TCP transport:
>
>8 byte protocol header followed by messages. Each message starts with 8 
>byte size in network byte order followed by the payload.
>
>On top of that, there's a messaging-pattern specific protocol (pub/sub, 
>req/rep etc.)
>
>> 4. the memory management
>> will the lib cause memery fragmentation, how large of payload could the
>> lib send, is there a memory pool, could user custom there own memory
>> management?
>> and so on.
>
>Every program causes some amount of memory fragmentation.
>
>You can send anything that fits into memory.
>
>There's no nanomsg-specific memory pool. It relies on C runtime/OS to 
>pool the memory.
>
>If you want to use custom memory allocation, just use an alternative 
>implementation of malloc/free/realloc in the way similar to tcmalloc, 
>jemalloc etc. Alternatively you can patch src/utils/alloc.c file and add 
>your memory allocation routines there.
>
>> and also i've got an explicit question on REQREP
>> Dose the REQREP support asynchronous msg? I wanna send many request
>> through the same socket at the same time in a message loop, and when
>> replies come back i should deal with it and find the related request.
>> eg.
>> switch (event)
>> {
>> case event_req:
>> send_req();
>> append_req_to_list();
>> break;
>> case event_reply:
>> req = get_req_by_reply_from_list(reply);
>> process(req, reply);
>> break;
>> }
>
>You can do that using raw REQ and REP sockets. Use AF_SP_RAW address 
>family when creating the sockets.
>
>Martin
>

Other related posts: