Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
import clickhouse_driver
c = clickhouse_driver.Client(host='127.1')
c.execute('select * from numbers(100000)', settings={'send_profile_events': 0})
c.execute('select * from numbers(100000)', settings={'send_profile_events': 1})
c.execute('insert into function null() values', ((x, ) for x in range(5)), settings={'send_profile_events': 1})
# this is broken
$ python /tmp/clickhouse-exception.py
(0, '!#Vf5ABBlu!?8He&[nGr')
(0, '\\4(?%F5=>i,2l$?h<@!$')
(0, ':225JvK(tIr>!:*#t\\cD')
(0, 'E93AuwfS%QL~<NYr(&!M')
(0, 'r}e\\ K;8_w$x&fu [ht"')
(0, 'I\\x Kicp;N@okI?*J23 ')
(0, "ml{pd'|O>RX14@][H )]")
(0, 'S"Rj"_c\'".L,MB#9f)\'M')
(0, "'$ltY~+FpQ<=OA_^Edt+")
// Written with ChatGPT
#include <iostream>
#include <chrono>
#include <format>
#include <print>
#include <fmt/core.h>
#include <fmt/format.h>
#include <fmt/chrono.h>
#include <fmt/ranges.h>
@azat
azat / clickhouse.untracked_memory.stacktrace
Created December 10, 2024 20:05
Example of stacktrace with untracked_memory for ThreadStatus
2024.12.10 14:13:33.100758 [ 3466 ] {b0c2bae7-e930-484d-9a98-26d972c8a985} <Trace> PushingToViews: Pushing (sequentially) from default.t_null (97ff26c2-3608-4b4b-b9a9-41696dd3f1a1) to default.t_mv (6ce3ce80-e1b0-4986-a79f-6c318399a8a6) took 21719 ms.
2024.12.10 14:13:33.100823 [ 3466 ] {} <Error> ThreadStatus: Untracked memory left: -96.00 B
2024.12.10 14:13:33.100969 [ 3135 ] {} <Trace> BaseDaemon: Received signal 6
2024.12.10 14:13:33.101277 [ 13793 ] {} <Fatal> BaseDaemon: ########## Short fault info ############
2024.12.10 14:13:33.101325 [ 13793 ] {} <Fatal> BaseDaemon: (version 24.12.1.1, build id: FBBF1E9C30254289BBFDF63093B967C2508ACB4C, git hash: 423da86c3064580c77679684d61b2b9d73da756f, architecture: x86_64) (from thread 3466) Received signal 6
2024.12.10 14:13:33.101344 [ 13793 ] {} <Fatal> BaseDaemon: Signal description: Aborted
2024.12.10 14:13:33.101351 [ 13793 ] {} <Fatal> BaseDaemon:
2024.12.10 14:13:33.101370 [ 13793 ] {} <Fatal> BaseDaemon: Stack trace: 0x000000000c16f4ed 0x000000000c42cafc
import os
import pyinotify
def get_current_memory_cgroup_path():
try:
with open("/proc/self/cgroup", "r") as f:
for line in f:
parts = line.strip().split(":")
if len(parts) == 3 and parts[1] == "":
#!/usr/bin/env python3
import matplotlib.pyplot as plt
def hashsocket_1(fd):
return fd
def hashsocket_2(fd):
@azat
azat / test-clocks-monotonicity.cpp
Last active July 12, 2024 12:18
Test CLOCK_MONOTONIC/CLOCK_MONOTONIC_RAW/rdtsc monotonicity
#include <atomic>
#include <bits/types/clockid_t.h>
#include <cstdint>
#include <cstdlib>
#include <ctime>
#include <cerrno>
#include <iostream>
#include <list>
#include <random>
#include <sched.h>
@azat
azat / lockfree-rename-benchmark.sh
Created June 7, 2024 13:40
Measure overhead of fsync_part_directory for SELECTs from MergeTree/ReplicatedMergeTree in ClickHouse (due to rename under lock)
#!/usr/bin/env bash
# Measure overhead of fsync_part_directory for SELECTs from MergeTree/ReplicatedMergeTree (due to rename under lock)
# Refs: https://github.com/ClickHouse/ClickHouse/pull/64955
set -e
bin=$1 && shift
id=$BASHPID
@azat
azat / addr2line
Last active April 23, 2025 22:10
Wrapper for llvm addr2line (faster then binutils) for perf
#!/usr/bin/env bash
# This is wrapper for faster addr2line, that is required for "perf --call-graph dwarf"
# NOTE: since v6.3 perf supports specifying addr2line and supports LLVM so it is not required there
# stdbuf is important here to avoid buffering, otherwise perf will stuck
stdbuf -o0 -i0 sed -e 's/,//' -e 's/^$/ffffffffffffff/' | llvm-addr2line "$@"
@azat
azat / test-locks.cpp
Last active January 28, 2024 15:10
Test various locks (under contention and not)
#include <boost/smart_ptr/detail/spinlock.hpp>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <iostream>
#include <list>
#include <mutex>
#include <optional>
#include <shared_mutex>
#include <thread>