msgpack 1.3.3 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog +99 -0
- data/README.md +293 -0
- data/ext/java/org/msgpack/jruby/Buffer.java +26 -19
- data/ext/java/org/msgpack/jruby/Decoder.java +46 -23
- data/ext/java/org/msgpack/jruby/Encoder.java +68 -30
- data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +43 -64
- data/ext/java/org/msgpack/jruby/ExtensionValue.java +6 -9
- data/ext/java/org/msgpack/jruby/Factory.java +43 -42
- data/ext/java/org/msgpack/jruby/Packer.java +37 -40
- data/ext/java/org/msgpack/jruby/Unpacker.java +86 -68
- data/ext/msgpack/buffer.c +58 -85
- data/ext/msgpack/buffer.h +59 -20
- data/ext/msgpack/buffer_class.c +161 -52
- data/ext/msgpack/buffer_class.h +1 -0
- data/ext/msgpack/compat.h +1 -111
- data/ext/msgpack/extconf.rb +41 -23
- data/ext/msgpack/factory_class.c +143 -87
- data/ext/msgpack/packer.c +66 -43
- data/ext/msgpack/packer.h +25 -27
- data/ext/msgpack/packer_class.c +102 -130
- data/ext/msgpack/packer_class.h +11 -0
- data/ext/msgpack/packer_ext_registry.c +35 -40
- data/ext/msgpack/packer_ext_registry.h +41 -38
- data/ext/msgpack/rbinit.c +1 -1
- data/ext/msgpack/rmem.c +3 -4
- data/ext/msgpack/sysdep.h +5 -2
- data/ext/msgpack/unpacker.c +130 -126
- data/ext/msgpack/unpacker.h +22 -13
- data/ext/msgpack/unpacker_class.c +94 -124
- data/ext/msgpack/unpacker_class.h +11 -0
- data/ext/msgpack/unpacker_ext_registry.c +40 -28
- data/ext/msgpack/unpacker_ext_registry.h +21 -18
- data/lib/msgpack/bigint.rb +69 -0
- data/lib/msgpack/buffer.rb +9 -0
- data/lib/msgpack/factory.rb +140 -10
- data/lib/msgpack/packer.rb +10 -1
- data/lib/msgpack/symbol.rb +21 -4
- data/lib/msgpack/time.rb +1 -1
- data/lib/msgpack/unpacker.rb +14 -1
- data/lib/msgpack/version.rb +4 -8
- data/lib/msgpack.rb +7 -12
- data/msgpack.gemspec +9 -8
- metadata +37 -96
- data/.gitignore +0 -23
- data/.rubocop.yml +0 -36
- data/.travis.yml +0 -43
- data/Gemfile +0 -9
- data/README.rdoc +0 -225
- data/Rakefile +0 -78
- data/appveyor.yml +0 -18
- data/bench/pack.rb +0 -23
- data/bench/pack_log.rb +0 -33
- data/bench/pack_log_long.rb +0 -65
- data/bench/pack_symbols.rb +0 -28
- data/bench/run.sh +0 -14
- data/bench/run_long.sh +0 -35
- data/bench/run_symbols.sh +0 -26
- data/bench/unpack.rb +0 -21
- data/bench/unpack_log.rb +0 -34
- data/bench/unpack_log_long.rb +0 -67
- data/doclib/msgpack/buffer.rb +0 -193
- data/doclib/msgpack/core_ext.rb +0 -101
- data/doclib/msgpack/error.rb +0 -19
- data/doclib/msgpack/extension_value.rb +0 -9
- data/doclib/msgpack/factory.rb +0 -101
- data/doclib/msgpack/packer.rb +0 -208
- data/doclib/msgpack/time.rb +0 -22
- data/doclib/msgpack/timestamp.rb +0 -44
- data/doclib/msgpack/unpacker.rb +0 -183
- data/doclib/msgpack.rb +0 -87
- data/msgpack.org.md +0 -46
- data/spec/cases.json +0 -1
- data/spec/cases.msg +0 -0
- data/spec/cases_compact.msg +0 -0
- data/spec/cases_spec.rb +0 -39
- data/spec/cruby/buffer_io_spec.rb +0 -255
- data/spec/cruby/buffer_packer.rb +0 -29
- data/spec/cruby/buffer_spec.rb +0 -575
- data/spec/cruby/buffer_unpacker.rb +0 -19
- data/spec/cruby/unpacker_spec.rb +0 -70
- data/spec/ext_value_spec.rb +0 -99
- data/spec/exttypes.rb +0 -51
- data/spec/factory_spec.rb +0 -367
- data/spec/format_spec.rb +0 -301
- data/spec/jruby/benchmarks/shootout_bm.rb +0 -73
- data/spec/jruby/benchmarks/symbolize_keys_bm.rb +0 -25
- data/spec/jruby/unpacker_spec.rb +0 -186
- data/spec/msgpack_spec.rb +0 -214
- data/spec/pack_spec.rb +0 -61
- data/spec/packer_spec.rb +0 -557
- data/spec/random_compat.rb +0 -24
- data/spec/spec_helper.rb +0 -38
- data/spec/timestamp_spec.rb +0 -121
- data/spec/unpack_spec.rb +0 -57
- data/spec/unpacker_spec.rb +0 -716
data/.travis.yml
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
sudo: false
|
4
|
-
|
5
|
-
branches:
|
6
|
-
only:
|
7
|
-
- master
|
8
|
-
|
9
|
-
gemfile:
|
10
|
-
- Gemfile
|
11
|
-
|
12
|
-
before_install:
|
13
|
-
# This is only for Ruby 2.5.0, Bundler 1.16.1 and rubygems 2.7.3
|
14
|
-
# See https://github.com/travis-ci/travis-ci/issues/8969
|
15
|
-
- "[ \"x2.7.3\" = \"x\"$(gem --version) ] && gem update --system --no-document || echo \"no need to update rubygem\""
|
16
|
-
|
17
|
-
# http://rubies.travis-ci.org/
|
18
|
-
matrix:
|
19
|
-
include:
|
20
|
-
- rvm: 2.3.8
|
21
|
-
os: linux
|
22
|
-
- rvm: 2.4.5
|
23
|
-
os: linux
|
24
|
-
- rvm: 2.5.3
|
25
|
-
os: linux
|
26
|
-
- rvm: 2.6.1
|
27
|
-
os: linux
|
28
|
-
- rvm: 2.6.1
|
29
|
-
os: osx
|
30
|
-
- rvm: ruby-head
|
31
|
-
os: linux
|
32
|
-
- rvm: jruby-9.1.9.0
|
33
|
-
os: linux
|
34
|
-
- rvm: jruby-head
|
35
|
-
os: linux
|
36
|
-
- rvm: jruby-19mode
|
37
|
-
os: linux
|
38
|
-
allow_failures:
|
39
|
-
- rvm: 2.6.1
|
40
|
-
os: osx
|
41
|
-
- rvm: ruby-head
|
42
|
-
- rvm: jruby-head
|
43
|
-
- rvm: jruby-19mode
|
data/Gemfile
DELETED
data/README.rdoc
DELETED
@@ -1,225 +0,0 @@
|
|
1
|
-
|
2
|
-
= MessagePack
|
3
|
-
|
4
|
-
MessagePack[http://msgpack.org] is an efficient binary serialization format.
|
5
|
-
It lets you exchange data among multiple languages like JSON but it's faster and smaller.
|
6
|
-
For example, small integers (like flags or error code) are encoded into a single byte,
|
7
|
-
and typical short strings only require an extra byte in addition to the strings themselves.
|
8
|
-
|
9
|
-
If you ever wished to use JSON for convenience (storing an image with metadata) but could
|
10
|
-
not for technical reasons (binary data, size, speed...), MessagePack is a perfect replacement.
|
11
|
-
|
12
|
-
require 'msgpack'
|
13
|
-
msg = [1,2,3].to_msgpack #=> "\x93\x01\x02\x03"
|
14
|
-
MessagePack.unpack(msg) #=> [1,2,3]
|
15
|
-
|
16
|
-
Use RubyGems to install:
|
17
|
-
|
18
|
-
gem install msgpack
|
19
|
-
|
20
|
-
or build msgpack-ruby and install:
|
21
|
-
|
22
|
-
bundle
|
23
|
-
rake
|
24
|
-
gem install --local pkg/msgpack
|
25
|
-
|
26
|
-
|
27
|
-
= Use cases
|
28
|
-
|
29
|
-
* Create REST API returing MessagePack using Rails + [RABL](https://github.com/nesquena/rabl)
|
30
|
-
* Store objects efficiently serialized by msgpack on memcached or Redis
|
31
|
-
* In fact Redis supports msgpack in EVAL-scripts[http://redis.io/commands/eval]
|
32
|
-
* Upload data in efficient format from mobile devices such as smartphones
|
33
|
-
* MessagePack works on iPhone/iPad and Android. See also Objective-C[https://github.com/msgpack/msgpack-objectivec] and Java[https://github.com/msgpack/msgpack-java] implementations
|
34
|
-
* Design a portable protocol to communicate with embedded devices
|
35
|
-
* Check also Fluentd[http://fluentd.org/] which is a log collector which uses msgpack for the log format (they say it uses JSON but actually it's msgpack, which is compatible with JSON)
|
36
|
-
* Exchange objects between software components written in different languages
|
37
|
-
* You'll need a flexible but efficient format so that components exchange objects while keeping compatibility
|
38
|
-
|
39
|
-
= Portability
|
40
|
-
|
41
|
-
MessagePack for Ruby should run on x86, ARM, PowerPC, SPARC and other CPU architectures.
|
42
|
-
|
43
|
-
And it works with MRI (CRuby) and Rubinius.
|
44
|
-
Patches to improve portability is highly welcomed.
|
45
|
-
|
46
|
-
|
47
|
-
= Serializing objects
|
48
|
-
|
49
|
-
Use *MessagePack.pack* or *to_msgpack*:
|
50
|
-
|
51
|
-
require 'msgpack'
|
52
|
-
msg = MessagePack.pack(obj) # or
|
53
|
-
msg = obj.to_msgpack
|
54
|
-
|
55
|
-
== Streaming serialization
|
56
|
-
|
57
|
-
Packer provides advanced API to serialize objects in streaming style:
|
58
|
-
|
59
|
-
# serialize a 2-element array [e1, e2]
|
60
|
-
pk = MessagePack::Packer.new(io)
|
61
|
-
pk.write_array_header(2).write(e1).write(e2).flush
|
62
|
-
|
63
|
-
See {API reference}[http://ruby.msgpack.org/MessagePack/Packer.html] for details.
|
64
|
-
|
65
|
-
= Deserializing objects
|
66
|
-
|
67
|
-
Use *MessagePack.unpack*:
|
68
|
-
|
69
|
-
require 'msgpack'
|
70
|
-
obj = MessagePack.unpack(msg)
|
71
|
-
|
72
|
-
== Streaming deserialization
|
73
|
-
|
74
|
-
Unpacker provides advanced API to deserialize objects in streaming style:
|
75
|
-
|
76
|
-
# deserialize objects from an IO
|
77
|
-
u = MessagePack::Unpacker.new(io)
|
78
|
-
u.each do |obj|
|
79
|
-
# ...
|
80
|
-
end
|
81
|
-
|
82
|
-
or event-driven style which works well with EventMachine:
|
83
|
-
|
84
|
-
# event-driven deserialization
|
85
|
-
def on_read(data)
|
86
|
-
@u ||= MessagePack::Unpacker.new
|
87
|
-
@u.feed_each(data) {|obj|
|
88
|
-
# ...
|
89
|
-
}
|
90
|
-
end
|
91
|
-
|
92
|
-
See {API reference}[http://ruby.msgpack.org/MessagePack/Unpacker.html] for details.
|
93
|
-
|
94
|
-
= Serializing and deserializing symbols
|
95
|
-
|
96
|
-
By default, symbols are serialized as strings:
|
97
|
-
|
98
|
-
packed = :symbol.to_msgpack # => "\xA6symbol"
|
99
|
-
MessagePack.unpack(packed) # => "symbol"
|
100
|
-
|
101
|
-
This can be customized by registering an extension type for them:
|
102
|
-
|
103
|
-
MessagePack::DefaultFactory.register_type(0x00, Symbol)
|
104
|
-
|
105
|
-
# symbols now survive round trips
|
106
|
-
packed = :symbol.to_msgpack # => "\xc7\x06\x00symbol"
|
107
|
-
MessagePack.unpack(packed) # => :symbol
|
108
|
-
|
109
|
-
The extension type for symbols is configurable like any other extension type.
|
110
|
-
For example, to customize how symbols are packed you can just redefine
|
111
|
-
Symbol#to_msgpack_ext. Doing this gives you an option to prevent symbols from
|
112
|
-
being serialized altogether by throwing an exception:
|
113
|
-
|
114
|
-
class Symbol
|
115
|
-
def to_msgpack_ext
|
116
|
-
raise "Serialization of symbols prohibited"
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
MessagePack::DefaultFactory.register_type(0x00, Symbol)
|
121
|
-
|
122
|
-
[1, :symbol, 'string'].to_msgpack # => RuntimeError: Serialization of symbols prohibited
|
123
|
-
|
124
|
-
= Serializing and deserializing Time instances
|
125
|
-
|
126
|
-
There are the timestamp extension type in MessagePack,
|
127
|
-
but it is not registered by default.
|
128
|
-
|
129
|
-
To map Ruby's Time to MessagePack's timestamp for the default factory:
|
130
|
-
|
131
|
-
MessagePack::DefaultFactory.register_type(
|
132
|
-
MessagePack::Timestamp::TYPE, # or just -1
|
133
|
-
Time,
|
134
|
-
packer: MessagePack::Time::Packer,
|
135
|
-
unpacker: MessagePack::Time::Unpacker
|
136
|
-
)
|
137
|
-
|
138
|
-
See {API reference}[http://ruby.msgpack.org/] for details.
|
139
|
-
|
140
|
-
= Extension Types
|
141
|
-
|
142
|
-
Packer and Unpacker support {Extension types of MessagePack}[https://github.com/msgpack/msgpack/blob/master/spec.md#types-extension-type].
|
143
|
-
|
144
|
-
# register how to serialize custom class at first
|
145
|
-
pk = MessagePack::Packer.new(io)
|
146
|
-
pk.register_type(0x01, MyClass1, :to_msgpack_ext) # equal to pk.register_type(0x01, MyClass)
|
147
|
-
pk.register_type(0x02, MyClass2){|obj| obj.how_to_serialize() } # blocks also available
|
148
|
-
|
149
|
-
# almost same API for unpacker
|
150
|
-
uk = MessagePack::Unpacker.new()
|
151
|
-
uk.register_type(0x01, MyClass1, :from_msgpack_ext)
|
152
|
-
uk.register_type(0x02){|data| MyClass2.create_from_serialized_data(data) }
|
153
|
-
|
154
|
-
MessagePack::Factory is to create packer and unpacker which have same extension types.
|
155
|
-
|
156
|
-
factory = MessagePack::Factory.new
|
157
|
-
factory.register_type(0x01, MyClass1) # same with next line
|
158
|
-
factory.register_type(0x01, MyClass1, packer: :to_msgpack_ext, unpacker: :from_msgpack_ext)
|
159
|
-
pk = factory.packer(options_for_packer)
|
160
|
-
uk = factory.unpacker(options_for_unpacker)
|
161
|
-
|
162
|
-
For *MessagePack.pack* and *MessagePack.unpack*, default packer/unpacker refer *MessagePack::DefaultFactory*. Call *MessagePack::DefaultFactory.register_type* to enable types process globally.
|
163
|
-
|
164
|
-
MessagePack::DefaultFactory.register_type(0x03, MyClass3)
|
165
|
-
MessagePack.unpack(data_with_ext_typeid_03) #=> MyClass3 instance
|
166
|
-
|
167
|
-
= Buffer API
|
168
|
-
|
169
|
-
MessagePack for Ruby provides a buffer API so that you can read or write data by hand, not via Packer or Unpacker API.
|
170
|
-
|
171
|
-
This {MessagePack::Buffer}[http://ruby.msgpack.org/MessagePack/Buffer.html] is backed with a fixed-length shared memory pool which is very fast for small data (<= 4KB),
|
172
|
-
and has zero-copy capability which significantly affects performance to handle large binary data.
|
173
|
-
|
174
|
-
= How to build and run tests
|
175
|
-
|
176
|
-
Before building msgpack, you need to install bundler and dependencies.
|
177
|
-
|
178
|
-
gem install bundler
|
179
|
-
bundle install
|
180
|
-
|
181
|
-
Then, you can run the tasks as follows:
|
182
|
-
|
183
|
-
* Build
|
184
|
-
|
185
|
-
bundle exec rake build
|
186
|
-
|
187
|
-
* Run tests
|
188
|
-
|
189
|
-
bundle exec rake spec
|
190
|
-
|
191
|
-
* Generating docs
|
192
|
-
|
193
|
-
bundle exec rake doc
|
194
|
-
|
195
|
-
== How to build -java rubygems
|
196
|
-
|
197
|
-
To build -java gems for JRuby, run:
|
198
|
-
|
199
|
-
rake build:java
|
200
|
-
|
201
|
-
If this directory has Gemfile.lock (generated with MRI), remove it beforehand.
|
202
|
-
|
203
|
-
== How to build -mingw32 rubygems
|
204
|
-
|
205
|
-
MessagePack mingw32/64 rubygems build process uses {rake-compiler-dock}[https://github.com/rake-compiler/rake-compiler-dock]. Run:
|
206
|
-
|
207
|
-
rake build:windows
|
208
|
-
|
209
|
-
Once this step successes, target gems exist in pkg/msgpack-*-{x86,x64}-mingw32.gem.
|
210
|
-
|
211
|
-
== Updating documents
|
212
|
-
|
213
|
-
Online documents (http://ruby.msgpack.org) is generated from gh-pages branch.
|
214
|
-
Following commands update documents in gh-pages branch:
|
215
|
-
|
216
|
-
bundle exec rake doc
|
217
|
-
git checkout gh-pages
|
218
|
-
cp doc/* ./ -a
|
219
|
-
|
220
|
-
= Copyright
|
221
|
-
|
222
|
-
Author:: Sadayuki Furuhashi <frsyuki@gmail.com>
|
223
|
-
Copyright:: Copyright (c) 2008-2015 Sadayuki Furuhashi
|
224
|
-
License:: Apache License, Version 2.0
|
225
|
-
|
data/Rakefile
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'bundler'
|
3
|
-
Bundler::GemHelper.install_tasks
|
4
|
-
|
5
|
-
require 'fileutils'
|
6
|
-
|
7
|
-
require 'rspec/core'
|
8
|
-
require 'rspec/core/rake_task'
|
9
|
-
require 'yard'
|
10
|
-
|
11
|
-
task :spec => :compile
|
12
|
-
|
13
|
-
desc 'Run RSpec code examples and measure coverage'
|
14
|
-
task :coverage do |t|
|
15
|
-
ENV['SIMPLE_COV'] = '1'
|
16
|
-
Rake::Task["spec"].invoke
|
17
|
-
end
|
18
|
-
|
19
|
-
desc 'Generate YARD document'
|
20
|
-
YARD::Rake::YardocTask.new(:doc) do |t|
|
21
|
-
t.files = ['lib/msgpack/version.rb','doclib/**/*.rb']
|
22
|
-
t.options = []
|
23
|
-
t.options << '--debug' << '--verbose' if $trace
|
24
|
-
end
|
25
|
-
|
26
|
-
spec = eval File.read("msgpack.gemspec")
|
27
|
-
|
28
|
-
if RUBY_PLATFORM =~ /java/
|
29
|
-
require 'rake/javaextensiontask'
|
30
|
-
|
31
|
-
Rake::JavaExtensionTask.new('msgpack', spec) do |ext|
|
32
|
-
ext.ext_dir = 'ext/java'
|
33
|
-
jruby_home = RbConfig::CONFIG['prefix']
|
34
|
-
jars = ["#{jruby_home}/lib/jruby.jar"]
|
35
|
-
ext.classpath = jars.map { |x| File.expand_path(x) }.join(':')
|
36
|
-
ext.lib_dir = File.join(*['lib', 'msgpack', ENV['FAT_DIR']].compact)
|
37
|
-
ext.source_version = '1.6'
|
38
|
-
ext.target_version = '1.6'
|
39
|
-
end
|
40
|
-
else
|
41
|
-
require 'rake/extensiontask'
|
42
|
-
|
43
|
-
Rake::ExtensionTask.new('msgpack', spec) do |ext|
|
44
|
-
ext.ext_dir = 'ext/msgpack'
|
45
|
-
ext.cross_compile = true
|
46
|
-
ext.lib_dir = File.join(*['lib', 'msgpack', ENV['FAT_DIR']].compact)
|
47
|
-
# cross_platform names are of MRI's platform name
|
48
|
-
ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
test_pattern = case
|
53
|
-
when RUBY_PLATFORM =~ /java/ then 'spec/{,jruby/}*_spec.rb'
|
54
|
-
when RUBY_ENGINE =~ /rbx/ then 'spec/*_spec.rb'
|
55
|
-
else 'spec/{,cruby/}*_spec.rb' # MRI
|
56
|
-
end
|
57
|
-
RSpec::Core::RakeTask.new(:spec) do |t|
|
58
|
-
t.rspec_opts = ["-c", "-f progress"]
|
59
|
-
t.rspec_opts << "-Ilib"
|
60
|
-
t.pattern = test_pattern
|
61
|
-
t.verbose = true
|
62
|
-
end
|
63
|
-
|
64
|
-
namespace :build do
|
65
|
-
desc 'Build gem for JRuby after cleaning'
|
66
|
-
task :java => [:clean, :spec, :build]
|
67
|
-
|
68
|
-
desc 'Build gems for Windows per rake-compiler-dock'
|
69
|
-
task :windows do
|
70
|
-
require 'rake_compiler_dock'
|
71
|
-
# See RUBY_CC_VERSION in https://github.com/rake-compiler/rake-compiler-dock/blob/master/Dockerfile
|
72
|
-
RakeCompilerDock.sh 'bundle && gem i json && rake cross native gem RUBY_CC_VERSION=2.2.2:2.3.0:2.4.0:2.5.0:2.6.0:2.7.0'
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
CLEAN.include('lib/msgpack/msgpack.*')
|
77
|
-
|
78
|
-
task :default => [:spec, :build, :doc]
|
data/appveyor.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
---
|
2
|
-
install:
|
3
|
-
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
|
4
|
-
- ruby --version
|
5
|
-
- gem --version
|
6
|
-
- bundle install
|
7
|
-
build: off
|
8
|
-
test_script:
|
9
|
-
- bundle exec rake -rdevkit
|
10
|
-
|
11
|
-
environment:
|
12
|
-
matrix:
|
13
|
-
- ruby_version: "200"
|
14
|
-
- ruby_version: "200-x64"
|
15
|
-
- ruby_version: "21"
|
16
|
-
- ruby_version: "21-x64"
|
17
|
-
- ruby_version: "22"
|
18
|
-
- ruby_version: "22-x64"
|
data/bench/pack.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'viiite'
|
2
|
-
require 'msgpack'
|
3
|
-
|
4
|
-
data = { 'hello' => 'world', 'nested' => ['structure', {value: 42}] }
|
5
|
-
data_sym = { hello: 'world', nested: ['structure', {value: 42}] }
|
6
|
-
|
7
|
-
data = MessagePack.pack(:hello => 'world', :nested => ['structure', {:value => 42}])
|
8
|
-
|
9
|
-
Viiite.bench do |b|
|
10
|
-
b.range_over([10_000, 100_000, 1000_000], :runs) do |runs|
|
11
|
-
b.report(:strings) do
|
12
|
-
runs.times do
|
13
|
-
MessagePack.pack(data)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
b.report(:symbols) do
|
18
|
-
runs.times do
|
19
|
-
MessagePack.pack(data_sym)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/bench/pack_log.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'viiite'
|
2
|
-
require 'msgpack'
|
3
|
-
|
4
|
-
data_plain = { 'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"' }
|
5
|
-
data_structure = {
|
6
|
-
'remote_host' => '127.0.0.1',
|
7
|
-
'remote_user' => '-',
|
8
|
-
'date' => '10/Oct/2000:13:55:36 -0700',
|
9
|
-
'request' => 'GET /apache_pb.gif HTTP/1.0',
|
10
|
-
'method' => 'GET',
|
11
|
-
'path' => '/apache_pb.gif',
|
12
|
-
'protocol' => 'HTTP/1.0',
|
13
|
-
'status' => 200,
|
14
|
-
'bytes' => 2326,
|
15
|
-
'referer' => 'http://www.example.com/start.html',
|
16
|
-
'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
|
17
|
-
}
|
18
|
-
|
19
|
-
Viiite.bench do |b|
|
20
|
-
b.range_over([10_000, 100_000, 1000_000], :runs) do |runs|
|
21
|
-
b.report(:plain) do
|
22
|
-
runs.times do
|
23
|
-
MessagePack.pack(data_plain)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
b.report(:structure) do
|
28
|
-
runs.times do
|
29
|
-
MessagePack.pack(data_structure)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/bench/pack_log_long.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
# viiite report --regroup bench,threads bench/pack_log_long.rb
|
2
|
-
|
3
|
-
require 'viiite'
|
4
|
-
require 'msgpack'
|
5
|
-
|
6
|
-
data_plain = { 'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"' }
|
7
|
-
data_structure = {
|
8
|
-
'remote_host' => '127.0.0.1',
|
9
|
-
'remote_user' => '-',
|
10
|
-
'date' => '10/Oct/2000:13:55:36 -0700',
|
11
|
-
'request' => 'GET /apache_pb.gif HTTP/1.0',
|
12
|
-
'method' => 'GET',
|
13
|
-
'path' => '/apache_pb.gif',
|
14
|
-
'protocol' => 'HTTP/1.0',
|
15
|
-
'status' => 200,
|
16
|
-
'bytes' => 2326,
|
17
|
-
'referer' => 'http://www.example.com/start.html',
|
18
|
-
'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
|
19
|
-
}
|
20
|
-
|
21
|
-
seconds = 3600 # 1 hour
|
22
|
-
|
23
|
-
Viiite.bench do |b|
|
24
|
-
b.range_over([1, 2, 4, 8, 16], :threads) do |threads|
|
25
|
-
b.report(:plain) do
|
26
|
-
ths = []
|
27
|
-
end_at = Time.now + seconds
|
28
|
-
threads.times do
|
29
|
-
t = Thread.new do
|
30
|
-
packs = 0
|
31
|
-
while Time.now < end_at
|
32
|
-
10000.times do
|
33
|
-
MessagePack.pack(data_plain)
|
34
|
-
end
|
35
|
-
packs += 10000
|
36
|
-
end
|
37
|
-
packs
|
38
|
-
end
|
39
|
-
ths.push t
|
40
|
-
end
|
41
|
-
sum = ths.reduce(0){|r,t| r + t.value }
|
42
|
-
puts "MessagePack.pack, plain, #{threads} threads: #{sum} times, #{sum / seconds} times/second."
|
43
|
-
end
|
44
|
-
|
45
|
-
b.report(:structure) do
|
46
|
-
ths = []
|
47
|
-
end_at = Time.now + seconds
|
48
|
-
threads.times do
|
49
|
-
t = Thread.new do
|
50
|
-
packs = 0
|
51
|
-
while Time.now < end_at
|
52
|
-
10000.times do
|
53
|
-
MessagePack.pack(data_structure)
|
54
|
-
end
|
55
|
-
packs += 10000
|
56
|
-
end
|
57
|
-
packs
|
58
|
-
end
|
59
|
-
ths.push t
|
60
|
-
end
|
61
|
-
sum = ths.reduce(0){|r,t| r + t.value }
|
62
|
-
puts "MessagePack.pack, structured, #{threads} threads: #{sum} times, #{sum / seconds} times/second."
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
data/bench/pack_symbols.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'viiite'
|
2
|
-
require 'msgpack'
|
3
|
-
|
4
|
-
data = :symbol
|
5
|
-
|
6
|
-
Viiite.bench do |b|
|
7
|
-
b.variation_point :branch, `git rev-parse --abbrev-ref HEAD`
|
8
|
-
|
9
|
-
b.range_over([:symbol, :none], :reg_type) do |reg_type|
|
10
|
-
packer = MessagePack::Packer.new
|
11
|
-
packer.register_type(0x00, Symbol, :to_msgpack_ext) if reg_type == :symbol
|
12
|
-
|
13
|
-
b.range_over([100_000, 1_000_000, 10_000_000], :count) do |count|
|
14
|
-
packer.clear
|
15
|
-
b.report(:multi_run) do
|
16
|
-
count.times do
|
17
|
-
packer.pack(data)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
packer.clear
|
22
|
-
items_data = [].fill(data, 0, count)
|
23
|
-
b.report(:large_run) do
|
24
|
-
packer.pack(items_data)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/bench/run.sh
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
|
3
|
-
# prerequisites
|
4
|
-
# $ rbenv shell 2.2.1 (or jruby-x.x.x or ...)
|
5
|
-
# $ rake install
|
6
|
-
|
7
|
-
echo "pack"
|
8
|
-
viiite report --regroup bench,runs bench/pack.rb
|
9
|
-
echo "unpack"
|
10
|
-
viiite report --regroup bench,runs bench/unpack.rb
|
11
|
-
echo "pack log"
|
12
|
-
viiite report --regroup bench,runs bench/pack_log.rb
|
13
|
-
echo "unpack log"
|
14
|
-
viiite report --regroup bench,runs bench/unpack_log.rb
|
data/bench/run_long.sh
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
|
3
|
-
# prerequisites
|
4
|
-
# $ sudo apt-get install sysstat
|
5
|
-
# $ rbenv shell 2.2.1 (or jruby-x.x.x or ...)
|
6
|
-
# $ rake install
|
7
|
-
|
8
|
-
# 60 * 600 : 60*60 * 5[threads] * 2[bench]
|
9
|
-
|
10
|
-
ruby -v
|
11
|
-
|
12
|
-
echo "pack log long"
|
13
|
-
viiite report --regroup bench,threads bench/pack_log_long.rb &
|
14
|
-
sar -o pack_log_long.sar -r 60 600 > /dev/null 2>&1 &
|
15
|
-
|
16
|
-
declare -i i=0
|
17
|
-
while [ $i -lt 600 ]; do
|
18
|
-
ps auxww | grep ruby | grep -v grep | awk '{print $5,$6;}' >> pack_log_long.mem.txt
|
19
|
-
i=i+1
|
20
|
-
sleep 60
|
21
|
-
done
|
22
|
-
|
23
|
-
sleep 120 # cool down
|
24
|
-
|
25
|
-
echo "unpack log long"
|
26
|
-
viiite report --regroup bench,threads bench/unpack_log_long.rb &
|
27
|
-
sar -o unpack_log_long.sar -r 60 600 > /dev/null 2>&1 &
|
28
|
-
|
29
|
-
i=0
|
30
|
-
while [ $i -lt 600 ]; do
|
31
|
-
ps auxww | grep ruby | grep -v grep | awk '{print $5,$6;}' >> pack_log_long.mem.txt
|
32
|
-
i=i+1
|
33
|
-
sleep 60
|
34
|
-
done
|
35
|
-
|
data/bench/run_symbols.sh
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
|
3
|
-
# so master and this branch have the benchmark file in any case
|
4
|
-
cp bench/pack_symbols.rb bench/pack_symbols_tmp.rb
|
5
|
-
|
6
|
-
benchmark=""
|
7
|
-
current_branch=`git rev-parse --abbrev-ref HEAD`
|
8
|
-
|
9
|
-
for branch in master $current_branch; do
|
10
|
-
echo "Testing branch $branch"
|
11
|
-
git checkout $branch
|
12
|
-
|
13
|
-
echo "Installing gem..."
|
14
|
-
rake install
|
15
|
-
|
16
|
-
echo "Running benchmark..."
|
17
|
-
if [ "$benchmark" ]; then
|
18
|
-
benchmark+=$'\n'
|
19
|
-
fi
|
20
|
-
benchmark+=$(viiite run bench/pack_symbols_tmp.rb)
|
21
|
-
echo
|
22
|
-
done
|
23
|
-
|
24
|
-
rm bench/pack_symbols_tmp.rb
|
25
|
-
|
26
|
-
echo "$benchmark" | viiite report --regroup bench,reg_type,count,branch
|
data/bench/unpack.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'viiite'
|
2
|
-
require 'msgpack'
|
3
|
-
|
4
|
-
data = MessagePack.pack(:hello => 'world', :nested => ['structure', {:value => 42}])
|
5
|
-
|
6
|
-
Viiite.bench do |b|
|
7
|
-
b.range_over([10_000, 100_000, 1000_000], :runs) do |runs|
|
8
|
-
b.report(:strings) do
|
9
|
-
runs.times do
|
10
|
-
MessagePack.unpack(data)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
b.report(:symbols) do
|
15
|
-
options = {:symbolize_keys => true}
|
16
|
-
runs.times do
|
17
|
-
MessagePack.unpack(data, options)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/bench/unpack_log.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'viiite'
|
2
|
-
require 'msgpack'
|
3
|
-
|
4
|
-
data_plain = MessagePack.pack({ 'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"' })
|
5
|
-
|
6
|
-
data_structure = MessagePack.pack({
|
7
|
-
'remote_host' => '127.0.0.1',
|
8
|
-
'remote_user' => '-',
|
9
|
-
'date' => '10/Oct/2000:13:55:36 -0700',
|
10
|
-
'request' => 'GET /apache_pb.gif HTTP/1.0',
|
11
|
-
'method' => 'GET',
|
12
|
-
'path' => '/apache_pb.gif',
|
13
|
-
'protocol' => 'HTTP/1.0',
|
14
|
-
'status' => 200,
|
15
|
-
'bytes' => 2326,
|
16
|
-
'referer' => 'http://www.example.com/start.html',
|
17
|
-
'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
|
18
|
-
})
|
19
|
-
|
20
|
-
Viiite.bench do |b|
|
21
|
-
b.range_over([10_000, 100_000, 1000_000], :runs) do |runs|
|
22
|
-
b.report(:plain) do
|
23
|
-
runs.times do
|
24
|
-
MessagePack.unpack(data_plain)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
b.report(:structure) do
|
29
|
-
runs.times do
|
30
|
-
MessagePack.unpack(data_structure)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|