Skip to content

Commit

Permalink
perf: bandit adaptor (#2204)
Browse files Browse the repository at this point in the history
* perf: addition of bandit

* perf: remove bandit customizations

* perf: add in bandit transport options
  • Loading branch information
Ziinc authored Oct 18, 2024
1 parent 6e728c0 commit ef021e8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 38 deletions.
17 changes: 17 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ config :logflare, Logflare.Source.BigQuery.Schema, updates_per_minute: 6

# Configures the endpoint
config :logflare, LogflareWeb.Endpoint,
adapter: Bandit.PhoenixAdapter,
http: [
thousand_island_options: [
# https://cloud.google.com/load-balancing/docs/https/#timeouts_and_retries
# preserves idle keepalive connections up to load balancer max of 600s
read_timeout: 600_000,
# transport options are passed wholly to :gen_tcp
# https://github.com/mtrudel/thousand_island/blob/ae733332892b1bb2482a9cf4e97de03411fba2ad/lib/thousand_island/transports/tcp.ex#L61
transport_options: [
# https://www.erlang.org/doc/man/inet
# both reuseport and reuseport_lb should be provided for linux
reuseport: true,
reuseport_lb: true
#
]
]
],
url: [host: "localhost", scheme: "http", port: 4000],
secret_key_base: "DSzZYeAgGaXlfRXPQqMOPiA8hJOYSImhnR2lO8lREOE2vWDmkGn1XWHxoCZoASlP",
render_errors: [view: LogflareWeb.ErrorView, accepts: ~w(html json)],
Expand Down
9 changes: 1 addition & 8 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ config :logflare,
config :logflare, LogflareWeb.Endpoint,
server: true,
http: [
port: System.get_env("PORT") || 4000,
transport_options: [
max_connections: 16_384,
num_acceptors: 100,
socket_opts: [{:raw, 0xFFFF, 0x0200, <<1::32-native>>}]
],
protocol_options: [max_keepalive: 1_000],
compress: true
port: System.get_env("PORT") || 4000
],
live_view: [
signing_salt: "eVpFFmpN+OHPrilThexLilWnF+a8zBLbCtdH/OzAayShcm1B3OHOyGiadM6qOezp"
Expand Down
19 changes: 1 addition & 18 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,7 @@ config :logflare, env: :prod

config :logflare, LogflareWeb.Endpoint,
http: [
port: 4000,
transport_options: [
max_connections: 64_000,
num_acceptors: 1_000,
# for so_reuseport
socket_opts: [{:raw, 1, 15, <<1::32-native>>}]
],
# https://blog.percy.io/tuning-nginx-behind-google-cloud-platform-http-s-load-balancer-305982ddb340
# https://github.com/ninenines/cowboy/issues/1286#issuecomment-699643478
protocol_options: [
# https://ninenines.eu/docs/en/cowboy/2.8/manual/cowboy_http/
request_timeout: 30_000,
# https://cloud.google.com/load-balancing/docs/https/#timeouts_and_retries
# must be greater than 600s
idle_timeout: 650_000,
max_keepalive: :infinity
],
compress: true
port: 4000
],
cache_static_manifest: "priv/static/cache_manifest.json",
server: true,
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ defmodule Logflare.Mixfile do
defp deps do
[
# Phoenix stuff
{:phoenix, "~> 1.7"},
{:phoenix, "~> 1.7.14"},
{:phoenix_live_view, "~> 0.18"},
{:phoenix_view, "~> 2.0"},
{:phoenix_pubsub, "~> 2.1"},
{:phoenix_ecto, "~> 4.4"},
{:phoenix_live_reload, "~> 1.4", only: :dev},
{:bandit, ">= 0.7.7"},
{:bandit, "~> 1.5.7"},
{:plug_crypto, "~> 1.2.2"},
{:cors_plug, "~> 2.0"},
{:plug_caisson, "~> 0.2.1"},
Expand Down
Loading

0 comments on commit ef021e8

Please sign in to comment.