SlideShare a Scribd company logo
Blosc
Sending data from memory to CPU (and back)	

faster than memcpy()
Francesc Alted

Software Architect

PyData London 2014	

February 22, 2014
About Me
• I am the creator of tools like PyTables,
Blosc, BLZ and maintainer of Numexpr.	

• I learnt the hard way that ‘premature
optimization is the root of all evil’.	

• Now I only humbly try to optimize if I
really need to and I just hope that Blosc is
not an example of ‘premature optimization’.
About Continuum Analytics
• Develop new ways on how data is stored,
computed, and visualized.	

• Provide open technologies for data
integration on a massive scale.	

• Provide software tools, training, and
integration/consulting services to
corporate, government, and educational
clients worldwide.
Overview
• Compressing faster than memcpy(). Really?	

• How that can be?

(The ‘Starving CPU’ problem)	

• How Blosc works.	

• Being faster than memcpy() means that my
programs would actually run faster?
Compressing Faster
than memcpy()
Interactive Session Starts
• If you 	

want to experiment with Blosc in
your own machine: 

http://www.blosc.org/materials/PyData-
London-2014.tar.gz	

• blosc (blz too for later on) is required (both
are included in conda repository).
Open Questions
We have seen that, sometimes, Blosc can actually
be faster than memcpy(). Now:	

1. If compression takes way more CPU than
memcpy(), why Blosc can beat it?	

2. Does this mean that Blosc can actually
accelerate computations in real
scenarios?
The Starving CPU
Problem
“Across the industry, today’s chips are largely
able to execute code faster than we can feed
them with instructions and data.”	

!
– Richard Sites, after his article

“It’sThe Memory, Stupid!”, 

Microprocessor Report, 10(10),1996
Memory Access Time
vs CPU Cycle Time
Book in
2009
The Status of CPU
Starvation in 2014
• Memory latency (~10 ns) is much slower
(between 100x and 250x) than processors.	

• Memory bandwidth (~15 GB/s) is
improving at a better rate than memory
latency, but it is also slower than
processors (between 30x and 100x).
Blosc Goals and
Implementation
Blosc: (de)compressing
faster than memcpy()
Transmission + decompression faster than direct transfer?
Taking Advantage of
Memory-CPU Gap
• Blosc is meant to discover redundancy in
data as fast as possible.	

• It comes with a series of fast compressors:
BloscLZ, LZ4, Snappy, LZ4HC and Zlib	

• Blosc is meant for speed, not for high
compression ratios.
Blosc Is All About
Efficiency
• Uses data blocks that fit in L1 or L2 caches
(better speed, less compression ratios).	

• Uses multithreading by default.	

• The shuffle filter uses SSE2 instructions in
modern Intel and AMD processors.
Blocking: Divide and
Conquer
Suffling: Improving the
Compression Ratio
The shuffling algorithm does not actually
compress the data; it rather changes the byte
order in the data stream:
Shuffling Caveat
• Shuffling usually produces better
compression ratios with numerical data,
except when it does not.	

• If you mind about the compression ratio, it
is worth to deactivate it and check (it is
active by default).	

• Will see an example on real data later on.
Blosc Performance:
Laptop back in 2005
Blosc Performance:
Desktop Computer in 2012
First Answer for Open
Questions
• Blosc data blocking optimizes the cache
behavior during memory access.	

• Additionally, it uses multithreading and
SIMD instructions.	

• Add these to the Starved CPU problem and
you have a good hint now on why Blosc can
beat memcpy().
How Compression
Works With Real Data?
The Need for
Compression
• Compression allows to store more data
using the same storage capacity.	

• Sure, it uses more CPU time to compress/
decompress data.	

• But, that actually means using more wall
clock time?
The Need for a
Compressed Container
• A compressed container is meant to store
data in compressed state and transparently
deliver it uncompressed.	

• That means that the user only perceives
that her dataset takes less memory.	

• Only less space? What about data access
speed?
Source: Howison, M. High-throughput compression of FASTQ data with SeqDB.
IEEE Transactions on Computational Biology and Bioinformatics.
Example of How Blosc Accelerates Genomics I/O:	

SeqDB (backed by Blosc)
Bloscpack (I)
• Command line interface and serialization
format for Blosc:	

!
$ blpk c data.dat # compress
$ blpk d data.dat.blp # decompress
Bloscpack (II)
• Very convenient for easily serializing your
in-memory NumPy datasets:	

