Skip to content

Instantly share code, notes, and snippets.

View BewareMyPower's full-sized avatar
🏠
Working from home

Yunze Xu BewareMyPower

🏠
Working from home
View GitHub Profile
@BewareMyPower
BewareMyPower / topic-loading-in-pulsar.md
Created November 5, 2025 12:34
(Drafted) Topic loading in Pulsar

Topic load process

Specifically, for a partition of a partitioned persistent topic, the topic load process is as follows:

  1. Check if the topic exists (Metadata store: /managed-ledgers/<persistence-naming-encoding>)
  2. Get topic policies (via TopicPoliciesService#getTopicPoliciesAsync)
  3. Check topic ownership
  4. Check if the pending topic loading count exceeds the maxConcurrentTopicLoadRequest config (default: 5000), if not, the following steps will be executed after the previous topic loading operations are completed.
  5. Check topic ownership again
  6. Fetch topic properties (Metadata store: /admin/partitioned-topics///persistent/)
@BewareMyPower
BewareMyPower / netty-recycler-revisit.md
Created September 12, 2025 15:30
Revisit the Netty Recycler

Revisit Netty Recycler adoptions in Pulsar

TL; DR, go to the last section for the conclusion.

Background

Apache Pulsar heavily uses Netty Recycler as a memory pool to reduce heap memory usage to reduce GC pressure. Here are the full list:

$ find . -name "*.java" |  grep  "src/main" | xargs grep -n "new Recycler"
@BewareMyPower
BewareMyPower / LegacyTopicName.java
Created June 25, 2025 08:29
Pulsar's legacy TopicName implementation
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
@BewareMyPower
BewareMyPower / pulsar-client-go-release-verify.sh
Created May 20, 2025 08:28
Verify pulsar-client-go release
#!/bin/bash
set -e
cd `dirname $0`
VERSION=0.15.1
RC_SUFFIX="-candidate-1"
BASE_URL=https://dist.apache.org/repos/dist/dev/pulsar/pulsar-client-go-$VERSION$RC_SUFFIX
FILENAME=apache-pulsar-client-go-$VERSION-src.tar.gz
if [[ ! -f $FILENAME ]]; then
@BewareMyPower
BewareMyPower / ReflectionBenchmark.java
Created February 21, 2025 02:02
The cost of reflection vs. thread switching
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
@BewareMyPower
BewareMyPower / StreamBenchmark.java
Created February 17, 2025 09:23
Run benchmark for stream() vs parallelStream()
package io.bewaremypower;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Scope;
@BewareMyPower
BewareMyPower / ConcurrentHashMapGetTest.java
Last active August 24, 2024 08:15
Compare the get performance for various concurrent hash map
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@BewareMyPower
BewareMyPower / ConcurrentHashMapTest.java
Created August 24, 2024 07:44
Benchmark for various thread safe hash map
package org.example.benchmark;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
@BewareMyPower
BewareMyPower / verify-pulsar-client-cpp-vcpkg.md
Last active December 19, 2023 13:28
Verify pulsar-client-cpp vcpkg port.md

Example code and vcpkg.json

vcpkg.json:

{
  "name": "vcpkg-pulsar-demo",
  "version-string": "0.1.0",
  "builtin-baseline": "<commit-id>",
  "dependencies": [
@BewareMyPower
BewareMyPower / cluster.cc
Last active November 29, 2023 10:37
The tool to set up and tear down an Apache Pulsar cluster locally
// cluster.cc: The tool to set up and tear down an Apache Pulsar cluster locally.
//
// ## Preparation
//
// Build the CLI tool.
//
// ```bash
// g++ cluster.cc -std=c++11 -o cluster.out
// ```
//