Three Ruby usages

Kouhei Sutou
Kouhei SutouFree Software Programmer at ClearCode
Three Ruby usages 
Kouhei Sutou 
ClearCode Inc. 
RubyKaigi 2014 
2014/09/20 
Three Ruby usages Powered by Rabbit 2.1.4
Silver sponsor 
Three Ruby usages Powered by Rabbit 2.1.4
Goal 
You know three Ruby usages 
✓High-level interface 
✓Glue 
✓Embed 
✓ 
✓You can remember them later 
Three Ruby usages Powered by Rabbit 2.1.4
Targets 
High-level interface 
✓Pure Rubyists 
✓ 
Glue 
✓Rubyists who can write C/C++ 
✓ 
Embed 
✓Rubyists who also write C/C++ 
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
Case study 
Implement distributed 
full-text search engine in 
Ruby 
Abbreviation: DFTSE = Distributed Full-Text Search Engine 
Three Ruby usages Powered by Rabbit 2.1.4
DFTSE? 
Distrubuted 
Full- 
Text 
Search 
Engine 
Full- 
Text 
Search 
Engine 
1: Full-text search 
2: Distribute 
sub requests 
3: Merge 
responses 
Three Ruby usages Powered by Rabbit 2.1.4
Why do we use DFTSE? 
I'm developing 
Droonga 
(A DFTSE implementation in Ruby) 
 
