Skip to content

Instantly share code, notes, and snippets.

View VarunVats9's full-sized avatar
🏠
Working from home

VarunVats9

🏠
Working from home
View GitHub Profile
@VarunVats9
VarunVats9 / latency.markdown
Created July 12, 2023 02:29 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@VarunVats9
VarunVats9 / es-7.json
Last active February 29, 2020 19:15
Elasticsearch - filter, _source, yml
// Filter
GET /bank/_search >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
{
"query": {
"bool": {
"must": [
{
"match": {
"lastname": "Smith"
}
@VarunVats9
VarunVats9 / es-6.json
Last active February 29, 2020 18:40
Elasticsearch - parent-child inner hits, multi level relations
// Inner hits, has_child query
GET /department/_search >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
{
"query": {
"has_child": {
"type": "employee",
"inner_hits": {},
"query": {
"bool": {
"must": [
@VarunVats9
VarunVats9 / es-5.json
Created February 29, 2020 18:18
Elasticsearch - nested objects, nested inner hits
// Mapping
PUT /departments >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
{
"mappings": {
"properties": {
"name": {
"type": "text"
},
"employees": {
"type": "nested"
@VarunVats9
VarunVats9 / es-4.json
Last active February 29, 2020 17:44
Elasticsearch - join queries, has_parent, has_child
// Mapping
PUT /department >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
{
"mappings": {
"properties": {
"join_field": {
"type": "join",
"relations": {
"department": "employee"
}
@VarunVats9
VarunVats9 / es-api.json
Created February 26, 2020 18:00
Elasticsearch - mapping, index, get, update, delete, bulk, multiple action, search, search boolean
// Elasticsearch API
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs.html
// Typeless API
https://www.elastic.co/blog/moving-from-types-to-typeless-apis-in-elasticsearch-7-0
// Mapping >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
PUT /product
{
"mappings": {
@VarunVats9
VarunVats9 / es-3.json
Created February 26, 2020 17:57
Elasticsearch - must, and, should, must_not, filter, query
// MATCH == SHOULD
GET /product/_search >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
{
"query": {
"match": {
"name": "Spring Title"
}
}
}
@VarunVats9
VarunVats9 / es-2.json
Created February 26, 2020 14:45
Elasticsearch - date, operator, match_phrase, multiple fields
// Add another field
PUT /product/_mapping >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
{
"properties": {
"date": {
"type": "date",
"format": "yyyy-MM-dd"
}
}
}
@VarunVats9
VarunVats9 / es-1.json
Last active May 29, 2020 14:09
Elasticsearch - term, range, prefix, wildcard, regex
// Term queries don't analyze the query, just search for the exact term in the inverted index >>>>>>>>>
"query": {
"term": {
"name": "Framework"
}
}
}
GET /product/_search
{
Reference:
https://opensourceconnections.com/blog/2013/07/24/understanding-how-cql3-maps-to-cassandras-internal-data-structure-sets-lists-and-maps/
// Column-Family
-----------------------------------------------------------------------------------------------
ID Last First Bonus
1 Doe John 8000
2 Smith Jane 4000
3 Beck Sam 1000