blackode

Coding, thoughts, and ideas.

Follow publication

Member-only story

What I Wish Everyone Knew About

Smart Work Distribution across Nodes/Process | Data Partition |Elixir-Erlang

Divide and Conquer the big data

Malreddy Ankanna
blackode
Published in
6 min readDec 1, 2022

--

This article explains the distribution of data across multiple nodes or processes using the built-in Erlang function called phash2/2 in an efficient way.

Preface

I never thought I would write an entire blog on one function. But this function is worth it. I am just waiting for the moment to use this function in one of my projects.

Definition

The following is the definition from the Erlang docs

Portable hash function that gives the same hash for the same Erlang term regardless of machine architecture and ERTS version (the BIF was introduced in ERTS 5.2). The function returns a hash value for Term within the range 0..Range-1. The maximum value for Range is 2³². When without argument Range, a value in the range 0..2²⁷-1 is returned.

Expanding Definition

Simply, it gives the same random integer (here hash) within the range 0 ..Range-1 for the given same term and provided Range.
I know this is still confusing part. That confusion will be no more once after looking at the following examples.

--

--

blackode
blackode
Malreddy Ankanna
Malreddy Ankanna

Written by Malreddy Ankanna

Programmer & Writer, I write about coding, thoughts, ideas, personal musings, technical articles, and tutorials.https://bio.link/blackode

No responses yet