Skip to content

Instantly share code, notes, and snippets.

View sanketsudake's full-sized avatar

Sanket Sudake sanketsudake

View GitHub Profile

Stochastic Fairness Queuing (SFQ) is a packet scheduling algorithm designed to ensure fair access to network resources or application backends. Instead of allocating a dedicated queue for every single flow (which is memory-intensive and doesn't scale), SFQ hashes the flow identifier (like a user ID, IP address, or tenant ID) to assign it to one of a fixed number of queues.

While SFQ prevents a single high-volume flow from monopolizing the entire system, hash collisions can cause an innocent flow to share a queue with a "noisy neighbor." To mitigate this, advanced load balancing strategies like Shuffle Sharding and the Best of Two (Power of Two Choices) are often layered on top.

Here is how you can implement basic SFQ and its enhanced variants in Go. We will focus on the dispatcher logic—the part of the system responsible for routing an incoming request to the appropriate queue.

Setup: Basic Types and Hashing

// Unit testing is an important part of writing
// principled Go programs. The `testing` package
// provides the tools we need to write unit tests
// and the `go test` command runs tests.
// For the sake of demonstration, this code is in package
// `main`, but it could be any package. Testing code
// typically lives in the same package as the code it tests.
package main
@sanketsudake
sanketsudake / go-cache.md
Last active February 6, 2025 03:38
Go Cachec Checking and Cleanup

Check Go Cache Size

du -sh $(go env GOCACHE)

Check largest files in cache

find $(go env GOCACHE) -type f | xargs du -s | sort -n
@sanketsudake
sanketsudake / add-cloned-submodule
Created April 11, 2024 08:37
Add already cloned repo as submodules
for i in $(find example-sources -type d -depth 1)
do
echo $i
pushd $i
url=$(git remote get-url $(git remote))
echo $url
popd
git submodule add $url ./$i
done
@sanketsudake
sanketsudake / AWS Bedrock PDF Summary with langchain.md
Last active April 22, 2025 16:41
PDF summarizer with langchain and Amazon Bedrock Titan

Usage

  • Setup python dependencies from requirements.txt
  • Source your AWS enviroment credentials.
    • Enable Amazon bedrock amazon.titan-text-express-v1 model for access
    • AWS_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN(optional)
  • Run python pdf_summary.py
    python pdf_summary.py
    

Running on local URL: http://127.0.0.1:7860

@sanketsudake
sanketsudake / fission-kafka-mqt-dashboard.json
Created November 28, 2022 10:11
Fission Kafka MQT dashboard
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
# Reference: https://sharats.me/posts/shell-script-best-practices/
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
if [[ -n "${TRACE-}" ]]; then
set -o xtrace
fi
@sanketsudake
sanketsudake / dump-analyzer
Last active November 13, 2022 07:55
Dump Analyzer for Fission
#!/usr/bin/env bash
###
# This script is used to analyze the dump files generated by the Fission CI.
###
set -o errexit
set -o nounset
set -o pipefail
if [[ -n "${TRACE-}" ]]; then
set -o xtrace
fi
@sanketsudake
sanketsudake / kind-kubernetes-metrics-server.md
Last active January 29, 2026 22:14
Running metric-server on Kind Kubernetes

I have created a local Kubernetes cluster with kind. Following are changes you need to get metric-server running on Kind.

Deploy latest metric-server release.

kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.5.0/components.yaml

Within existing arguments to metric-server container, you need to add argument --kubelet-insecure-tls.

The Problem

Alice and Bob have accounts at Bankgroup. Each account has 0 or more dollars in it.

Bankgroup wants to add a new “wire” feature, where any user can transfer money to any other user. This feature has the following requirements:

  • Each wire must be between two different people in the bank and wire at least one dollar.

  • If a wire is successful, the value of the wire is deducted from the sender account and added to the receiver account.