chrisstpierre
Time Sensitive Functionality in Elixir
I need to understand more clearly how the runtime & scheduler works in regards to time sensitive functionality.
-
I would like to measure the response time of an HTTP Request to an external server. I want this measurement to be the exact time it took for the external server to respond. I can record the time it takes for the function to finish, but if the CPU is busy, etc this might not be the true response time. What is the best way to do this and why?
-
I want to run repeat cron-like tasks on a timer. How confident can I be that the task will run at the exact given time? If I overload it - say by scheduling 10,000 tasks at the same time - what will happen? Will they be scheduled in order? And can I retrieve the actual execution time?
In general I am still trying to understand when Asynchronous code should be a Process / Stream / GenServer / Task / Agent, and any guidance / resources here would be great!
This is a Phoenix project.
Thanks!
First Post!
hubertlepicki
Looks like you don’t want to overload your server then. You can limit the concurrency with something like GenStage, custom dynamic task supervisor or Poolboy. If you do overload your server, you not only get the wrong measurements, but your whole system will be, well, overloaded, slow and less responsive.
Having said that, Elixir/Phoenix does scale well when it comes to handling many concurrent I/O tasks like making HTTP requests. So it might simply not get overloaded. But if it does, limiting concurrency would be my first task to look at.








