sasa1977 / elixir-in-action Goto Github PK
View Code? Open in Web Editor NEWCode samples for Elixir in Action book
Code samples for Elixir in Action book
Why not directly use Todo.Supervisor
?
readme says your on 1.2 but code has been updated for 1.3
:protected
is not necessary because it is the default. Also, the book says in chapter 10:
Finally, you opt for protected access because you’ll synchronize cache writes in the cache process. This means only client process must be able to write to the table, but all processes must have read access.
Shouldn't it go,
This means only the cache process must be able to write to the table, but all processes out have read access?
Erlang/OTP 22 [erts-10.5.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1]
In this elixir version does not work.
Try to start two nodes in my macbook, by the following steps:
node1 : iex --sname node1@localhost -S mix
node2: iex --erl "-todo port 5555" --sname node2@localhost -S mix
in other terminal test add entries:
curl -d "" "http://localhost:5454/add_entry?list=bob&date=2018-12-19&title=Movies"
curl "http://localhost:5555/entries?list=bob&date=2018-12-19"
the curl command return empty, and the local folder in node2 is empty too.
If a client calls one of the interface functions after starting the server, but the server has not registered its alias, the client will get an error.
I wanted to congratulate Sasa for the great book.
I just loved It!
:erlang.phash() already puts the number between 1..n, no need to add one.
There is a typo in the code for handling :DOWN
after Listing 9.2.
def handle_info({:DOWN, _, :process, pid, _}, process_registry) do
{:noreply, deregister_pid(new_registry, pid)} #<- new_registry should be process_registry here
end
The code in this repo is correct:
https://github.com/sasa1977/elixir-in-action/blob/master/code_samples/ch09/pool_supervision/lib/todo/process_registry.ex#L55
Thank you very much for writing such a great book!
In page 61, when discussing the use of Mix, there is the sentence
"Starts the system; terminates as soon as MyProject.start finishes"
but "MyProject.start" was not introduced before.
Perhaps the introduction of Mix should be deferred until OTP applications are discussed to make the use of Mix more clear to the reader.
Hi,
the benchmark in elixir_in_action_code_samples/ch10/profile_cache is returning the following results
$ iex -S mix
Erlang/OTP 20 [erts-9.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.5.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Profiler.run(PageCache, 100000)
304625 reqs/sec
:ok
iex(2)> Profiler.run(PageCache, 100000, 100)
528910 reqs/sec
:ok
iex(3)>
Here are some more data:
iex(9)> Profiler.run(PageCache, 100000, 2)
305392 reqs/sec
:ok
iex(10)> Profiler.run(PageCache, 100000, 4)
389874 reqs/sec
:ok
iex(11)> Profiler.run(PageCache, 100000, 8)
324331 reqs/sec
:ok
iex(12)> Profiler.run(PageCache, 100000, 16)
360170 reqs/sec
:ok
iex(14)> Profiler.run(PageCache, 100000, 32)
381613 reqs/sec
:ok
iex(15)> Profiler.run(PageCache, 100000, 64)
460793 reqs/sec
:ok
iex(16)> Profiler.run(PageCache, 100000, 128)
534101 reqs/sec
:ok
iex(17)> Profiler.run(PageCache, 100000, 256)
543486 reqs/sec
:ok
iex(18)>
These are strange as instead of decreasing as in the book, the throughput is increasing?!
What am I doing wrong here?
I am with a Macbook Pro, 2.6 GHz Intel Core i5, 16 GB 1600 MHz DDR3, macOS Sierra 10.12.6, Erlang 20.2 and Elixir 1.5.2.
I had to change the code of the example to use Map instead of HashDict and to depend on Elixir 1.5.2 in mix.exs.
Thanks
I've been going through the book today and used this repo quite a lot. One thing that is annoying is that when you run iex -S mix
I get an error because the mix files say elixir: "~> 1.0.0"
.
I can take care of this in a PR if you want :-)
Again, this is a synthesis of techniques you’ve seen previously. You send a message and wait for the response. In the corresponding process_message/2
clause, you delegate to TodoList
, and then you send the response and return the unchanged to-do list. This is needed because loop/2
takes the result of process_message/2
as the new state.
In the above paragraph, loop/2
should be replaced with loop/1
as there is no loop function in this module with an arity of 2.
Hi, First of all, thank you for an amazing book. I'm pretty into it.
I have a problem regarding chapter - working with components.
In section 11.2.3 - Visualizing the system, I have run the :observer.start()
command, but the window doesn't appear (it actually flashes out).
The terminal fulls of huge cpp errors, like
/src/common/object.cpp(251): assert "classTable->Get(m_className) == NULL" failed in Register(): Class "wxMouseCaptureLostEvent" already in RTTI table - have you used IMPLEMENT_DYNAMIC_CLASS() multiple times or linked some object file twice)?
I am using macOS Big Sur and install elixir through brew
.
Is there anything I need to install to make it works?
Thank you.
Dear Saša,
I was going through the GenServer implementation of SimpleRegistry and am puzzled by this line in your example.
This registers the same SimpleRegistry's process's pid for any given key.
I think the intention was to create a new linked Process, something like
{:ok, pid} = Agent.start_link(fn -> %{} end)
and register it in the parent SimpleRegistry.
Am I missing anything?
Thanks,
Oda
Hi,
I'm working my way through your book - it's been great so far. Thanks.
I have reached chapter 2, page 28 where it is written that:
You can set the defaults for any combination of arguments:
defmodule MyModule do
def fun(a, b \\ 1, c, d \\ 2) do
a+b+c+d
end
end
Always keep in mind that default values generate multiple functions of the same name
with different arities. So the previous code generates three functions: MyModule.fun/2,
MyModule.fun/3, and MyModule.fun/4.
It is clear to me how the /2 and /4 arity functions would be generated. But there are two options for the /3 arity function - how does it generate one function which satisfies both conditions?
In Chapter 09, section 9.1, the following code on iex
Todo.System.start_link
Process.exit(Process.whereis(Todo.ProcessRegistry),:kill)
causes the Supervisor to crash(after trying to restart the children). Trying to inspect the result of Registry.start_link
, it shows
{:error,
{:shutdown,
{:failed_to_start_child, Todo.ProcessRegistry.PIDPartition0,
{:already_started, #PID<0.183.0>}}}}
Am guessing that this happens because the supervisor is starting ProcessRegistry
in succession before the actual Registry
is shutdown and keeps erroring 3 times, ending up in shutdown.
Is that correct?
How to handle this scenario gracefully?
The Book's Reference is: "https://erlang.org/doc/man/ets.html"
The new Link to the ETS Reference in the Erlang Manual is: "https://www.erlang.org/doc/apps/stdlib/ets"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.