Skip to content

Instantly share code, notes, and snippets.

View cspinetta's full-sized avatar
👨‍💻
I may be slow to respond.

Cristian Spinetta cspinetta

👨‍💻
I may be slow to respond.
View GitHub Profile
#!/usr/bin/env bash
cat /proc/net/tcp* | awk '
{
TOTAL += $7;
COUNT++;
}
END {
printf "rate_retr %.3f\n", TOTAL/COUNT
}
@cspinetta
cspinetta / docker-compose.yml
Created May 21, 2020 12:26
Promtail example extracting data from json log
version: "3.6"
services:
promtail:
image: grafana/promtail:1.4.0
container_name: promtail
command: [ "-config.file=/etc/promtail/local-config.yaml" ]
volumes:
- './promtail.yml:/etc/promtail/local-config.yaml:ro'
- '__path_to_logs_directory__:/app/log:ro'
@cspinetta
cspinetta / synchronization-implementation-in-jvm.md
Last active February 24, 2022 15:45
Synchronization in Java

Object locking implementation in the Java HotSpot VM

The most synchronization idiom in Java is using the synchronized keyword.

The JVM supports synchronization of both methods and sequences of instructions within a method using a single synchronization construct - synchronized - which is built around an internal entity known as the intrinsic lock or monitor lock (The API specification often refers to this entity simply as a "monitor"). Intrinsic locks play a role in both aspects of synchronization: enforcing exclusive access to an object's state and establishing happens-before relationships to ensure a correct visibility amoung threads.

At bytecode level, the JVM supplies the monitorenter and monitorexit instructions to support such constructs.

At runtime level, in the Java HotSpot VM, every object has a built-in monitor (the so called intrinsic lock or monitor lock) that can be acquired by any thread.

@cspinetta
cspinetta / main.go
Created April 19, 2021 20:05
Simulate a large payload on the fly with an io.Reader
package main
import (
"fmt"
"io"
)
func main() {
r := NewDataGenerator(1000)