pedromvieira
FLOW - How to Enhance performance from a series of flows?
I’m migrating some functions from parallel_stream to flow.
This function loads a xlsx file and generate data to import.
The ideia is to increase performance overall. So far so good, specially with files over 50k lines.
In some tests, went from 106 seconds (parallel_stream) to 62 seconds (flow).
Any tips to increase performance or do it in a few flows?
flow pipeline
def flow_it(path, header, accepted, id) do
final_header =
header_filter(header, accepted)
final_id =
id
|> String.to_integer()
{_status, _header, lines} =
path
|> Sheet.load_all()
lines
|> flow_1(final_header)
|> flow_2()
|> flow_3(final_id)
end
reduce
def flow_1(enum, final_header) do
enum
|> Flow.from_enumerable()
|> Flow.partition()
|> Flow.reduce(fn -> [] end, fn {_x, y}, acc ->
temp =
final_header
|> Enum.reduce(%{}, fn {a, b}, acc ->
%{
b => y |> Map.get(a)
}
|> Map.merge(acc)
end)
[temp]
|> Enum.concat(acc)
end)
|> Enum.to_list()
end
only unique rows
def flow_2(enum) do
enum
|> Flow.from_enumerable()
|> Flow.partition()
|> Flow.uniq_by(fn x ->
x["email"]
end)
|> Enum.to_list()
end
some cleaning and calculation
def flow_3(enum, final_id) do
enum
|> Flow.from_enumerable()
|> Flow.partition()
|> Flow.reduce(fn -> [] end, fn x, acc ->
check_email =
x["email"]
|> email_fix()
temp =
case is_nil(check_email) do
true ->
nil
false ->
data =
x
|> Map.pop("email")
|> elem(1)
domain =
check_email
|> domain_from_email()
final_data =
data
|> Map.merge(%{"domain" => domain})
|> Sheet.attrs_validation(["country", "phone"])
%{
email: check_email,
enabled: true,
list_id: final_id,
data: final_data
}
end
[temp]
|> Enum.concat(acc)
end)
|> Enum.to_list()
end
Most Liked
david_ex
Check this out: http://teamon.eu/2016/tuning-elixir-genstage-flow-pipeline-processing/
The graph stuff he explains here http://teamon.eu/2016/measuring-visualizing-genstage-flow-with-gnuplot/ could help you visualize and tweak your setup (number of stages, demand size, etc.).
1
Popular in Questions
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
Student & New to elixir. Nice language.
I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
I have a list say
x = ["23gh", "56kh", "97mh"]
I would like to pass each element to Val in each iteration.
Say, in iteration 1 -------...
New
Hi all
I want to have a unix time, from the current time plus 1 hour.
DateTime.now + 1 hour
How to get it in elixir?
Thanks
New
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Other popular topics
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New







