Skip to content

Instantly share code, notes, and snippets.

View r4um's full-sized avatar

Pranay Kanwar r4um

View GitHub Profile
@r4um
r4um / SynchSB.java
Created October 2, 2017 14:12 — forked from rednaxelafx/SynchSB.java
Demo JDK8 HotSpot C2's escape analysis + lock elision
public class SynchSB {
StringBuilder sb = new StringBuilder();
public synchronized int length() {
return sb.length();
}
public synchronized StringBuilder append(String str) {
return sb.append(str);
}
@r4um
r4um / dockerpsns.sh
Created September 18, 2017 07:36 — forked from brendangregg/dockerpsns.sh
docker ps --namespaces
#!/bin/bash
#
# dockerpsns - proof of concept for a "docker ps --namespaces".
#
# USAGE: ./dockerpsns.sh
#
# This lists containers, their init PIDs, and namespace IDs. If container
# namespaces equal the host namespace, they are colored red (this can be
# disabled by setting color=0 below).
#
@r4um
r4um / hsdis.md
Last active March 31, 2021 07:17
hsdis with binutils-2.30

Get from http://hg.openjdk.java.net/jdk/jdk/file/ee1d592a9f53/src/utils/hsdis

diff -r 96e9e479ff8a src/share/tools/hsdis/hsdis.c
--- a/src/share/tools/hsdis/hsdis.c	Thu Aug 24 01:27:02 2017 -0400
+++ b/src/share/tools/hsdis/hsdis.c	Thu Aug 31 18:36:50 2017 +0530
@@ -312,7 +312,7 @@

   /* Finish linking together the various callback blocks. */
 app_data->dinfo.application_data = (void*) app_data;
@r4um
r4um / wait_timeout.go
Created July 7, 2017 13:55 — forked from x32net/wait_timeout.go
Golang - WaitGroup Timeout
package main
import (
"fmt"
"sync"
"time"
)
func main() {
wg := sync.WaitGroup{}
@r4um
r4um / count_hbase.sh
Created May 22, 2017 17:02 — forked from tsuna/count_hbase.sh
Script to get stats on the number of KeyValue and size of an HBase table, directly from HFiles
#!/bin/bash
# Copyright (c) 2010, 2011 Benoit Sigoure. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
@r4um
r4um / jvmrap.md
Created May 19, 2017 12:29
jvm rap
  ⚡ cat RAvailableProcessors.java 
public class RAvailableProcessors {
    public static void main(String[] args) {
        Runtime runtime = Runtime.getRuntime();
        int numberOfProcessors = runtime.availableProcessors();
        System.out.println(numberOfProcessors);
    }
}
@r4um
r4um / lcla.md
Last active April 24, 2017 13:50
LogrotateContainerLogger args
{
  "libraries": [{
    "file": "/usr/lib/liblogrotate_container_logger.so",
    "modules": [{
      "name": "org_apache_mesos_LogrotateContainerLogger",
       "parameters": [
             {
               "key": "max_stdout_size",
 "value": "25MB"
@r4um
r4um / mlgkill.md
Created April 12, 2017 18:40
mlg kill
slave-one_1  | I0412 18:22:24.104487 23545 slave.cpp:3538] executor(1)@172.17.0.1:38691 exited
slave-one_1  | I0412 18:22:24.126058 23540 docker.cpp:1932] Executor for container 'a0218785-4781-466f-9f4b-412a7a1cbf0c' has exited
slave-one_1  | I0412 18:22:24.126096 23540 docker.cpp:1696] Destroying container 'a0218785-4781-466f-9f4b-412a7a1cbf0c'
slave-one_1  | I0412 18:22:24.126121 23540 docker.cpp:1824] Running docker stop on container 'a0218785-4781-466f-9f4b-412a7a1cbf0c'
slave-one_1  | I0412 18:22:24.127027 23544 slave.cpp:3871] Executor 'hello-flask.d7203ed9-1fac-11e7-a2bf-0242bd6725c6' of framework 630eaa98-6cd5-42c5-ab3b-c26e0f376e5b-0000 terminated with signal Terminated
slave-one_1  | I0412 18:22:24.127125 23544 slave.cpp:3012] Handling status update TASK_FAILED (UUID: 37b0aa35-bdd4-4ccf-98e4-99dddd22a7e4) for task hello-flask.d7203ed9-1fac-11e7-a2bf-0242bd6725c6 of framework 630eaa98-6cd5-42c5-ab3b-c26e0f376e5b-0000 from @0.0.0.0:0
slave-one_1  | W0412 18:22:24.127547 23545 docker.cpp:1302] Igno

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@r4um
r4um / btrace.md
Created November 3, 2016 06:11
BTrace foo

Need java 7, jdk8 crashes pending fix see btraceio/btrace#240

⚡ java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

Assuming btrace is installed in ~/bin/btrace-1.3.8.3/