Comments (6)
So once you send, yes, the function assumes ownership of the message, and will return it back to the pool when done.
It might be possible to build a system where instead of nng_msg_free returning the message to the heap directly, it calls a user-supplied callback which could then reuse it. This would reduce pressure on the heap, although you probably would not achieve precisely what you want with respect to a single memory region.
Other solutions are also possible under the hood, but they would involve more data copies, which is something that I think you're trying to avoid.
from nng.
Sorry for being so late to get back to you.
The best way to do explicitly manage memory is to use nng_msg_alloc() with large messages, and then use those. This will avoid copying data.
For those you can use nng_ctx_send, nng_ctx_recv, or nng_send_aio(), or nng_recv_aio().
What happens is that these utilize the message memory directly. The older NNG_FLAG_ALLOC is a convenience and intended mostly for compatibility with legacy nanomsg. It isn't as efficient as allocating the messages directly.
To allocate the message directly, you can allocate it for as large as you think it will grow. Then you can either truncate it and grow it, or just access the body directly.
You should ignore nng_aio_set_iov... that API is indeed for the underlying byte stream APIs, and not intended for the SP message oriented protocols.
from nng.
Note that if you use nng_msg_append() or something like that, then it definitely is not zero copy. The trick to zero copy is to use the message memory directly.
Also, btw, it isn't truly zero copy. It's less copies. True zero copy requires rather sophisticated memory management and hardware support for direct DMA, etc. Generally what we have done here is usually good enough, but for extreme high performance you'll probably want to investigate RDMA or something like that.
from nng.
And 100K requests per second is not extreme high performance, unless they are very large.
from nng.
Thanks for your reply.
Using nng_msg_alloc() and building the message in place may be a very reasonable solution. On the other hand, I was considering doing one allocation per context, rather than per message. I was hoping to get around The function assumes ownership of the message
.
If I could pre-allocate the space for responses too, that would solve the alignment problem.
If it is not possible, would you like to sketch what the implementation would entail? In case anyone finds time to work on it.
from nng.
Note that with respect to responses, the function normally allocates messages with a certain amount of "head room". This ensures that you can inject or change headers if you need to. Again, this isn't exactly what you're asking for, but it may help.
from nng.
Related Issues (20)
- If I understand correctly, NNG's REP is analog to ROUTER when in raw mode or using a context object for asynchronous operations. REQ is similarly analog to DEALER when in raw mode or using a context object. So these socket types are unnecessary... I presume that the same reasoning applies to the lack of XPUB/XSUB in NNG. HOT 1
- Replace ZMQ(router/dealer) to NNG in raw mode problem HOT 1
- [Question] How to pass a value or datas in the callback function of nng_aio_alloc?
- Your text about Russia/Ukraine (typo) HOT 1
- Websocket masking could a lot faster
- IPC socket could support setting ownership HOT 1
- Missing Header in posix_rand_getrandom.c
- nng_msg_insert: munmap_chunk(): invalid pointer HOT 3
- Deadlock during nng_close() - multi platform HOT 23
- Sendmsg Thread Blocking HOT 1
- How to create a new language binding using a binary/dll? HOT 1
- Compiler warnings / errors from new logging feature on Windows HOT 2
- Windows a deadlock on `nng_close()` HOT 13
- mqttv5_client chokes on CONNACK packet HOT 2
- Setting TLS config option via nng_socket_set_ptr causes access violation if you free config HOT 3
- Memory Leak in nng_rep0_open HOT 2
- IPC - Use After Free HOT 1
- Will the NNG framework built-in handle packet splitting and sticking issues during streaming transmission? HOT 2
- Tools or API could obtain all communication endpoint information for establishing communication with this machine HOT 2
- nng_socket_set_ms didn't work HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nng.