Skip to content

Instantly share code, notes, and snippets.

@MichaelScofield
MichaelScofield / JavaWaitAndNotify
Created May 7, 2013 12:01
Typical usage of Object.wait() and Object.notify()
package test;
public class Main {
private final Object MONITOR = new Object();
private class PrintNum extends Thread {
volatile int num = 1;
@MichaelScofield
MichaelScofield / ClhSpinLock.java
Last active August 29, 2015 14:08
A simple CLH spin lock implementation
public class ClhSpinLock {
private final ThreadLocal<Node> pred;
private final ThreadLocal<Node> node;
private final AtomicReference<Node> tail = new AtomicReference<Node>(new Node());
public ClhSpinLock() {
node = new ThreadLocal<Node>() {
protected Node initialValue() {
return new Node();
}
@MichaelScofield
MichaelScofield / leetcode_solution_538.go
Created September 14, 2017 09:56
538. Convert BST to Greater Tree
var sum int
func convertBST(root *TreeNode) *TreeNode {
if root == nil {
return nil
}
sum = 0
traverse(root)
import org.apache.commons.lang3.tuple.Pair;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
//noinspection unchecked
Pair<String, Boolean>[] testCases = new Pair[]{
Pair.of("ex 1", true),
Pair.of("px 1", true),
@MichaelScofield
MichaelScofield / redis.py
Created May 13, 2021 02:11 — forked from joewalnes/redis.py
Microlibrary: Python Redis client
from telnetlib import Telnet
class RedisLiteClient:
"""
Super lightweight no-frills blocking Redis client that doesn't require any additional dependencies.
This is a microlibrary, designed for easy copy'n'paste into a project, where you don't want to
rely on pip/easy_install/etc.
Usage:
@MichaelScofield
MichaelScofield / High_Performance_Redis.md
Created August 6, 2022 11:19 — forked from neomantra/High_Performance_Redis.md
Notes on running Redis with HPC techniques

High Performance Redis

In response to this brief blog entry, @antirez tweeted for some documentation on high-performance techniques for Redis. What I present here are general high-performance computing (HPC) techniques. The examples are oriented to Redis. but they work well for any program designed to be single- or worker-threaded and asynchronous (e.g. uses epoll).

The motivation for using these techniques is to maximize performance of our system and services. By isolating work, controlling memory, and other tuning, you can achieve significant reduction in latency and increase in throughput.

My perspective comes from the microcosm of my own bare-metal (vs VM), on-premises deployment. It might not be suitable for all scenarios, especially cloud deployments, as I have little experience with HPC there. After some discussion, maybe this can be adapted as [redis.io documentation](https://redis.io/do