Skip to content

Latest commit

 

History

History
115 lines (74 loc) · 3.85 KB

CHANGELOG.md

File metadata and controls

115 lines (74 loc) · 3.85 KB

Something like a changelog

As soon as the infrastructure was up and running, I started working on the application. This is what happened.

1 - mount function

Diff:

I added a call to the increase_counter function to the mount function of the liveview.

Problems:

  • Only seems to work when client makes use of JavaScript (wrk benchmark didn't increase the number) <- not so sure about that.
  • Misses requests if you reload fast enough

2 - custom plug

Diff:

I moved the function call from the mount function to a custom Plug.

Now we don't miss a request but it is very slow. wrk measured about 1,5 requests per second.

Problems:

  • Request is blocked by mnesia transaction
  • Very slow (~1,5 requests per second)

3 - genserver

Diff:

I created a singleton GenServer to call the increase_counter function. The custom plug is now only used to call the client API of the GenServer.

The requests are not blocked anymore, but the time until all the messages are processed takes around (you might have guessed it already) 1,5 seconds per update.

6k requests of the wrk benchmark took about 1,5*6000 seconds to complete.

Problems:

  • Very slow update processing

4 - sum up before update

Diff:

I added a dedicated state and a scheduled update to the GenServer. The state takes care of all the incoming messages and sums them up per node. The scheduled update only runs once per second and then adds the sum of the state to the sum which is already in the database.

Instead of two transactions per request we now have eight transactions every second (number of nodes times two).

One for each node to get the current state and one for each node to update the number in the database.

Problem:

  • rather slow because of the amount of transactions

5 - reduce complexity (reverted)

Diff:

Instead of multiple transactions, make use of a single :ets.update_counter.

Problem:

  • :ets.update_counter is not a transaction and is only available on the node it was run on. All other nodes do not receive the update.

6 - reduce amount of transactions

Diff:

ChatGPT taught me something obvious: I can do more than just call :mnesia.(read|write) in a transaction. m( Instead of two transactions I reduced it to one.

Problem:

  • We still create one transaction per node

7 - refactor mnesiac store init

Diff

Whenever a node restarted (for whatever reason) it re-initialized the store which set every record to zero. This is now fixed and the counter just keeps on growing.

Not even a deployment should reset the counter now. I think.

Problem:

  • Too many transactions (one per node) which update the counter too slow

8 - show active users

Diff

Phoenix Presence is now part of the application. It shows the current amount of active users on each node.

Next

The next iteration should reduce the amount of transactions to one.