msgpack-r | Fast reading and writing of Msgpack data in R msgpack.org | Code Editor library
kandi X-RAY | msgpack-r Summary
kandi X-RAY | msgpack-r Summary
Fast reading and writing of Msgpack data in R msgpack.org[R]
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of msgpack-r
msgpack-r Key Features
msgpack-r Examples and Code Snippets
Community Discussions
Trending Discussions on msgpack-r
QUESTION
I have a large, somewhat complicated data structure that I can serialize and deserialize with serde
and rmp-serde
, but I find that deserialization is quite slow. I think this is because my data structure includes two rather large HashMaps. I don't know how efficiently rmp_serde::from_slice
can create the HashMap -- will it initialize using .with_capacity
or does it just create a HashMap and insert one-by-one? And besides, I've found that AHashMap gives me considerable performance improvements elsewhere, so I'm trying to avoid using the default HashMap.
I want to try deserializing with rmpv::decode::value::read_value
, but I'd like to leave most of the deserialization to rmp_serde and only implement some deserialization myself given some Value
. Is there a way to choose which pieces I manually deserialize?
Conceptually, what I'd like to do is something like:
...ANSWER
Answered 2021-Feb-04 at 16:40I was able to get this to work using deserialize-with
. First, I had to annotate my struct:
QUESTION
I am working on a data system that needs to store large amounts of simple, extensible data (alongside some specialist indexing we are developing in-house, and not part of this question). I expect there to be billions of records stored, so efficient serialisation is a key part of the system. The serialisation needs to be fast, space-efficient, and supported in multiple platforms and languages (because packing and unpacking this data will be a client component responsibility, not part of the storage system)
The data type is effectively a hash with optional key/value pairs. Keys will be small integers (interpreted at application layer). Values can be a variety of simple data types - String, Integer, Float.
As a technology choice, we have picked MessagePack, and I am writing code to perform data serialisation via Ruby's msgpack-ruby gem.
I don't need the precision of Ruby's 64-bit Float. None of the numbers being stored has meaningful precision even to limits of 32-bit. So I want to use MessagePack support for 32-bit floating point values. This definitely exists. However, the default behaviour in Ruby on any 64-bit system is to serialise Float to 64 bits:
...ANSWER
Answered 2018-Sep-07 at 12:29As of right now (version 1.2.4 of msgpack-ruby
) this is not possible in the exact fashion you tried: the msgpack_packer_write_value
function first checks all hard-coded data types, and handles them with its default implementation. Only if the current object does not fit any of those types are the extensions handled.
In other words: you cannot override the default pack formats with MessagePack::DefaultFactory#register_type
, calling that will simply be a no-op.
Furthermore, the extension mechanism is not what you are looking at, anyways. Using that, messagepack would emit a marker byte "this is an extension", followed by the extension ID (the value "0" in your example), followed by what is already encoded as float32 - alternatively you would need to handle the binary encoding/decoding yourself.
Creating your own Float classYou could, in principle, create your own FloatX
class or whatever, but this is just a very bad move:
Float
has nonew
method which you could monkeypatch, and I know of no way to tell ruby to create aFloatX
instance when you write10.3
in your code. So you would have to do manual object creation throughout your code, probably with severe impact on performance.- You would end up with the extension mechanism anyways, infeasible as shown above.
msgpack_packer_write_value
You would need to to override the msgpack_packer_write_value
implementation of packer.c
. Unfortunately you cannot do that in the ruby world since there is no equivalent ruby method defined for it. So the usual monkeypatching of ruby cannot be used.
Also, the method is called from plenty of other methods inside the packer.c
implementation, for example in the respective methods responsible for writing arrays or hashes. Those of course would not call a ruby method of the same name either, as they're living in their binary world completely.
Finally, whily the usage of a factory mechanism seems to imply that you can somehow create different implementations of packers, I see no evidence that this is actually true - reading the C code of the Gem, there seems to be no provision for anything of that kind. The factory seems to be there to handle the ruby<->C interactions of the Gem.
What nowIf I were in your shoes, I would clone that Gem and modify msgpack_packer_write_value
in packer.c
to behave as you wish. Check the case T_FLOAT
and go on from there. The code seems pretty straightforward - it soon proceeds to the following method in packer.h
:
QUESTION
This question may be slightly off topic but I didn't know where else to ask. I was reading this https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md and saw that the specification included being able to send out of order messages using the same connection.
The only way I have done TCP socket programming before is by sending requests synchronously on a socket, for example, I will open a socket to 127.0.0.1
, send a request to that server through that socket and wait for a response. When I get the response for the request I have sent I close that connection by calling close()
on the client and close()
on the server after I have responded to the request.
For background, I am working on a project in C++ with libevent
to do something very similar to what RPC systems do, so I wanted to know what request response socket cycle I should use in the underlying transport system.
In C++ thrift there is a client method called open()
that (presumably) opens a connection and keeps it open until you call close()
. How does this work in systems where that is abstracted away? For example in that messagepack-RPC link I have included above. What is the best course of action? Open a connection if there is none, send the request and when all previous requests are served close that connection (on the server, call close()
when all pending requests have been responded to)? Or do we have to somehow try and keep that connection alive for a period of time that extends beyond the request lifetimes? How will the server and the client know what that time period is? For example should we register a read event handler on the socket and close the connection when recv()
returns 0
?
If this is a problem that different systems solve differently then can someone direct me to a resource that I can use to read up on possible patterns for keeping connections alive (preferably in event driven systems)? For example I read that HTTP servers always keep the connection open, why is that? Doesn't keeping every single connection open mean that the server will essentially leak memory?
Sorry about the seemingly basic question, I have only ever done really simple TCP socket programming before, so I might not know how things are done.
...ANSWER
Answered 2018-Jan-19 at 04:48- Use a connection pool at the client.
- Have a background thread in the client that expires idle connections after some timeout.
- Write the server so it can handle multiple requests on each accepted socket, i.e. loop reading requests and sending responses until the peer closes the connection, or a read timeout occurs reading the request, or a socket error occurs.
- Don't send a close message from either side. Closng the socket is sufficient.
- Don't use an application ping message to keep the connection alive. If the peer or an intermediate router considers connections so expensive as to terminate them after some period, you don't have any business trying to fool it.
All this is much how most HTTP implementations already work. Note the timeouts at both ends to control each end's idle resource usage.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install msgpack-r
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page