>>> a = np.linspace(0, 1, 3e8)
>>> print a.size, a.dtype
300000000 float64
>>> bp.pack_ndarray_file(a, 'a.blp')
>>> b = bp.unpack_ndarray_file('a.blp')
>>> (a == b).all()
True
Yet Another Example: 	

BLZ	

• BLZ is a both a format and library that has
been designed as an efficient data container
for Big Data.	

• Blosc and Bloscpack are at the heart of it in
order to achieve high-speed compression/
decompression.	

• BLZ is one of the backends supported by
our nascent Blaze library.
Appending Data in
Large NumPy Objects
Copy!
New memory	

allocation
array to be enlarged final array object
new data to append
• Normally a realloc() syscall will not succeed	

• Both memory areas have to exist simultaneously
Contiguous vs Chunked
NumPy container
Contiguous memory
BLZ container
chunk 1
chunk 2
Discontiguous memory
chunk N
...
Appending data in BLZ
compress
new chunk
array to be enlarged final array object
new data to append
Only a small amount of data has to be compressed
X
chunk 1
chunk 2
chunk 1
chunk 2
The btable object in BLZ
New row to append
• Columns are contiguous in memory	

• Chunks follow column order	

• Very efficient for querying (specially with a

large number of columns)
Chunks
Second Interactive
Session: BLZ and Blosc
on a Real Dataset
Second Hint for Open
Questions	

Blosc usage in BLZ means not only less storage
usage (~15x-40x reduction for the real life data
shown), but almost the same access time to
the data (~2x-10x slowdown).	

(Still need to address implementation details for
getting better performance)
Summary
• Blosc, being able to transfer data faster than
memcpy(), has enormous implications on
data management.	

• It is well suited not only for saving memory,
but for allowing close performance to
typical uncompressed data containers.	

• It works well not only for synthetic data,
but also for real-life datasets.
References
• Blosc: http://www.blosc.org	

• Bloscpack: https://github.com/Blosc/bloscpack	

• BLZ: http://blz.pydata.org
“Across the industry, today’s chips are largely able to execute code
faster than we can feed them with instructions and data. There are no
longer performance bottlenecks in the floating-point multiplier or in
having only a single integer unit. The real design action is in memory
subsystems— caches, buses, bandwidth, and latency.”	

!
“Over the coming decade, memory subsystem design will be the only
important design issue for microprocessors.”	

!
– Richard Sites, after his article “It’sThe Memory, Stupid!”,
Microprocessor Report, 10(10),1996
“Over this decade (2010-2020), memory subsystem optimization
will be (almost) the only important design issue for improving
performance.”	

– Me :)
Thank you!

More Related Content

PDF
It's the memory, stupid! CodeJam 2014
PDF
The Google file system
PDF
LizardFS-WhitePaper-Eng-v4.0 (1)
PDF
computer-memory
PDF
Understanding DLmalloc
DOCX
Data replication
PDF
The Google File System (GFS)
DOCX
data deduplication
It's the memory, stupid! CodeJam 2014
The Google file system
LizardFS-WhitePaper-Eng-v4.0 (1)
computer-memory
Understanding DLmalloc
Data replication
The Google File System (GFS)
data deduplication

What's hot (18)

PDF
Technology Updates of PG-Strom at Aug-2014 (PGUnconf@Tokyo)
PDF
HKG15-The Machine: A new kind of computer- Keynote by Dejan Milojicic
PPTX
Modern software design in Big data era
PDF
I-Sieve: An inline High Performance Deduplication System Used in cloud storage
PPTX
Mongodb backup
PDF
Joblib Toward efficient computing : from laptop to cloud
PDF
Joblib PyDataParis2016
ODP
My talk at Topconf.com conference, Tallinn, 1st of November 2012
PDF
Apache tajo configuration
PDF
Database Research on Modern Computing Architecture
PPTX
GFS & HDFS Introduction
PDF
Slides for In-Datacenter Performance Analysis of a Tensor Processing Unit
PPTX
Webinar: Understanding Storage for Performance and Data Safety
PPTX
Availability and scalability in mongo
PPTX
ScimoreDB @ CommunityDays 2011
PDF
The Google Chubby lock service for loosely-coupled distributed systems
PPTX
Cassandra in Operation
Technology Updates of PG-Strom at Aug-2014 (PGUnconf@Tokyo)
HKG15-The Machine: A new kind of computer- Keynote by Dejan Milojicic
Modern software design in Big data era
I-Sieve: An inline High Performance Deduplication System Used in cloud storage
Mongodb backup
Joblib Toward efficient computing : from laptop to cloud
Joblib PyDataParis2016
My talk at Topconf.com conference, Tallinn, 1st of November 2012
Apache tajo configuration
Database Research on Modern Computing Architecture
GFS & HDFS Introduction
Slides for In-Datacenter Performance Analysis of a Tensor Processing Unit
Webinar: Understanding Storage for Performance and Data Safety
Availability and scalability in mongo
ScimoreDB @ CommunityDays 2011
The Google Chubby lock service for loosely-coupled distributed systems
Cassandra in Operation
Ad

Similar to Blosc: Sending Data from Memory to CPU (and back) Faster than Memcpy by Francesc Alted (20)

PDF
PyData Paris 2015 - Closing keynote Francesc Alted
PPTX
Elements of cache design
PDF
Ceph Day Amsterdam 2015: Measuring and predicting performance of Ceph clusters
PPTX
Limitations of memory system performance
PPTX
Data warehouse 26 exploiting parallel technologies
PPTX
Cache Memory.pptx
KEY
Deployment Strategies
PPTX
Unit II - Data Science (3) VI semester SRMIST
PPTX
COA notes
PDF
High Performance With Java
PPTX
Scaling up Machine Learning Algorithms for Classification
PPTX
Cache coherence ppt
PDF
Real time database compression optimization using iterative length compressio...
PDF
REAL TIME DATABASE COMPRESSION OPTIMIZATION USING ITERATIVE LENGTH COMPRESSIO...
PPTX
Training Webinar: Enterprise application performance with distributed caching
PPT
5 Pitfalls to Avoid with MongoDB
KEY
Deployment Strategy
PDF
The Fundamental Characteristics of Storage concepts for DBAs
PPTX
Percona FT / TokuDB
PPTX
Blue and Green Narrative Writing Story Starters Education Presentation _20241...
PyData Paris 2015 - Closing keynote Francesc Alted
Elements of cache design
Ceph Day Amsterdam 2015: Measuring and predicting performance of Ceph clusters
Limitations of memory system performance
Data warehouse 26 exploiting parallel technologies
Cache Memory.pptx
Deployment Strategies
Unit II - Data Science (3) VI semester SRMIST
COA notes
High Performance With Java
Scaling up Machine Learning Algorithms for Classification
Cache coherence ppt
Real time database compression optimization using iterative length compressio...
REAL TIME DATABASE COMPRESSION OPTIMIZATION USING ITERATIVE LENGTH COMPRESSIO...
Training Webinar: Enterprise application performance with distributed caching
5 Pitfalls to Avoid with MongoDB
Deployment Strategy
The Fundamental Characteristics of Storage concepts for DBAs
Percona FT / TokuDB
Blue and Green Narrative Writing Story Starters Education Presentation _20241...
Ad

More from PyData (20)

PDF
Michal Mucha: Build and Deploy an End-to-end Streaming NLP Insight System | P...
PDF
Unit testing data with marbles - Jane Stewart Adams, Leif Walsh
PDF
The TileDB Array Data Storage Manager - Stavros Papadopoulos, Jake Bolewski
PDF
Using Embeddings to Understand the Variance and Evolution of Data Science... ...
PDF
Deploying Data Science for Distribution of The New York Times - Anne Bauer
PPTX
Graph Analytics - From the Whiteboard to Your Toolbox - Sam Lerma
PPTX
Do Your Homework! Writing tests for Data Science and Stochastic Code - David ...
PDF
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
PDF
Mining dockless bikeshare and dockless scootershare trip data - Stefanie Brod...
PDF
Avoiding Bad Database Surprises: Simulation and Scalability - Steven Lott
PDF
Words in Space - Rebecca Bilbro
PDF
End-to-End Machine learning pipelines for Python driven organizations - Nick ...
PPTX
Pydata beautiful soup - Monica Puerto
PDF
1D Convolutional Neural Networks for Time Series Modeling - Nathan Janos, Jef...
PPTX
Extending Pandas with Custom Types - Will Ayd
PDF
Measuring Model Fairness - Stephen Hoover
PDF
What's the Science in Data Science? - Skipper Seabold
PDF
Applying Statistical Modeling and Machine Learning to Perform Time-Series For...
PDF
Solving very simple substitution ciphers algorithmically - Stephen Enright-Ward
PDF
The Face of Nanomaterials: Insightful Classification Using Deep Learning - An...
Michal Mucha: Build and Deploy an End-to-end Streaming NLP Insight System | P...
Unit testing data with marbles - Jane Stewart Adams, Leif Walsh
The TileDB Array Data Storage Manager - Stavros Papadopoulos, Jake Bolewski
Using Embeddings to Understand the Variance and Evolution of Data Science... ...
Deploying Data Science for Distribution of The New York Times - Anne Bauer
Graph Analytics - From the Whiteboard to Your Toolbox - Sam Lerma
Do Your Homework! Writing tests for Data Science and Stochastic Code - David ...
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
Mining dockless bikeshare and dockless scootershare trip data - Stefanie Brod...
Avoiding Bad Database Surprises: Simulation and Scalability - Steven Lott
Words in Space - Rebecca Bilbro
End-to-End Machine learning pipelines for Python driven organizations - Nick ...
Pydata beautiful soup - Monica Puerto
1D Convolutional Neural Networks for Time Series Modeling - Nathan Janos, Jef...
Extending Pandas with Custom Types - Will Ayd
Measuring Model Fairness - Stephen Hoover
What's the Science in Data Science? - Skipper Seabold
Applying Statistical Modeling and Machine Learning to Perform Time-Series For...
Solving very simple substitution ciphers algorithmically - Stephen Enright-Ward
The Face of Nanomaterials: Insightful Classification Using Deep Learning - An...

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Cloud computing and distributed systems.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Machine Learning_overview_presentation.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Approach and Philosophy of On baking technology
MIND Revenue Release Quarter 2 2025 Press Release
Diabetes mellitus diagnosis method based random forest with bat algorithm
The Rise and Fall of 3GPP – Time for a Sabbatical?
20250228 LYD VKU AI Blended-Learning.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Big Data Technologies - Introduction.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Cloud computing and distributed systems.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Review of recent advances in non-invasive hemoglobin estimation
sap open course for s4hana steps from ECC to s4
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Network Security Unit 5.pdf for BCA BBA.
Machine Learning_overview_presentation.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Reach Out and Touch Someone: Haptics and Empathic Computing

Blosc: Sending Data from Memory to CPU (and back) Faster than Memcpy by Francesc Alted

  • 1. Blosc Sending data from memory to CPU (and back) faster than memcpy() Francesc Alted
 Software Architect
 PyData London 2014 February 22, 2014
  • 2. About Me • I am the creator of tools like PyTables, Blosc, BLZ and maintainer of Numexpr. • I learnt the hard way that ‘premature optimization is the root of all evil’. • Now I only humbly try to optimize if I really need to and I just hope that Blosc is not an example of ‘premature optimization’.
  • 3. About Continuum Analytics • Develop new ways on how data is stored, computed, and visualized. • Provide open technologies for data integration on a massive scale. • Provide software tools, training, and integration/consulting services to corporate, government, and educational clients worldwide.
  • 4. Overview • Compressing faster than memcpy(). Really? • How that can be?
 (The ‘Starving CPU’ problem) • How Blosc works. • Being faster than memcpy() means that my programs would actually run faster?
  • 6. Interactive Session Starts • If you want to experiment with Blosc in your own machine: 
 http://www.blosc.org/materials/PyData- London-2014.tar.gz • blosc (blz too for later on) is required (both are included in conda repository).
  • 7. Open Questions We have seen that, sometimes, Blosc can actually be faster than memcpy(). Now: 1. If compression takes way more CPU than memcpy(), why Blosc can beat it? 2. Does this mean that Blosc can actually accelerate computations in real scenarios?
  • 8. The Starving CPU Problem “Across the industry, today’s chips are largely able to execute code faster than we can feed them with instructions and data.” ! – Richard Sites, after his article
 “It’sThe Memory, Stupid!”, 
 Microprocessor Report, 10(10),1996
  • 9. Memory Access Time vs CPU Cycle Time
  • 11. The Status of CPU Starvation in 2014 • Memory latency (~10 ns) is much slower (between 100x and 250x) than processors. • Memory bandwidth (~15 GB/s) is improving at a better rate than memory latency, but it is also slower than processors (between 30x and 100x).
  • 13. Blosc: (de)compressing faster than memcpy() Transmission + decompression faster than direct transfer?
  • 14. Taking Advantage of Memory-CPU Gap • Blosc is meant to discover redundancy in data as fast as possible. • It comes with a series of fast compressors: BloscLZ, LZ4, Snappy, LZ4HC and Zlib • Blosc is meant for speed, not for high compression ratios.
  • 15. Blosc Is All About Efficiency • Uses data blocks that fit in L1 or L2 caches (better speed, less compression ratios). • Uses multithreading by default. • The shuffle filter uses SSE2 instructions in modern Intel and AMD processors.
  • 17. Suffling: Improving the Compression Ratio The shuffling algorithm does not actually compress the data; it rather changes the byte order in the data stream:
  • 18. Shuffling Caveat • Shuffling usually produces better compression ratios with numerical data, except when it does not. • If you mind about the compression ratio, it is worth to deactivate it and check (it is active by default). • Will see an example on real data later on.
  • 21. First Answer for Open Questions • Blosc data blocking optimizes the cache behavior during memory access. • Additionally, it uses multithreading and SIMD instructions. • Add these to the Starved CPU problem and you have a good hint now on why Blosc can beat memcpy().
  • 23. The Need for Compression • Compression allows to store more data using the same storage capacity. • Sure, it uses more CPU time to compress/ decompress data. • But, that actually means using more wall clock time?
  • 24. The Need for a Compressed Container • A compressed container is meant to store data in compressed state and transparently deliver it uncompressed. • That means that the user only perceives that her dataset takes less memory. • Only less space? What about data access speed?
  • 25. Source: Howison, M. High-throughput compression of FASTQ data with SeqDB. IEEE Transactions on Computational Biology and Bioinformatics. Example of How Blosc Accelerates Genomics I/O: SeqDB (backed by Blosc)
  • 26. Bloscpack (I) • Command line interface and serialization format for Blosc: ! $ blpk c data.dat # compress $ blpk d data.dat.blp # decompress
  • 27. Bloscpack (II) • Very convenient for easily serializing your in-memory NumPy datasets: >>> a = np.linspace(0, 1, 3e8) >>> print a.size, a.dtype 300000000 float64 >>> bp.pack_ndarray_file(a, 'a.blp') >>> b = bp.unpack_ndarray_file('a.blp') >>> (a == b).all() True
  • 28. Yet Another Example: BLZ • BLZ is a both a format and library that has been designed as an efficient data container for Big Data. • Blosc and Bloscpack are at the heart of it in order to achieve high-speed compression/ decompression. • BLZ is one of the backends supported by our nascent Blaze library.
  • 29. Appending Data in Large NumPy Objects Copy! New memory allocation array to be enlarged final array object new data to append • Normally a realloc() syscall will not succeed • Both memory areas have to exist simultaneously
  • 30. Contiguous vs Chunked NumPy container Contiguous memory BLZ container chunk 1 chunk 2 Discontiguous memory chunk N ...
  • 31. Appending data in BLZ compress new chunk array to be enlarged final array object new data to append Only a small amount of data has to be compressed X chunk 1 chunk 2 chunk 1 chunk 2
  • 32. The btable object in BLZ New row to append • Columns are contiguous in memory • Chunks follow column order • Very efficient for querying (specially with a
 large number of columns) Chunks
  • 33. Second Interactive Session: BLZ and Blosc on a Real Dataset
  • 34. Second Hint for Open Questions Blosc usage in BLZ means not only less storage usage (~15x-40x reduction for the real life data shown), but almost the same access time to the data (~2x-10x slowdown). (Still need to address implementation details for getting better performance)
  • 35. Summary • Blosc, being able to transfer data faster than memcpy(), has enormous implications on data management. • It is well suited not only for saving memory, but for allowing close performance to typical uncompressed data containers. • It works well not only for synthetic data, but also for real-life datasets.
  • 36. References • Blosc: http://www.blosc.org • Bloscpack: https://github.com/Blosc/bloscpack • BLZ: http://blz.pydata.org
  • 37. “Across the industry, today’s chips are largely able to execute code faster than we can feed them with instructions and data. There are no longer performance bottlenecks in the floating-point multiplier or in having only a single integer unit. The real design action is in memory subsystems— caches, buses, bandwidth, and latency.” ! “Over the coming decade, memory subsystem design will be the only important design issue for microprocessors.” ! – Richard Sites, after his article “It’sThe Memory, Stupid!”, Microprocessor Report, 10(10),1996 “Over this decade (2010-2020), memory subsystem optimization will be (almost) the only important design issue for improving performance.” – Me :)