jeramyRR

jeramyRR

Why does elixir purge logging statements at compile time? I know you have to indicate what level you’d like to purge in the config, but doesn’t this take away the ability to temporarily increase logging in production if something goes wrong?

Showing Posts 1 to 10

NobbZ

NobbZ

Well, calls to logger cost you some cycles.

  1. Calculate the arguments (some use "#{inspect foo}" everywhere, so that has to be done, regardless if it will be logged or not.
  2. We have a remote call into Logger and remote calls are more expensive than local calls.
  3. In the Logging function we have at least if level <= wanted_level which need to be done

All this costs your process valuable reductions, which it can’t spend with its primary task.

Therefore unpurged but filtered logger calls are a bad thing.

But you are right. Usually I do only purge debug, and keep the rest while only actively logging :warn and :error.

jeramyRR

jeramyRR OP

This seems like a serious oversight in the VM design if it can’t handle logging without stripping calls from the bytecode first.

NobbZ

NobbZ

Sorry, but I do not understand this statement.

If it were stripping things, you weren’t able to get them back at runtime, and then we are back at compile time purging.

aseigo

aseigo

It can, and does so just fine. However, when doing the filtering at runtime instead of compiletime, there is some expense still spent in log message that are never shown. So if you want every last bit of performance, you can strip out the debug levels you really don’t want (e.g. debug in production builds).

If you have stripped them, and you want them back in a running system, you can always build an upgrade release and hot-load it to get your debug statements back.

Logger does do as much as it can to help even when not stripped at compile time, though. If you are not showing debug statements, then the Logger.debug macro does not evaluate the parameters (e.g. strings with interpolations) …

aseigo

aseigo

Are you sure about that? From the docs;

 The Logger.info/2 macro emits the provided message at the :info level. Note the arguments given to 
 info/2 will only be evaluated if a message is logged. For instance, if the Logger level is set to :warn, 
 messages are never logged and therefore the arguments given above won’t even be executed.
NobbZ

NobbZ

At least it was like I’ve described it in earlier versions. As far as I remember there has even been the advise to wrap expensive to calculate arguments into an anonymous function, to make it “lazy”. Perhaps I missed the lazy by default change?

aseigo

aseigo

That is still true for Logger.bare_log/3, as noted in the docs, but not the case anymore for the other macros.

jeramyRR

jeramyRR OP

Is this something that could be circumvented by implementing a Logger in Rust and calling it through Elixir if Elixirs native logging performance became inhibitive, or would the call down to native be just as expensive?

aseigo

aseigo

Cycles are cycles. And when you have a million connections being handled by your application, those cycles add up. I’ve seen the same thing with C/C++ code bases, including ones where methods that were slow were improved by conditionally compiling out logging output that was disabled at runtime with configuration.

The fact that you can reclaim those cycles by compiling the calls right out does not equal “calls to Logger are horribly slow”. I honestly don’t know how slow they are (I don’t have numbers on that), but you could always take Benchee and wrap it around a large number of Logger calls which do not hit the backend and find out.

As for the cost of native calls: they are quite cheap: Latency of Native Functions for Erlang and Elixir · potatosalad

sneako

sneako

I’m pretty sure that was a new feature of 1.7. if you look at the docs for 1.6 here Logger – Logger v1.6.0, you’ll find: " The Logger macros also accept messages as strings, but keep in mind that strings are always evaluated regardless of log-level. As such, it is recommended to use a function whenever the message is expensive to compute." As stated by @NobbZ

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 91898 914
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews