rogerweb

rogerweb

Is Application.fetch_env expensive?

Hi,

In terms of performance, is it ok to call Application.fetch_env! in a function that is called every time my Phoenix application receives a new websocket connection?

Should I wrap my function in a GenServer just to keep the value in the state? (I don’t think so but just checking)

Is there any “context” that Phoenix might provide that I could use to store this value and somehow would end up being available to me in the socket structure?

The long story is like this: I have this Phoenix application that accepts websocket connections and I am using Joken to verify a token that comes in the connection request. It’s a JWT generated by another system and signed using RS256 so I need to know the public key for verifying it. When the application starts, my runtime.exs reads the public key from an environment variable and stores it as an application configuration. Then, every time a new websocket connection comes in my verify function in my Token module reads the public key using Application.fetch_env! and verifies the token.

Thanks for any guidance.

Marked As Solved

derek-zhou

derek-zhou

Yes. It is cheap enough. also you don’t want to use stale env if those can be updated by user triggered actions within your application.

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
albydarned
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
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54260 488
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
New
albydarned
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
JorisKok
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

We're in Beta

About us Mission Statement