Skip to content

Instantly share code, notes, and snippets.

@azat
azat / 01830_mmap.config.xml
Created April 19, 2021 21:24
clickhouse-min_bytes_to_use_mmap_io-issue
<?xml version="1.0"?>
<yandex>
<logger>
<level>trace</level>
<console>true</console>
</logger>
<tcp_port>9000</tcp_port>
<path>./</path>
@azat
azat / fio.cfg
Last active April 19, 2021 08:04
read/read page cache/read direct/read mmap
[global]
size=512m
blocksize=32k
timeout=60
numjobs=1
invalidate=1 ; invalidate page-cache (set it explicitly, even though default is true)
[read_mmap]
stonewall
ioengine=mmap
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#include <string.h>
void* mmap_hint()
{
SELECT *
FROM system.distribution_queue
FORMAT Vertical
Query id: bb17b27d-c681-4826-8eb6-607a960414f3
Row 1:
──────
database: default
table: dist
@azat
azat / atomic_benchmark.cpp
Created November 23, 2020 19:48
userspace-RCU-vs-std::atomic
/// https://github.com/aosp-mirror/platform_bionic/blob/master/benchmarks/atomic_benchmark.cpp
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
select version();
-- ┌─version()───┐
-- │ 20.3.15.133 │
-- └─────────────┘
create table ranges_data engine=Memory() as select number key, number value from numbers(100);
create dictionary default.ranges_dict (key UInt64, value UInt64 default 1) primary key key source(clickhouse(host '127.0.0.1' port 9000 table 'ranges_data' db 'default' user 'default' password '')) lifetime(0) layout(cache(size_in_cells 100));
create table dist as system.one engine=Distributed('test_cluster_two_shards', system, one, dictGetUInt64('default.ranges_dict', 'value', toUInt64(dummy)));
SELECT *
#!/usr/bin/env bash
# XXX: cannot use expect since we need two clients
# XXX: requires bash 4.4+
function assert()
{
if ! "$@"; then
echo "'$*' failed" >&2
exit 1
@azat
azat / rand.c
Last active October 7, 2020 08:52
// gist for showing that rand() with global lock is slower ~60x times
// (came to this for librdkafa random partitioning with producer per group, and eventually program has ~1200 threads)
//
// $ g++ -DRAND -o rand -O3 -pthread rand.cpp
// $ g++ -DRAND_R -o rand_r -O3 -pthread rand.cpp
//
// $ time ./rand
//
// real 0m2.336s
// user 0m2.685s
@azat
azat / test-MADV_DONTNEED.c
Created October 3, 2020 22:22
test-MADV_DONTNEED.c
// Gist to check possible issues with MADV_DONTNEED
// For example it does not supported by qemu user
// There is a patch for this [1], but it hasn't been applied.
// [1]: https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg05422.html
#include <sys/mman.h>
#include <stdio.h>
#include <stddef.h>
#include <assert.h>
#include <string.h>
2020-09-22 00:48:35 01502_jemalloc_percpu_arena: [ FAIL ] 7.43 sec. - return code 66
2020-09-22 00:48:35 ==================
2020-09-22 00:48:35 WARNING: ThreadSanitizer: data race (pid=384)
2020-09-22 00:48:35 Write of size 8 at 0x7b1000008ff8 by main thread (mutexes: write M1432):
2020-09-22 00:48:35 #0 operator delete(void*, unsigned long) <null> (clickhouse+0x8085f1e)
2020-09-22 00:48:35 #1 Poco::Logger::~Logger() /build/obj-x86_64-linux-gnu/../contrib/poco/Foundation/src/Logger.cpp:39:1 (clickhouse+0x14dc78ce)
2020-09-22 00:48:35 #2 non-virtual thunk to Poco::Logger::~Logger() /build/obj-x86_64-linux-gnu/../contrib/poco/Foundation/src/Logger.cpp (clickhouse+0x14dc78ce)
2020-09-22 00:48:35 #3 Poco::RefCountedObject::release() const /build/obj-x86_64-linux-gnu/../contrib/poco/Foundation/include/Poco/RefCountedObject.h:82:24 (clickhouse+0x14dcb797)
2020-09-22 00:48:35 #4 Poco::Logger::shutdown() /build/obj-x86_64-linux-gnu/../contrib/poco/Found