{"id":16372495,"url":"https://github.com/mgwidmann/elixir-process-chain","last_synced_at":"2025-06-16T22:03:51.243Z","repository":{"id":22711277,"uuid":"26055464","full_name":"mgwidmann/elixir-process-chain","owner":"mgwidmann","description":"A small module which illustrates creating large numbers of processes in the Erlang VM","archived":false,"fork":false,"pushed_at":"2014-11-01T16:53:06.000Z","size":116,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-31T17:22:56.276Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mgwidmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-01T16:08:51.000Z","updated_at":"2024-02-09T13:22:53.000Z","dependencies_parsed_at":"2022-08-21T10:00:32.256Z","dependency_job_id":null,"html_url":"https://github.com/mgwidmann/elixir-process-chain","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Felixir-process-chain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Felixir-process-chain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Felixir-process-chain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgwidmann%2Felixir-process-chain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mgwidmann","download_url":"https://codeload.github.com/mgwidmann/elixir-process-chain/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239921877,"owners_count":19718842,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T03:11:34.769Z","updated_at":"2025-02-20T21:52:35.239Z","avatar_url":"https://github.com/mgwidmann.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"Chain\n=====\n\nWill spawn the number of processes asked and have them all pass a single message serially between themselves.\n\n## Running\n\nStart up iex:\n\n    iex -S mix\n\nRun with any given number:\n\n    iex\u003e Chain.run(1000)\n    {7432, \"Result is 1000\"}\n    :ok\n\nThe number which you passed in comes back in a string to prove that your process received the final message.\n\nThe time reported in the first portion of the tuple is in microseconds. This particular result shows creating\n1,000 processes and starting with the first process with 0 as the start value, adding one to the\nnumber received as a message and passing that result to the next process in the chain.\nThat took 7,432 microseconds or **7.4 milliseconds**!\n\n\n## Running a large number of processes (260k+)\n\nThe Erlang VM attempts to protect you from runaway process creation. In a real world scenario, this protects from unnecessarily using up too many resources. To override this behavior, we have to set that number higher. Simply start iex with the following command:\n\n    iex -erl \"+P 10000000\" -S mix\n\n    iex\u003eChain.run(10_000_000)\n    {102169594, \"Result is 10000000\"}\n    :ok\n\n102169594 microseconds is approximately 1.7 minutes.\n\nRunning without iex is approximately the same time:\n\n    $ ELIXIR_ERL_OPTIONS=\"+P 10000000\" mix run -e \"Chain.run(10_000_000)\"\n    {102593788, \"Result is 10000000\"}\n\n\n# Results on My Machine\n\nBelow I show using an .exs extension, Elixir's scripting format. Below are my machine's specs, though I suspect since the logic is all pretty much serial, more cores would not make any effect.\n\n### iMac 2013 3.5GHz Intel Quad Core i7 w/ hyperthreading (8 CPUs) 8 GB RAM\n\n    $ time elixir -r chain.exs -e \"Chain.run(1)\"\n    {3967, \"Result is 1\"}\n    elixir -r chain.exs -e \"Chain.run(1)\"  0.23s user 0.09s system 124% cpu 0.264 total\n\nMost of the above time is loading of the VM, interpreting the .exs file as well as the -e parameter.\nTime result in printout is in microseconds, 3967 is 0.003967 seconds\n\n\n    $ time elixir -r chain.exs -e \"Chain.run(100)\"\n    {4574, \"Result is 100\"}\n    elixir -r chain.exs -e \"Chain.run(100)\"  0.23s user 0.09s system 125% cpu 0.258 total\n\nNearly no time difference and a factor of 100 times increase in work. Time result in printout is in microseconds, 4574 is 0.004574 seconds\n\n\n    $ time elixir -r chain.exs -e \"Chain.run(10_000)\"\n    {79202, \"Result is 10000\"}\n    elixir -r chain.exs -e \"Chain.run(10_000)\"  0.28s user 0.14s system 127% cpu 0.331 total\n\nStill no real time difference. 0.23s vs 0.28s difference is all non-deterministic system load.\nTime result in printout is in microseconds, 79202 is 0.079202 seconds\n\n\n    $ time elixir -r chain.exs -e \"Chain.run(100_000)\"\n    {753390, \"Result is 100000\"}\n    elixir -r chain.exs -e \"Chain.run(100_000)\"  0.77s user 0.66s system 139% cpu 1.021 total\n\nNow it starts to show some increase in time. Time result in printout is in microseconds, 753390 is 0.75339 seconds\n\n\n    $ time elixir -r chain.exs -e \"Chain.run(250_000)\"\n    {1887977, \"Result is 250000\"}\n    elixir -r chain.exs -e \"Chain.run(250_000)\"  1.66s user 1.55s system 147% cpu 2.166 total\n\nTime result in printout is in microseconds, 1887977 is 1.887977 seconds\n\n\n    $ time elixir -r chain.exs -e \"Chain.run(1_000_000)\" --erl \"+P 1000000\"\n    {6166674, \"Result is 1000000\"}\n    elixir -r chain.exs -e \"Chain.run(1_000_000)\" --erl \"+P 1000000\"  4.29s user 3.90s system 126% cpu 6.456 total\n\nA little more than 6 seconds to boot up one million processes.\nTime result in printout is in microseconds, 6166674 is 6.16667 seconds.\n\n    $ time elixir -r chain.exs -e \"Chain.run(10_000_000)\" --erl \"+P 10000000\"\n    {105322568, \"Result is 10000000\"}\n    elixir -r chain.exs -e \"Chain.run(10_000_000)\" --erl \"+P 10000000\"  70.69s user 56.61s system 120% cpu 1:45.73 total\n\nStill impressive. In just over 1 minute, the Erlang VM booted up, interpreted our code, spawned **10,000,000** processes, passed a message to each process **serially** and exited.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgwidmann%2Felixir-process-chain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmgwidmann%2Felixir-process-chain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgwidmann%2Felixir-process-chain/lists"}