Skip to content

Instantly share code, notes, and snippets.

View mostafa-asg's full-sized avatar
:octocat:
while(!(succeed = try()))

Mostafa Asgari mostafa-asg

:octocat:
while(!(succeed = try()))
View GitHub Profile
After downloading the source code:
$ ./configure --enable-optimizations
$ sudo make altinstall
uuid_generate_v4()
Activate it via:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
@mostafa-asg
mostafa-asg / gist:8817c6eb45d7eb029535dfa34a7003ed
Created January 13, 2022 08:24
How many partitions to use for a topic?
The formula for determining the number of partitions per Kafka topic has been pretty well explored over time.
When creating a new topic in your Kafka cluster, you should first think about your desired throughput (t) in MB/sec.
Next, consider the producer throughput that you can achieve on a single partition (p)—this is affected by producer
configurations but generally sits at roughly 10s of MB/sec. Finally, you need to determine the consumer throughput (c)
you will have—this is application-dependent so you’ll have to measure it yourself. You should anticipate having at least
max(t/p, t/c) partitions for that topic. So if you have a throughput requirement of 250 MB/sec, with a producer and
consumer throughput of 50 MB/sec and 25 MB/sec respectively.
Then you should use at least max(250/50, 250/25) = max(5, 10) = 10 partitions for that topic.
https://www.confluent.io/blog/5-common-pitfalls-when-using-apache-kafka/
@mostafa-asg
mostafa-asg / With React Router
Created May 15, 2021 11:23
Dockerizing a React App
# build environment
FROM node:13.12.0-alpine as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json ./
COPY package-lock.json ./
RUN npm ci --silent
RUN npm install react-scripts@3.4.1 -g --silent
COPY . ./
RUN npm run build
A readiness probe allows Kubernetes to poll the pod and not consider it ready to receive requests until the application indicates it is ready.
```YAML
readinessProbe: # if readiness probe fails, is taken out of your loadbalancer
initialDelaySeconds: 15 #adjust this to be a little less than the time it normally takes for your application to startup
httpGet:
path: /internal/health
port: 8080
timeoutSeconds: 3
```
@mostafa-asg
mostafa-asg / docker-compose.yml
Created April 10, 2021 08:37
Confluent kafka via docker compose
version: '2'
services:
zookeeper:
image: confluentinc/cp-zookeeper:6.0.0
hostname: zookeeper
container_name: zookeeper
ports:
- "2181:2181"
environment:
@mostafa-asg
mostafa-asg / kafka-server-start.sh
Last active February 22, 2021 07:48
Kafka Prometheous JMX exporter config
export KAFKA_OPTS="-javaagent:{PATH}/jmx_prometheus_javaagent-0.14.0.jar=9090:{PATH}/prom-jmx-agent-config.yml"
@mostafa-asg
mostafa-asg / Kafka JMX metrics to Prometheus
Last active December 1, 2020 11:39
Kafka JMX metrics to Prometheus
export KAFKA_OPTS="-javaagent:./jmx_prometheus_javaagent-0.14.0.jar=9090:./prom-jmx-agent-config.yml"
Download jmx_prometheus_javaagent-0.14.0.jar from https://github.com/prometheus/jmx_exporter.
@mostafa-asg
mostafa-asg / gist:2dff5a934ea6d1329717fd18cd6ff9a5
Created October 21, 2020 18:39
Add postgres user to the new database
sudo -u postgres psql postgres
CREATE DATABASE {db_name}
\password postgres (OPTIONAL)
GRANT ALL PRIVILEGES ON DATABASE {db_name} to postgres;
@mostafa-asg
mostafa-asg / install-docker.md
Created May 9, 2020 17:21 — forked from npearce/install-docker.md
Amazon Linux 2 - install docker & docker-compose using 'sudo amazon-linux-extras' command

UPDATE (March 2020, thanks @ic): I don't know the exact AMI version but yum install docker now works on the latest Amazon Linux 2. The instructions below may still be relevant depending on the vintage AMI you are using.

Amazon changed the install in Linux 2. One no-longer using 'yum' See: https://aws.amazon.com/amazon-linux-2/release-notes/

Docker CE Install

sudo amazon-linux-extras install docker
sudo service docker start