scottmessinger

scottmessinger

How to troubleshoot increased memory usage in Bandit?

We just put it into production (Bandit 1.2.2) and are also seeing increased memory usage (about 50% more). We upgraded several libraries, so I don’t want to definitively say it was from Bandit, but it does seem likely.

Side note: I think it’s incredibly impressive for mtrudel to build the whole thing and have it be drop in compatible. Very cool library. That said, we might switch back to cowboy if we can’t resolve the memory issue.

Most Liked

jjcarstens

jjcarstens

Nerves Core Team

We put this in NervesHub and were having issues with websockets in our setup at scale which unlimitedly led to reverting to cowboy (Big lengthy breakdown in that PR as well)

However, just today we found one of the default options in ThousandIsland was to set linger: {true, 30} which would hold sockets and increase memory load. That was fixed today in :thousand_island 1.3.3, we deployed and it was all fixed! :tada: It would be worth updating that to see if you still have issues

Also, we set thousand_island: [transport_ports: [hibernate_after: 15_000]] in the endpoint which dropped the memory usage significantly as well.

14
Post #2
mtrudel

mtrudel

Creator of Bandit

@scottmessinger and others; 1.3.0 just went out with a fix for the long-standing issue of increasing memory use (which wasn’t really a memory issue so much as it was an issue with how memory use is reported, but anyway), along with a few other fixes. See CHANGELOG as always. Hopefully this fixes your issue; please report back if so as I’d love to have more evidence that we’ve finally licked this.

mtrudel

mtrudel

Creator of Bandit

A couple of things that would greatly help:

  • Would you be able to disable websocket compression in Bandit and see if that helps? The relevant option is
config MyAppWeb,
   http: [
     ...
     websocket_options: [compress: false]
   ]
  • If you have console access to your server, running the following would provide a snapshot of a random process’ state; helpful in seeing where you may be using all that memory:
{:ok, pid} = Bandit.PhoenixAdapter.bandit_pid(YourAppWeb.Endpoint)
{:ok, connection_pids} = ThousandIsland.connection_pids(pid)
# You may need to turn the following a few times until you get one back that has `handler_module: Bandit.WebSocket.Handler` listed in its state
:sys.get_state(Enum.random(connection_pids)) 

This will be a raw dump of everything your socket process has in state; feel free to redact as needed (you’ll probably want to elide the whole elem(1).connection.websock_state; that’s all of your Phoenix state and should be identical between Bandit and Cowboy). Also, if you want to DM me here to further limit any exposure, that’s fine too.

Looking forward to hunting this down!

mtrudel

mtrudel

Creator of Bandit

I’d suspect it’s the same issue that @jjcarstens et al saw last week, and which is fixed in Thousand Island 1.3.3+. If you’re able, give Bandit a spin with Thousand Island bumped appropriately and see if it fixes your issue; I’d love to get as many data points as possible for perf issues like this!

mtrudel

mtrudel

Creator of Bandit

I think we’ve got a fix.

Anyone able to try the branch referenced here, I’d love to see more evidence that this resolves the issue. The main wrinkle in this solution is that GCing every request is using a sledgehammer on a nail; I’m hoping that I’ll be able to pull the mitigation back to something more reasonable

Where Next?

Popular in Questions Top

pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New

Other popular topics Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement