Using The Linux Kernel and Cgroups to Simulate Starvation
When using a database like ArangoDB it is also important to explore how it behaves once it reaches system bottlenecks, or which KPIs (Key Performance Indicators) it can achieve in your benchmarks under certain limitations. One can achieve this by torturing the system by effectively saturating the resources using random processes.
This however will drown your system effectively - it may hinder you from capturing statistics, do debugging, and all other sorts of things you're used to from a normally running system. The more clever way is to tell your system to limit the available resources for processes belonging to a certain cgroup.
So we will put an ArangoDB server process (arangod
) into a cgroup, the rest of your system won't be in.
Cgroups - What’s That?
Definition from Wikipedia:
cgroups (abbreviated from control groups) is a Linux kernel feature that limits, accounts for, and isolates the resource usage (CPU, memory, disk I/O, network, etc.) of a collection of processes.
Cgroups were introduced in 2006 and their first real usage example was that you were able to compile a Linux kernel with many parallel compilation processes without sacrificing the snappiness of the user interface – continue browsing, emailing etc. while your sysem compiles with all available resources.
Cgroups are available wherever you run a recent Linux kernel, including Docker Machine on Mac and Windows if you have root access to the host VM.
I/O Saturation
A basic resource you can run out of is disk I/O. The available bandwidth to your storage can be defined by several bottlenecks:
- the bus your storage is connected to - SATA, FC-AL, or even a VM where the hypervisor controls your available bandwidth
- the physical medium, be it spinning disk, SSD, or be it abstracted away from you by a VM
In a cooperative cloud environment you may find completely different behavior compared to bare metal infrastructure which is not virtualized or shared. The available bandwidth is shared between you and other users of this cloud. For example, AWS has a system of Burst Credits where you are allowed to have a certain amount of high speed I/O operations. However, once these credits dry up, your system comes to a grinding hold.
I/O Throttling via Cgroups
Since it may be hard to reach the physical limitations of the SUT, and – as we already discussed – other odd behavior may occur when loading the machine hard to its limits, simply lowering the limit for the processes in question is a good thing.
To access these cgroups you most likely need to have root
access to your system. Either login as root for the following commands, or use sudo
.
Linux cgroups may limit I/O bandwidth per physical device in total (not partitions), and then split that further for individual processes. So the easiest way ahead is to add a second storage device to be used for the ArangoDB database files.
At first you need to configure the bandwidth of the "physical" device; search its major and minor node ID by listing its device file:
ls -l /dev/sdc
brw-rw---- 1 root disk 8, 32 Apr 18 11:16 /dev/sdc
(We picked the third disk here; your names may be different. Check the output of mount
to find out.)
We now mount a partition from sdc so we can access it with arangod
:
/dev/sdc1 on /limitedio type ext4 (rw,relatime)
Now we alter the /etc/arangodb3/arangod.conf
so it will create its database directory on this disk:
[database]
directory = /limitedio/db/
Here we pick the major
number (8) and minor
number (32) from the physical device file:
echo "8:32 1073741824" > /sys/fs/cgroup/blkio/blkio.throttle.write_bps_device
echo "8:32 1073741824" > /sys/fs/cgroup/blkio/blkio.throttle.read_bps_device
This permits a full gigabyte per second for the complete device.
We now can sub-license I/O quota for sdc into a CGroup we name limit1M
which will get 1 MB/s:
mkdir -p /sys/fs/cgroup/blkio/limit1M/
echo "8:32 1048576" > /sys/fs/cgroup/blkio/limit1M/blkio.throttle.write_bps_device
echo "8:32 1048576" > /sys/fs/cgroup/blkio/limit1M/blkio.throttle.read_bps_device
We want to jail one arangod
process into the limit1M
cgroup, we inspect its welcome message for its PID:
2019-01-10T18:00:00Z [13716] INFO ArangoDB (version 3.4.2 [linux]) is ready for business. Have fun!
We add this process with the PID 13716
to the cgroup limit1M
by invoking:
echo 13716 > /sys/fs/cgroup/blkio/limit1M/tasks
Now this arangod
process will be permitted to read and write with 1 MB/s to any partition on sdc. You may want to compare the throughput you get using i.e. arangobench
or arangoimport
.
Real numbers
Depending on pricing and scaling cloud providers give you varying limits in throughput. It appears the worst case is Google at 3 MB/s (as of this posting).
- https://cloud.google.com/compute/docs/disks/performance
- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html
So you may use your notebook with a high-end M2-SSD, and get an estimate whether certain cloud instances may handle the load of your application.
Happy Holidays from ArangoDB!
2018 has been a fantastic year for the ArangoDB project. The community has welcomed many new members, customers, supporters and friends. Together we’ve reached new “heights” – accomplished goals, shipped a big brand-new release and improved ArangoDB on all fronts. Read more
Deploying ArangoDB 3.4 on Kubernetes
It has been a few months since we first released the Kubernetes operator for ArangoDB and started to brag about it. Since then, quite a few things have happened.
For example, we have done a lot of testing, fixed bugs, and by now the operator is declared to be production ready for three popular public Kubernetes offerings, namely Google Kubernetes Engine (GKE), Amazon Elastic Kubernetes Service (EKS) and Pivotal Kubernetes Service (PKS) (see here for the current state of affairs). Read more
ArangoDB 3.4 GA
Full-text Search, GeoJSON, Streaming & More
The ability to see your data from various perspectives is the idea of a multi-model database. Having the freedom to combine these perspectives into a single query is the idea behind native multi-model in ArangoDB. Extending this freedom is the main thought behind the release of ArangoDB 3.4.
We’re always excited to put a new version of ArangoDB out there, but this time it’s something special. This new release includes two huge features: a C++ based full-text search and ranking engine called ArangoSearch; and largely extended capabilities for geospatial queries by integrating Google™ S2 Geometry Library and GeoJSON. Read more
RC1 ArangoDB 3.4 – What’s new?
For ArangoDB 3.4 we already added 100,000 lines of code, happily deleted 50,000 lines and changed over 13,000 files until today. We merged countless PRs, invested months of problem solving, hacking, testing, hacking and testing again and are super excited to share the feature complete RC1 of ArangoDB 3.4 with you today. Read more
Gartner Report: Top-Rated Operational Database Management Systems
Firstly, a huge thank you to all our customers that took the time to review ArangoDB for the Gartner Peer Insights “Voice of the Customer”: Operational Database Management Systems Market report. Without your help and assistance, the continued improvements and enhancements we make to our software wouldn’t be possible. Read more
Time traveling with graph databases
Graph databases are often used to analyze relations within highly interconnected datasets. Social networks, recommendation engines, corporate hierarchies, fraud detection or querying a bill of materials are common use cases. But these datasets change over time and you as a developer or data scientist may want to time travel and analyze these changes.
While ArangoDB may not come with built-in support for managing the revision history of graph data, we’ll show in this article how to manage it in a performant manner for some general classes of graphs. Best of all, this won’t require any groundbreaking new ideas. We’ll simply borrow a few tools and tricks from the persistent data structure literature and adapt them for good performance within ArangoDB. We hope that this will help enable new ways to use everyone’s favorite avocado-fueled datastore, and power some useful applications. Read more
Speeding Up Dump Restore in ArangoDB: Enhanced Data Recovery
Many ArangoDB users rely on our `arangodump` and `arangorestore` tools as an integral part of their backup and recovery procedures. As such, we want to make the use of these tools, especially `arangodump`, as fast as possible. We’ve been working hard toward this goal in preparation for the upcoming 3.4 release.
We’ve made a number of low-level server-side changes to significantly reduce overhead and improve throughput. Additionally, we’ve put some work into rewriting much of the code for the client tools to allow dumping and restoring collections in parallel, using a number of worker threads specified by `–threads n`. Read more
Data retrieval performance optimizations in ArangoDB 3.3.9
Our recent release 3.3.9 includes several performance optimizations for data retrieval cases. Benefits can be expected for both storage engines, MMFiles and RocksDB, AQL batch lookup queries, and cluster AQL queries.
MMFiles index batch lookups
For the MMFiles engine, an optimization has been made for retrieving multiple documents from an index (hash index, skiplist index or persistent index) in a batch.
Read more
An implementation of phase-fair reader/writer locks
We were in search for some C++ reader/writer locks implementation that allows a thread to acquire a lock and then optionally pass it on to another thread. The C++11 and C++14 standard library lock implementations std::mutex and shared_mutex do not allow that (it would be undefined behaviour – by the way, it’s also undefined behaviour when doing this with the pthreads library).
Additionally, we were looking for locks that would neither prefer readers nor writers, so that there will be neither reader starvation nor writer starvation. And then, we wanted concurrently queued read and write requests that compete for the lock to be brought into some defined execution order. Ideally, queued operations that cannot instantly acquire the lock should be processed in approximately the same order in which they queued. Read more
Get the latest tutorials,
blog posts and news:
Thanks for subscribing! Please check your email for further instructions.