Skip to content

Instantly share code, notes, and snippets.

View guizmaii's full-sized avatar
🏄‍♂️

Jules Ivanic guizmaii

🏄‍♂️
View GitHub Profile
@guizmaii
guizmaii / latency.txt
Created December 1, 2017 21:55 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@guizmaii
guizmaii / aws_postgresql_max_connection.md
Last active November 25, 2025 21:42
AWS PostgreSQL max_connection per instance type

The default formula use by AWS RDS to calculate the max_connections parameter is: LEAST({DBInstanceClassMemory/9531392},5000)

But It's hard to find the exact value of DBInstanceClassMemory.

So, here are the values I got when I ran the SQL commmand: show max_connections; in some RDS instances:

Instance type RAM (GB) max_connections
db.t2.small 2 198
db.t2.medium 4 413
@guizmaii
guizmaii / aws_to_gce_and_inverse_via_vpn_and_internet_network_performances.md
Last active January 31, 2018 10:07
Network performance tests between an AWS m5.large machine and a GCE n1-standard-4, via internet and via a VPN

AWS (client) => GCE (server) via VPN:

  • logs clients:
ubuntu@ip-172-31-43-143:~$ iperf -c 10.132.0.2 -f M -p 5001
------------------------------------------------------------
Client connecting to 10.132.0.2, TCP port 5001
TCP window size: 0.04 MByte (default)
------------------------------------------------------------
[  3] local 172.31.43.143 port 55156 connected with 10.132.0.2 port 5001
@guizmaii
guizmaii / jts_geom_json.scala
Last active November 21, 2018 10:14
JTS Geometry Play JSON Format
import com.vividsolutions.jts.geom.Geometry
import com.vividsolutions.jts.io.ParseException
import com.vividsolutions.jts.io.geojson.{GeoJsonReader, GeoJsonWriter}
import play.api.libs.json._
import scala.reflect.ClassTag
import scala.util.{Failure, Success, Try}
object GeometryJson {
implicit final val geometryFormat: Format[Geometry] = {
@guizmaii
guizmaii / gist:e4bac45621f1489c78dcdb71a9cdf23a
Created February 19, 2018 10:08
JST GeometryFactory instance
import com.vividsolutions.jts.geom.{GeometryFactory, PrecisionModel}
object GeometryFactoryInstance {
lazy val instance: GeometryFactory = new GeometryFactory(new PrecisionModel(), 4326)
}

Quick Tips for Fast Code on the JVM

I was talking to a coworker recently about general techniques that almost always form the core of any effort to write very fast, down-to-the-metal hot path code on the JVM, and they pointed out that there really isn't a particularly good place to go for this information. It occurred to me that, really, I had more or less picked up all of it by word of mouth and experience, and there just aren't any good reference sources on the topic. So… here's my word of mouth.

This is by no means a comprehensive gist. It's also important to understand that the techniques that I outline in here are not 100% absolute either. Performance on the JVM is an incredibly complicated subject, and while there are rules that almost always hold true, the "almost" remains very salient. Also, for many or even most applications, there will be other techniques that I'm not mentioning which will have a greater impact. JMH, Java Flight Recorder, and a good profiler are your very best friend! Mea

@guizmaii
guizmaii / NonEmptySet.scala
Created March 24, 2018 16:48 — forked from channingwalton/NonEmptySet.scala
NonEmptySet Implementation
import cats.data.NonEmptyList
import cats.Eq
import scala.collection.GenTraversableOnce
sealed trait NonEmptySet[T] extends (T => Boolean) {
def head: T
def set: Set[T]
def +(t: T): NonEmptySet[T]
def ++(ts: NonEmptySet[T]): NonEmptySet[T]
@guizmaii
guizmaii / NonEmptySet.scala
Created March 24, 2018 16:48 — forked from channingwalton/NonEmptySet.scala
NonEmptySet Implementation
import cats.data.NonEmptyList
import cats.Eq
import scala.collection.GenTraversableOnce
sealed trait NonEmptySet[T] extends (T => Boolean) {
def head: T
def set: Set[T]
def +(t: T): NonEmptySet[T]
def ++(ts: NonEmptySet[T]): NonEmptySet[T]
@guizmaii
guizmaii / x.scala
Created May 28, 2018 16:24 — forked from kevinmeredith/x.scala
Run IO[List[Int]] in Parallel using Ammonite
@ import $ivy.`org.typelevel::cats-effect:0.10.1`
@ import cats._, cats.data._, cats.implicits._, cats.effect._
@ def lift(i: Int): IO[Int] = Timer[IO].sleep(1.second) >> IO {
println(Thread.currentThread.getName + "At time = " + java.time.Instant.now)
i
}
@guizmaii
guizmaii / x.scala
Last active May 28, 2018 16:28 — forked from kevinmeredith/x.scala
Run IO[List[Int]] in Parallel using Ammonite
@ import $ivy.`org.typelevel::cats-effect:0.10.1`
@ import cats._, cats.data._, cats.implicits._, cats.effect._, scala.concurrent.duration._, import scala.concurrent.ExecutionContext.Implicits.global
@ def lift(i: Int): IO[Int] = Timer[IO].sleep(1.second) >> IO {
println(Thread.currentThread.getName + "At time = " + java.time.Instant.now)
i
}