Three Ruby usages Powered by Rabbit 2.1.4
High-level interface 
Three Ruby usages 
High-level interface 
Target: ✓ Pure Rubyists 
✓ 
✓Glue 
✓Embed 
Three Ruby usages Powered by Rabbit 2.1.4
High-level interface 
Provides 
lower layer feature to 
higher layer 
✓ 
With simpler/✓ convenience API 
Three Ruby usages Powered by Rabbit 2.1.4
High-level interface 
Higher layer users 
High-level 
interface 
Feature 
by Yukihiro Matsumoto 
Application/Library 
Three Ruby usages Powered by Rabbit 2.1.4
Example 
Vagrant Active Record 
Developers 
Vagrantfile 
Build 
development 
environment 
Vagrant 
b y Y u k i h i r o M a t s u m o t o 
Developers 
Object based API 
b y Y u k i h i r o M a t s u m o t o 
Access data in RDBMS 
Active Record 
Three Ruby usages Powered by Rabbit 2.1.4
Droonga: High-level IF 
DFTSE components 
Full-✓ text search engine 
✓Messaging system 
✓Cluster management 
✓Process management 
Three Ruby usages Powered by Rabbit 2.1.4
Messaging system 
1: Full-text search DTFSE 
FTSE 
2: Distribute 
sub requests 
3: Merge 
responses 
Worker 
process 
Messaging 
system 
Three Ruby usages Powered by Rabbit 2.1.4
Messaging system 
Provides 
distributed search feature 
✓Plan how to search 
✓Distribute requests 
✓Merge responses 
✓ 
✓Users don't know details 
Three Ruby usages Powered by Rabbit 2.1.4
Characteristic 
Plan how to search 
May speed up/✓ down over 100 times 
✓ 
Distribute requests 
✓Network bound operation 
✓ 
Merge responses 
✓CPU and network bound operation 
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
Point 
Algorithm is important 
Need to find new/existing better 
algorithm 
✓ 
"Rapid prototype and measure" 
feedback loop is helpful 
✓ 
Ruby is ✓ good at rapid dev. 
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
Glue 
Three Ruby usages 
✓High-level interface 
Glue 
Target: 
Rubyists who can write C/C++ 
✓ 
✓ 
✓Embed 
Three Ruby usages Powered by Rabbit 2.1.4
Glue 
Export 
a feature 
Feature 
Combine 
features 
Glue 
Ruby 
Other 
Language 
Three Ruby usages Powered by Rabbit 2.1.4
Example 
mysql2 gem 
Vagrant 
Access to MySQL VM Provision 
libmysqlclient.so 
(VirtualBox) (Chef) 
Feature 
Active Record 
Glue 
Three Ruby usages Powered by Rabbit 2.1.4
Why do we glue? 
Reuse ✓ existing features 
Three Ruby usages Powered by Rabbit 2.1.4
How to glue 
Use external library 
Implement ✓ bindings (mysql2 gem) 
✓ 
Use external command 
✓Spawn command (Vagrant) 
✓ 
Use external service 
✓Implement client 
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
Glue in Droonga 
Rroonga: Groonga bindings 
Groonga: ✓ FTSE C library (and server) 
✓ 
Cool.io: libev bindings 
libev: Event loop C library 
(Based on I/O multiplexing and non-blocking I/O) 
✓ 
✓ 
✓Serf: Clustering tool (in Droonga) 
Three Ruby usages Powered by Rabbit 2.1.4
Rroonga in Droonga 
1: Full-text search DTFSE 
FTSE 
2: Distribute 
sub requests 
3: Merge 
responses 
Worker 
process 
Messaging 
system 
Three Ruby usages Powered by Rabbit 2.1.4
FTSE in Droonga 
✓Must be fast! 
✓CPU bound processing 
Three Ruby usages Powered by Rabbit 2.1.4
For fast Rroonga 
Do heavy processing in C 
Nice to ✓ have Ruby-ish API 
✓ 
Less memory allocation 
✓Cache internal buffer 
✓ 
Multiprocessing 
✓Groonga supports multiprocessing 
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
Search 
Groonga::Database.open(ARGV[0]) 
entries = Groonga["Entries"] 
entries.select do |record| 
record.description =~ "Ruby" 
end 
Three Ruby usages Powered by Rabbit 2.1.4
Search - Pure Ruby (ref) 
Groonga::Database.open(ARGV[0]) 
entries = Groonga["Entries"] 
entries.find_all do |record| 
# This block is evaluated for each record 
/Ruby/ =~ record.description 
end 
Three Ruby usages Powered by Rabbit 2.1.4
Search impl. 
# (2) Evaluate expression in C 
entries.select do |record| 
# (1) Build expression in Ruby 
# This block is evaluated only once 
record.description =~ "Ruby" 
end 
Three Ruby usages Powered by Rabbit 2.1.4
Search impl. - Fig. 
Ruby 
by Groonga project 
C 
entries.select do |record| 
record.description =~ "Ruby" 
end 
Build Search 
request 
Expression 
Result set 
Evaluate expression by Groonga project 
Three Ruby usages Powered by Rabbit 2.1.4
Search - Benchmark 
✓Ruby (It's already showed) 
✓C 
Three Ruby usages Powered by Rabbit 2.1.4
Search - C 
grn_obj *expr; 
grn_obj *variable; 
const gchar *filter = "description @ "Ruby""; 
grn_obj *result; 
GRN_EXPR_CREATE_FOR_QUERY(&ctx, table, expr, variable); 
grn_expr_parse(&ctx, expr, 
filter, strlen(filter), NULL, 
GRN_OP_MATCH, GRN_OP_AND, 
GRN_EXPR_SYNTAX_SCRIPT); 
result = grn_table_select(&ctx, table, expr, NULL, GRN_OP_OR); 
grn_obj_unlink(&ctx, expr); 
grn_obj_unlink(&ctx, result); 
Three Ruby usages Powered by Rabbit 2.1.4
Search - Benchmark 
Ruby impl. is fast enough  
Impl. Elapsed time 
C 0.6ms 
Ruby 0.8ms 
(Full-text search with "Ruby" against 72632 records) 
Three Ruby usages Powered by Rabbit 2.1.4
Embed 
Three Ruby usages 
✓High-level interface 
✓Glue 
Embed 
Target: 
Rubyists who also write C/C++ 
✓ 
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
Embed 
Internal engine Interface 
C/C++ application 
C/C++ library 
Implement 
some features 
in Ruby 
Plugin API 
Conifugration 
by Yukihiro Matsumoto 
by Yukihiro Matsumoto C/C++ application 
C/C++ library 
Three Ruby usages Powered by Rabbit 2.1.4
Examples 
Internal engine Interface 
Implement 
query optimizer 
in Ruby 
vim-ruby by Yukihiro Matsumoto 
by Yukihiro Matsumoto VIM 
Three Ruby usages Powered by Rabbit 2.1.4
Embed in Droonga 
by Yukihiro Matsumoto 
by Yukihiro Matsumoto 
... 
by The Groonga Project 
by The Groonga Project 
by The Groonga Project 
mruby 
by Yukihiro Matsumoto 
Three Ruby usages Powered by Rabbit 2.1.4
CRuby vs. mruby 
CRuby 
✓Full featured! 
✓Signal handler isn't needed  
✓ 
mruby 
✓Multi-interpreters in a process! 
✓You may miss some features  
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
mruby in Groonga 
✓Query optimizer 
Command interface (plan) 
✓Interface and also high-level interface! 
✓ 
Plugin API (plan) 
✓Interface! 
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
Query optimizer 
Query 
Optimize Optimized 
Query 
Optimizer 
query 
Full-text search 
Evaluator 
by Yukihiro Matsumoto 
Result set 
Three Ruby usages Powered by Rabbit 2.1.4
Query optimizer 
Plan how to search 
✓It's a bother  
✓ 
✓Light operation than FTS 
Depends on data 
(Choose effective index, use table scan and so on) 
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
Example 
rank < 200 && rank > 100 
Three Ruby usages Powered by Rabbit 2.1.4
Simple impl. 
rank 1 2 ... 100 ... 200 ... ... 
10000 
rank > 100 
rank < 200 
101 199 
&& 
101 ... 199 
rank < 200 && rank > 100 
Three Ruby usages Powered by Rabbit 2.1.4
Simple impl. 
Slow against 
many out of range data 
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
Optimized impl. 
rank 1 2 ... 100 101 ... 199 
200 ... ... 
10000 
100 < rank < 200 
101 ... 199 
rank < 200 && rank > 100 
Three Ruby usages Powered by Rabbit 2.1.4
Is embedding reasonable? 
Measure 
Three Ruby usages Powered by Rabbit 2.1.4
Measure 
✓mruby overhead 
✓Speed-up by optimization 
Three Ruby usages Powered by Rabbit 2.1.4
Overhead 
Small overhead: Reasonable 
# conds mruby Elapsed 
1 ○ 0.24ms 
1 × 0.16ms 
4 ○ 0.45ms 
4 × 0.19ms 
Three Ruby usages Powered by Rabbit 2.1.4
Speed-up 
Fast for many data:Reasonable 
# records mruby no mruby 
1000 0.29ms 0.31ms 
10000 0.31ms 2.3ms 
100000 0.26ms 21.1ms 
1000000 0.26ms 210.2ms 
Three Ruby usages Powered by Rabbit 2.1.4
Note 
Embedding needs many works 
Write bindings, import mruby your 
build system and ... 
✓ 
✓ 
How to test your mruby part? 
✓And how to debug? 
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
Conclusion
Conclusion 1 
Describe three Ruby usages 
✓High-level interface 
✓Glue 
✓Embed 
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
Conclusion 2 
High-level interface 
✓ Target: Pure Rubyists 
✓ 
Provides lower layer feature to 
higher layer w/ usable interface 
✓Ruby's flexibility is useful 
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
Conclusion 3 
Glue 
Target: 
Rubyists who can write C/C++ 
✓ 
Why: Reuse ✓ existing feature 
✓To be fast, do the process in C 
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
Conclusion 4 
Embed 
Target: 
Rubyists who also write C/C++ 
✓ 
Why: 
Avoid bother programming by Ruby 
✓ 
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
Conclusion 5 
Embed 
Is it reasonable ✓ for your case? 
✓You need many works 
✓ 
Very powerful 
if your case is reasonable 
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
Announcement 
ClearCode Inc. 
✓A silver sponsor 
✓Is recruiting 
✓Will do readable code workshop 
✓ 
The next Groonga conference 
✓It's held at 11/29 
✓ 
Three Ruby usages Powered by Rabbit 2.1.4
1 of 56

Recommended

Python VS GO by
Python VS GOPython VS GO
Python VS GOOfir Nir
86 views45 slides
MongoDB as Message Queue by
MongoDB as Message QueueMongoDB as Message Queue
MongoDB as Message QueueMongoDB
17.2K views13 slides
Developing High Performance Application with Aerospike & Go by
Developing High Performance Application with Aerospike & GoDeveloping High Performance Application with Aerospike & Go
Developing High Performance Application with Aerospike & GoChris Stivers
3.1K views44 slides
Building your First gRPC Service by
Building your First gRPC ServiceBuilding your First gRPC Service
Building your First gRPC ServiceJessie Barnett
737 views38 slides
Rapid Application Design in Financial Services by
Rapid Application Design in Financial ServicesRapid Application Design in Financial Services
Rapid Application Design in Financial ServicesAerospike
898 views40 slides
HTTP2 and gRPC by
HTTP2 and gRPCHTTP2 and gRPC
HTTP2 and gRPCGuo Jing
14.4K views62 slides

More Related Content

What's hot

Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ... by
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...confluent
2.6K views40 slides
Performance Optimization of Rails Applications by
Performance Optimization of Rails ApplicationsPerformance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsSerge Smetana
8.8K views80 slides
Performance optimization 101 - Erlang Factory SF 2014 by
Performance optimization 101 - Erlang Factory SF 2014Performance optimization 101 - Erlang Factory SF 2014
Performance optimization 101 - Erlang Factory SF 2014lpgauth
6.4K views54 slides
Rails Application Optimization Techniques & Tools by
Rails Application Optimization Techniques & ToolsRails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & Toolsguest05c09d
4.9K views50 slides
gRPC - RPC rebirth? by
gRPC - RPC rebirth?gRPC - RPC rebirth?
gRPC - RPC rebirth?Luís Barbosa
870 views62 slides
Fighting Spam With A Perimeter Mail System 20071108 Sasag by
Fighting Spam With A Perimeter Mail System 20071108 SasagFighting Spam With A Perimeter Mail System 20071108 Sasag
Fighting Spam With A Perimeter Mail System 20071108 Sasaggarrett honeycutt
564 views32 slides

What's hot(20)

Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ... by confluent
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
confluent2.6K views
Performance Optimization of Rails Applications by Serge Smetana
Performance Optimization of Rails ApplicationsPerformance Optimization of Rails Applications
Performance Optimization of Rails Applications
Serge Smetana8.8K views
Performance optimization 101 - Erlang Factory SF 2014 by lpgauth
Performance optimization 101 - Erlang Factory SF 2014Performance optimization 101 - Erlang Factory SF 2014
Performance optimization 101 - Erlang Factory SF 2014
lpgauth6.4K views
Rails Application Optimization Techniques & Tools by guest05c09d
Rails Application Optimization Techniques & ToolsRails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & Tools
guest05c09d4.9K views
Fighting Spam With A Perimeter Mail System 20071108 Sasag by garrett honeycutt
Fighting Spam With A Perimeter Mail System 20071108 SasagFighting Spam With A Perimeter Mail System 20071108 Sasag
Fighting Spam With A Perimeter Mail System 20071108 Sasag
garrett honeycutt564 views
[233] level 2 network programming using packet ngin rtos by NAVER D2
[233] level 2 network programming using packet ngin rtos[233] level 2 network programming using packet ngin rtos
[233] level 2 network programming using packet ngin rtos
NAVER D29.4K views
Peter Zaitsev "18 ways to fix MySQL bottlenecks" by Fwdays
Peter Zaitsev "18 ways to fix MySQL bottlenecks"Peter Zaitsev "18 ways to fix MySQL bottlenecks"
Peter Zaitsev "18 ways to fix MySQL bottlenecks"
Fwdays185 views
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t... by AboutYouGmbH
 Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t... Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
AboutYouGmbH13.4K views
Kafka Evaluation - High Throughout Message Queue by Shafaq Abdullah
Kafka Evaluation - High Throughout Message QueueKafka Evaluation - High Throughout Message Queue
Kafka Evaluation - High Throughout Message Queue
Shafaq Abdullah2.1K views
Galaxy CloudMan performance on AWS by Enis Afgan
Galaxy CloudMan performance on AWSGalaxy CloudMan performance on AWS
Galaxy CloudMan performance on AWS
Enis Afgan415 views
Scaling PostgreSQL with Skytools by Gavin Roy
Scaling PostgreSQL with SkytoolsScaling PostgreSQL with Skytools
Scaling PostgreSQL with Skytools
Gavin Roy5.1K views
[231] the simplicity of cluster apps with circuit by NAVER D2
[231] the simplicity of cluster apps with circuit[231] the simplicity of cluster apps with circuit
[231] the simplicity of cluster apps with circuit
NAVER D26.4K views
Microservices summit talk 1/31 by Varun Talwar
Microservices summit talk   1/31Microservices summit talk   1/31
Microservices summit talk 1/31
Varun Talwar760 views
Perl Dist::Surveyor 2011 by Tim Bunce
Perl Dist::Surveyor 2011Perl Dist::Surveyor 2011
Perl Dist::Surveyor 2011
Tim Bunce2.7K views
Golang Performance : microbenchmarks, profilers, and a war story by Aerospike
Golang Performance : microbenchmarks, profilers, and a war storyGolang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war story
Aerospike10.3K views

Similar to Three Ruby usages

Network Traffic Search using Apache HBase by
Network Traffic Search using Apache HBaseNetwork Traffic Search using Apache HBase
Network Traffic Search using Apache HBaseEvans Ye
3.7K views36 slides
"Introducing Distributed Tracing in a Large Software System", Kostiantyn Sha... by
"Introducing Distributed Tracing in a Large Software System",  Kostiantyn Sha..."Introducing Distributed Tracing in a Large Software System",  Kostiantyn Sha...
"Introducing Distributed Tracing in a Large Software System", Kostiantyn Sha...Fwdays
82 views50 slides
[2C1] 아파치 피그를 위한 테즈 연산 엔진 개발하기 최종 by
[2C1] 아파치 피그를 위한 테즈 연산 엔진 개발하기 최종[2C1] 아파치 피그를 위한 테즈 연산 엔진 개발하기 최종
[2C1] 아파치 피그를 위한 테즈 연산 엔진 개발하기 최종NAVER D2
4K views36 slides
NocInformatyka2022.pdf by
NocInformatyka2022.pdfNocInformatyka2022.pdf
NocInformatyka2022.pdfAdam Przybyła
49 views27 slides
Web Scraping Basics by
Web Scraping BasicsWeb Scraping Basics
Web Scraping BasicsKyle Banerjee
3.4K views63 slides
Google File System by
Google File SystemGoogle File System
Google File SystemJunyoung Jung
5.8K views48 slides

Similar to Three Ruby usages(20)

Network Traffic Search using Apache HBase by Evans Ye
Network Traffic Search using Apache HBaseNetwork Traffic Search using Apache HBase
Network Traffic Search using Apache HBase
Evans Ye3.7K views
"Introducing Distributed Tracing in a Large Software System", Kostiantyn Sha... by Fwdays
"Introducing Distributed Tracing in a Large Software System",  Kostiantyn Sha..."Introducing Distributed Tracing in a Large Software System",  Kostiantyn Sha...
"Introducing Distributed Tracing in a Large Software System", Kostiantyn Sha...
Fwdays82 views
[2C1] 아파치 피그를 위한 테즈 연산 엔진 개발하기 최종 by NAVER D2
[2C1] 아파치 피그를 위한 테즈 연산 엔진 개발하기 최종[2C1] 아파치 피그를 위한 테즈 연산 엔진 개발하기 최종
[2C1] 아파치 피그를 위한 테즈 연산 엔진 개발하기 최종
NAVER D24K views
PostgreSQL: present and near future by NaN-tic
PostgreSQL: present and near futurePostgreSQL: present and near future
PostgreSQL: present and near future
NaN-tic444 views
202107 - Orion introduction - COSCUP by Ronald Hsu
202107 - Orion introduction - COSCUP202107 - Orion introduction - COSCUP
202107 - Orion introduction - COSCUP
Ronald Hsu119 views
Extending Solr: Building a Cloud-like Knowledge Discovery Platform by Lucidworks (Archived)
Extending Solr: Building a Cloud-like Knowledge Discovery PlatformExtending Solr: Building a Cloud-like Knowledge Discovery Platform
Extending Solr: Building a Cloud-like Knowledge Discovery Platform
Extending Solr: Behind CareerBuilder’s Cloud-like Knowledge Discovery Platfor... by lucenerevolution
Extending Solr: Behind CareerBuilder’s Cloud-like Knowledge Discovery Platfor...Extending Solr: Behind CareerBuilder’s Cloud-like Knowledge Discovery Platfor...
Extending Solr: Behind CareerBuilder’s Cloud-like Knowledge Discovery Platfor...
lucenerevolution1.4K views
Extending Solr: Building a Cloud-like Knowledge Discovery Platform by Trey Grainger
Extending Solr: Building a Cloud-like Knowledge Discovery PlatformExtending Solr: Building a Cloud-like Knowledge Discovery Platform
Extending Solr: Building a Cloud-like Knowledge Discovery Platform
Trey Grainger1.7K views
Google File Systems by Azeem Mumtaz
Google File SystemsGoogle File Systems
Google File Systems
Azeem Mumtaz4.4K views
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U... by Paolo Negri
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Paolo Negri6.6K views
Taking Splunk to the Next Level - Architecture Breakout Session by Splunk
Taking Splunk to the Next Level - Architecture Breakout SessionTaking Splunk to the Next Level - Architecture Breakout Session
Taking Splunk to the Next Level - Architecture Breakout Session
Splunk5.1K views
Concurrent Programming with Ruby and Tuple Spaces by luccastera
Concurrent Programming with Ruby and Tuple SpacesConcurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple Spaces
luccastera5.4K views
Parallelizing CI using Docker Swarm-Mode by Akihiro Suda
Parallelizing CI using Docker Swarm-ModeParallelizing CI using Docker Swarm-Mode
Parallelizing CI using Docker Swarm-Mode
Akihiro Suda1.1K views
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ... by javier ramirez
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
javier ramirez43 views

More from Kouhei Sutou

Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021 by
Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021
Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021Kouhei Sutou
500 views42 slides
RubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache Arrow by
RubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache ArrowRubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache Arrow
RubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache ArrowKouhei Sutou
246 views67 slides
Rubyと仕事と自由なソフトウェア by
Rubyと仕事と自由なソフトウェアRubyと仕事と自由なソフトウェア
Rubyと仕事と自由なソフトウェアKouhei Sutou
686 views40 slides
Apache Arrowフォーマットはなぜ速いのか by
Apache Arrowフォーマットはなぜ速いのかApache Arrowフォーマットはなぜ速いのか
Apache Arrowフォーマットはなぜ速いのかKouhei Sutou
506 views45 slides
Apache Arrow 1.0 - A cross-language development platform for in-memory data by
Apache Arrow 1.0 - A cross-language development platform for in-memory dataApache Arrow 1.0 - A cross-language development platform for in-memory data
Apache Arrow 1.0 - A cross-language development platform for in-memory dataKouhei Sutou
539 views48 slides
Apache Arrow 2019 by
Apache Arrow 2019Apache Arrow 2019
Apache Arrow 2019Kouhei Sutou
1.3K views55 slides

More from Kouhei Sutou(20)

Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021 by Kouhei Sutou
Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021
Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021
Kouhei Sutou500 views
RubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache Arrow by Kouhei Sutou
RubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache ArrowRubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache Arrow
RubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache Arrow
Kouhei Sutou246 views
Rubyと仕事と自由なソフトウェア by Kouhei Sutou
Rubyと仕事と自由なソフトウェアRubyと仕事と自由なソフトウェア
Rubyと仕事と自由なソフトウェア
Kouhei Sutou686 views
Apache Arrowフォーマットはなぜ速いのか by Kouhei Sutou
Apache Arrowフォーマットはなぜ速いのかApache Arrowフォーマットはなぜ速いのか
Apache Arrowフォーマットはなぜ速いのか
Kouhei Sutou506 views
Apache Arrow 1.0 - A cross-language development platform for in-memory data by Kouhei Sutou
Apache Arrow 1.0 - A cross-language development platform for in-memory dataApache Arrow 1.0 - A cross-language development platform for in-memory data
Apache Arrow 1.0 - A cross-language development platform for in-memory data
Kouhei Sutou539 views
Apache Arrow 2019 by Kouhei Sutou
Apache Arrow 2019Apache Arrow 2019
Apache Arrow 2019
Kouhei Sutou1.3K views
Redmine検索の未来像 by Kouhei Sutou
Redmine検索の未来像Redmine検索の未来像
Redmine検索の未来像
Kouhei Sutou1.3K views
Apache Arrow - A cross-language development platform for in-memory data by Kouhei Sutou
Apache Arrow - A cross-language development platform for in-memory dataApache Arrow - A cross-language development platform for in-memory data
Apache Arrow - A cross-language development platform for in-memory data
Kouhei Sutou1.2K views
Better CSV processing with Ruby 2.6 by Kouhei Sutou
Better CSV processing with Ruby 2.6Better CSV processing with Ruby 2.6
Better CSV processing with Ruby 2.6
Kouhei Sutou4.5K views
Apache Arrow - データ処理ツールの次世代プラットフォーム by Kouhei Sutou
Apache Arrow - データ処理ツールの次世代プラットフォームApache Arrow - データ処理ツールの次世代プラットフォーム
Apache Arrow - データ処理ツールの次世代プラットフォーム
Kouhei Sutou7.6K views
MySQL・PostgreSQLだけで作る高速あいまい全文検索システム by Kouhei Sutou
MySQL・PostgreSQLだけで作る高速あいまい全文検索システムMySQL・PostgreSQLだけで作る高速あいまい全文検索システム
MySQL・PostgreSQLだけで作る高速あいまい全文検索システム
Kouhei Sutou9.1K views
MySQL 8.0でMroonga by Kouhei Sutou
MySQL 8.0でMroongaMySQL 8.0でMroonga
MySQL 8.0でMroonga
Kouhei Sutou1.1K views
Mroongaの高速全文検索機能でWordPress内のコンテンツを有効活用! by Kouhei Sutou
Mroongaの高速全文検索機能でWordPress内のコンテンツを有効活用!Mroongaの高速全文検索機能でWordPress内のコンテンツを有効活用!
Mroongaの高速全文検索機能でWordPress内のコンテンツを有効活用!
Kouhei Sutou2.5K views
MariaDBとMroongaで作る全言語対応超高速全文検索システム by Kouhei Sutou
MariaDBとMroongaで作る全言語対応超高速全文検索システムMariaDBとMroongaで作る全言語対応超高速全文検索システム
MariaDBとMroongaで作る全言語対応超高速全文検索システム
Kouhei Sutou7.3K views
PGroonga 2 – Make PostgreSQL rich full text search system backend! by Kouhei Sutou
PGroonga 2 – Make PostgreSQL rich full text search system backend!PGroonga 2 – Make PostgreSQL rich full text search system backend!
PGroonga 2 – Make PostgreSQL rich full text search system backend!
Kouhei Sutou597 views
PGroonga 2 - PostgreSQLでの全文検索の決定版 by Kouhei Sutou
PGroonga 2 - PostgreSQLでの全文検索の決定版PGroonga 2 - PostgreSQLでの全文検索の決定版
PGroonga 2 - PostgreSQLでの全文検索の決定版
Kouhei Sutou5.2K views

Recently uploaded

Empathic Computing: Delivering the Potential of the Metaverse by
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the MetaverseMark Billinghurst
470 views80 slides
ChatGPT and AI for Web Developers by
ChatGPT and AI for Web DevelopersChatGPT and AI for Web Developers
ChatGPT and AI for Web DevelopersMaximiliano Firtman
181 views82 slides
handbook for web 3 adoption.pdf by
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdfLiveplex
19 views16 slides
Throughput by
ThroughputThroughput
ThroughputMoisés Armani Ramírez
36 views11 slides
The Importance of Cybersecurity for Digital Transformation by
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital TransformationNUS-ISS
27 views26 slides
RADIUS-Omnichannel Interaction System by
RADIUS-Omnichannel Interaction SystemRADIUS-Omnichannel Interaction System
RADIUS-Omnichannel Interaction SystemRADIUS
15 views21 slides

Recently uploaded(20)

Empathic Computing: Delivering the Potential of the Metaverse by Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst470 views
handbook for web 3 adoption.pdf by Liveplex
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdf
Liveplex19 views
The Importance of Cybersecurity for Digital Transformation by NUS-ISS
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital Transformation
NUS-ISS27 views
RADIUS-Omnichannel Interaction System by RADIUS
RADIUS-Omnichannel Interaction SystemRADIUS-Omnichannel Interaction System
RADIUS-Omnichannel Interaction System
RADIUS15 views
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica... by NUS-ISS
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
NUS-ISS16 views
Understanding GenAI/LLM and What is Google Offering - Felix Goh by NUS-ISS
Understanding GenAI/LLM and What is Google Offering - Felix GohUnderstanding GenAI/LLM and What is Google Offering - Felix Goh
Understanding GenAI/LLM and What is Google Offering - Felix Goh
NUS-ISS41 views
The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada121 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab15 views
Spesifikasi Lengkap ASUS Vivobook Go 14 by Dot Semarang
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14
Dot Semarang35 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman27 views
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum... by NUS-ISS
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
NUS-ISS34 views
Future of Learning - Yap Aye Wee.pdf by NUS-ISS
Future of Learning - Yap Aye Wee.pdfFuture of Learning - Yap Aye Wee.pdf
Future of Learning - Yap Aye Wee.pdf
NUS-ISS41 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 views
DALI Basics Course 2023 by Ivory Egg
DALI Basics Course  2023DALI Basics Course  2023
DALI Basics Course 2023
Ivory Egg14 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi120 views

Three Ruby usages

  • 1. Three Ruby usages Kouhei Sutou ClearCode Inc. RubyKaigi 2014 2014/09/20 Three Ruby usages Powered by Rabbit 2.1.4
  • 2. Silver sponsor Three Ruby usages Powered by Rabbit 2.1.4
  • 3. Goal You know three Ruby usages ✓High-level interface ✓Glue ✓Embed ✓ ✓You can remember them later Three Ruby usages Powered by Rabbit 2.1.4
  • 4. Targets High-level interface ✓Pure Rubyists ✓ Glue ✓Rubyists who can write C/C++ ✓ Embed ✓Rubyists who also write C/C++ ✓ Three Ruby usages Powered by Rabbit 2.1.4
  • 5. Case study Implement distributed full-text search engine in Ruby Abbreviation: DFTSE = Distributed Full-Text Search Engine Three Ruby usages Powered by Rabbit 2.1.4
  • 6. DFTSE? Distrubuted Full- Text Search Engine Full- Text Search Engine 1: Full-text search 2: Distribute sub requests 3: Merge responses Three Ruby usages Powered by Rabbit 2.1.4
  • 7. Why do we use DFTSE? I'm developing Droonga (A DFTSE implementation in Ruby)  Three Ruby usages Powered by Rabbit 2.1.4
  • 8. High-level interface Three Ruby usages High-level interface Target: ✓ Pure Rubyists ✓ ✓Glue ✓Embed Three Ruby usages Powered by Rabbit 2.1.4
  • 9. High-level interface Provides lower layer feature to higher layer ✓ With simpler/✓ convenience API Three Ruby usages Powered by Rabbit 2.1.4
  • 10. High-level interface Higher layer users High-level interface Feature by Yukihiro Matsumoto Application/Library Three Ruby usages Powered by Rabbit 2.1.4
  • 11. Example Vagrant Active Record Developers Vagrantfile Build development environment Vagrant b y Y u k i h i r o M a t s u m o t o Developers Object based API b y Y u k i h i r o M a t s u m o t o Access data in RDBMS Active Record Three Ruby usages Powered by Rabbit 2.1.4
  • 12. Droonga: High-level IF DFTSE components Full-✓ text search engine ✓Messaging system ✓Cluster management ✓Process management Three Ruby usages Powered by Rabbit 2.1.4
  • 13. Messaging system 1: Full-text search DTFSE FTSE 2: Distribute sub requests 3: Merge responses Worker process Messaging system Three Ruby usages Powered by Rabbit 2.1.4
  • 14. Messaging system Provides distributed search feature ✓Plan how to search ✓Distribute requests ✓Merge responses ✓ ✓Users don't know details Three Ruby usages Powered by Rabbit 2.1.4
  • 15. Characteristic Plan how to search May speed up/✓ down over 100 times ✓ Distribute requests ✓Network bound operation ✓ Merge responses ✓CPU and network bound operation ✓ Three Ruby usages Powered by Rabbit 2.1.4
  • 16. Point Algorithm is important Need to find new/existing better algorithm ✓ "Rapid prototype and measure" feedback loop is helpful ✓ Ruby is ✓ good at rapid dev. ✓ Three Ruby usages Powered by Rabbit 2.1.4
  • 17. Glue Three Ruby usages ✓High-level interface Glue Target: Rubyists who can write C/C++ ✓ ✓ ✓Embed Three Ruby usages Powered by Rabbit 2.1.4
  • 18. Glue Export a feature Feature Combine features Glue Ruby Other Language Three Ruby usages Powered by Rabbit 2.1.4
  • 19. Example mysql2 gem Vagrant Access to MySQL VM Provision libmysqlclient.so (VirtualBox) (Chef) Feature Active Record Glue Three Ruby usages Powered by Rabbit 2.1.4
  • 20. Why do we glue? Reuse ✓ existing features Three Ruby usages Powered by Rabbit 2.1.4
  • 21. How to glue Use external library Implement ✓ bindings (mysql2 gem) ✓ Use external command ✓Spawn command (Vagrant) ✓ Use external service ✓Implement client ✓ Three Ruby usages Powered by Rabbit 2.1.4
  • 22. Glue in Droonga Rroonga: Groonga bindings Groonga: ✓ FTSE C library (and server) ✓ Cool.io: libev bindings libev: Event loop C library (Based on I/O multiplexing and non-blocking I/O) ✓ ✓ ✓Serf: Clustering tool (in Droonga) Three Ruby usages Powered by Rabbit 2.1.4
  • 23. Rroonga in Droonga 1: Full-text search DTFSE FTSE 2: Distribute sub requests 3: Merge responses Worker process Messaging system Three Ruby usages Powered by Rabbit 2.1.4
  • 24. FTSE in Droonga ✓Must be fast! ✓CPU bound processing Three Ruby usages Powered by Rabbit 2.1.4
  • 25. For fast Rroonga Do heavy processing in C Nice to ✓ have Ruby-ish API ✓ Less memory allocation ✓Cache internal buffer ✓ Multiprocessing ✓Groonga supports multiprocessing ✓ Three Ruby usages Powered by Rabbit 2.1.4
  • 26. Search Groonga::Database.open(ARGV[0]) entries = Groonga["Entries"] entries.select do |record| record.description =~ "Ruby" end Three Ruby usages Powered by Rabbit 2.1.4
  • 27. Search - Pure Ruby (ref) Groonga::Database.open(ARGV[0]) entries = Groonga["Entries"] entries.find_all do |record| # This block is evaluated for each record /Ruby/ =~ record.description end Three Ruby usages Powered by Rabbit 2.1.4
  • 28. Search impl. # (2) Evaluate expression in C entries.select do |record| # (1) Build expression in Ruby # This block is evaluated only once record.description =~ "Ruby" end Three Ruby usages Powered by Rabbit 2.1.4
  • 29. Search impl. - Fig. Ruby by Groonga project C entries.select do |record| record.description =~ "Ruby" end Build Search request Expression Result set Evaluate expression by Groonga project Three Ruby usages Powered by Rabbit 2.1.4
  • 30. Search - Benchmark ✓Ruby (It's already showed) ✓C Three Ruby usages Powered by Rabbit 2.1.4
  • 31. Search - C grn_obj *expr; grn_obj *variable; const gchar *filter = "description @ "Ruby""; grn_obj *result; GRN_EXPR_CREATE_FOR_QUERY(&ctx, table, expr, variable); grn_expr_parse(&ctx, expr, filter, strlen(filter), NULL, GRN_OP_MATCH, GRN_OP_AND, GRN_EXPR_SYNTAX_SCRIPT); result = grn_table_select(&ctx, table, expr, NULL, GRN_OP_OR); grn_obj_unlink(&ctx, expr); grn_obj_unlink(&ctx, result); Three Ruby usages Powered by Rabbit 2.1.4
  • 32. Search - Benchmark Ruby impl. is fast enough  Impl. Elapsed time C 0.6ms Ruby 0.8ms (Full-text search with "Ruby" against 72632 records) Three Ruby usages Powered by Rabbit 2.1.4
  • 33. Embed Three Ruby usages ✓High-level interface ✓Glue Embed Target: Rubyists who also write C/C++ ✓ ✓ Three Ruby usages Powered by Rabbit 2.1.4
  • 34. Embed Internal engine Interface C/C++ application C/C++ library Implement some features in Ruby Plugin API Conifugration by Yukihiro Matsumoto by Yukihiro Matsumoto C/C++ application C/C++ library Three Ruby usages Powered by Rabbit 2.1.4
  • 35. Examples Internal engine Interface Implement query optimizer in Ruby vim-ruby by Yukihiro Matsumoto by Yukihiro Matsumoto VIM Three Ruby usages Powered by Rabbit 2.1.4
  • 36. Embed in Droonga by Yukihiro Matsumoto by Yukihiro Matsumoto ... by The Groonga Project by The Groonga Project by The Groonga Project mruby by Yukihiro Matsumoto Three Ruby usages Powered by Rabbit 2.1.4
  • 37. CRuby vs. mruby CRuby ✓Full featured! ✓Signal handler isn't needed  ✓ mruby ✓Multi-interpreters in a process! ✓You may miss some features  ✓ Three Ruby usages Powered by Rabbit 2.1.4
  • 38. mruby in Groonga ✓Query optimizer Command interface (plan) ✓Interface and also high-level interface! ✓ Plugin API (plan) ✓Interface! ✓ Three Ruby usages Powered by Rabbit 2.1.4
  • 39. Query optimizer Query Optimize Optimized Query Optimizer query Full-text search Evaluator by Yukihiro Matsumoto Result set Three Ruby usages Powered by Rabbit 2.1.4
  • 40. Query optimizer Plan how to search ✓It's a bother  ✓ ✓Light operation than FTS Depends on data (Choose effective index, use table scan and so on) ✓ Three Ruby usages Powered by Rabbit 2.1.4
  • 41. Example rank < 200 && rank > 100 Three Ruby usages Powered by Rabbit 2.1.4
  • 42. Simple impl. rank 1 2 ... 100 ... 200 ... ... 10000 rank > 100 rank < 200 101 199 && 101 ... 199 rank < 200 && rank > 100 Three Ruby usages Powered by Rabbit 2.1.4
  • 43. Simple impl. Slow against many out of range data ✓ Three Ruby usages Powered by Rabbit 2.1.4
  • 44. Optimized impl. rank 1 2 ... 100 101 ... 199 200 ... ... 10000 100 < rank < 200 101 ... 199 rank < 200 && rank > 100 Three Ruby usages Powered by Rabbit 2.1.4
  • 45. Is embedding reasonable? Measure Three Ruby usages Powered by Rabbit 2.1.4
  • 46. Measure ✓mruby overhead ✓Speed-up by optimization Three Ruby usages Powered by Rabbit 2.1.4
  • 47. Overhead Small overhead: Reasonable # conds mruby Elapsed 1 ○ 0.24ms 1 × 0.16ms 4 ○ 0.45ms 4 × 0.19ms Three Ruby usages Powered by Rabbit 2.1.4
  • 48. Speed-up Fast for many data:Reasonable # records mruby no mruby 1000 0.29ms 0.31ms 10000 0.31ms 2.3ms 100000 0.26ms 21.1ms 1000000 0.26ms 210.2ms Three Ruby usages Powered by Rabbit 2.1.4
  • 49. Note Embedding needs many works Write bindings, import mruby your build system and ... ✓ ✓ How to test your mruby part? ✓And how to debug? ✓ Three Ruby usages Powered by Rabbit 2.1.4
  • 51. Conclusion 1 Describe three Ruby usages ✓High-level interface ✓Glue ✓Embed ✓ Three Ruby usages Powered by Rabbit 2.1.4
  • 52. Conclusion 2 High-level interface ✓ Target: Pure Rubyists ✓ Provides lower layer feature to higher layer w/ usable interface ✓Ruby's flexibility is useful ✓ Three Ruby usages Powered by Rabbit 2.1.4
  • 53. Conclusion 3 Glue Target: Rubyists who can write C/C++ ✓ Why: Reuse ✓ existing feature ✓To be fast, do the process in C ✓ Three Ruby usages Powered by Rabbit 2.1.4
  • 54. Conclusion 4 Embed Target: Rubyists who also write C/C++ ✓ Why: Avoid bother programming by Ruby ✓ ✓ Three Ruby usages Powered by Rabbit 2.1.4
  • 55. Conclusion 5 Embed Is it reasonable ✓ for your case? ✓You need many works ✓ Very powerful if your case is reasonable ✓ Three Ruby usages Powered by Rabbit 2.1.4
  • 56. Announcement ClearCode Inc. ✓A silver sponsor ✓Is recruiting ✓Will do readable code workshop ✓ The next Groonga conference ✓It's held at 11/29 ✓ Three Ruby usages Powered by Rabbit 2.1.4