Commit f1ef4910 authored by KT315's avatar KT315

Elixir dummy with fast stream

parent c6fff78d
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
# The directory Mix will write compiled artifacts to.
/_build/
# If you run "mix test --cover", coverage assets end up here.
/cover/
# The directory Mix downloads your dependencies sources to.
/deps/
# Where 3rd-party dependencies like ExDoc output generated docs.
/doc/
# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch
# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump
# Also ignore archive artifacts (built via "mix archive.build").
*.ez
# Ignore package tarball (built via "mix hex.build").
elixir_dummy-*.tar
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
defmodule Dummy do
@moduledoc false
@behaviour :cowboy_stream
@body "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis dictum ligula, ut sagittis nisl malesuada nec. Fusce hendrerit leo augue, nec pretium dolor porta sodales. Sed consequat sed purus eu aliquet. Etiam laoreet nibh vel ex sodales, non egestas lorem tempor. Pellentesque placerat facilisis felis, nec bibendum metus finibus quis. Donec lobortis, sapien at tristique placerat, nibh libero volutpat eros, eget mollis nibh elit et enim. Vestibulum consequat ut lorem sed eleifend. Ut eu dolor ut lectus faucibus rhoncus. Nam vestibulum vitae massa vel congue. Nam ac odio lacus. Nam condimentum ante eget mollis vestibulum. Cras nisi sapien, tempor nec diam at, vulputate cursus odio. Maecenas vitae tellus efficitur arcu mollis ultrices id vitae ex. Suspendisse potenti. Duis nec vestibulum dui. Donec ultricies sit amet lorem eu feugiat. Ut pretium vitae lectus at tempor. Curabitur condimentum arcu varius nulla ultricies, id feugiat odio dictum. Vivamus sollicitudin consectetur nullam."
def init(_stream_id, req, opts) do
env = Map.get(opts, :env, %{})
{:ok, req, %{handler: DummyHandler}} = :cowboy_router.execute(req, env)
Process.sleep(trunc(100 + (5 - :rand.uniform() * 10)))
{[
{:response, 200, :cowboy_req.response_headers(%{"content-type" => "text/plain", "content-length" => Integer.to_string(byte_size(@body))}, req),
@body},
:stop
], :undefined}
end
def data(stream_id, is_fin, data, next) do
:cowboy_stream.data(stream_id, is_fin, data, next)
end
def info(stream_id, info, next) do
:cowboy_stream.info(stream_id, info, next)
end
def terminate(stream_id, reason, next) do
:cowboy_stream.terminate(stream_id, reason, next)
end
def early_error(stream_id, reason, partial_req, resp, opts) do
:cowboy_stream.early_error(stream_id, reason, partial_req, resp, opts)
end
end
defmodule Dummy.Application do
@moduledoc false
use Application
def start(_type, _args) do
dispatch =
:cowboy_router.compile([
{:_,
[
{"/", DummyHandler, %{}}
]}
])
children = [
%{
id: :dummy,
start:
{:cowboy, :start_clear,
[
:dummy,
%{num_acceptors: 10, max_connections: 999_999, socket_opts: [port: 5000]},
%{max_keepalive: 1_000, env: %{dispatch: dispatch}, stream_handlers: [Dummy]}
]},
restart: :permanent,
shutdown: :infinity,
type: :supervisor
}
]
opts = [strategy: :one_for_one, name: Dummy.Supervisor]
Supervisor.start_link(children, opts)
end
end
defmodule Dummy.MixProject do
use Mix.Project
def project do
[
app: :elixir_dummy,
version: "0.1.0",
elixir: "~> 1.9",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
def application do
[
extra_applications: [:logger],
mod: {Dummy.Application, []}
]
end
defp deps do
[
{:cowboy, "~> 2.7.0"}
#{:cowboy, git: "https://github.com/ninenines/cowboy.git", branch: "active_n"}
]
end
end
%{
"cowboy": {:git, "https://github.com/ninenines/cowboy.git", "8241791a3ea19deeaaa5d80252e69a958227a1d8", [branch: "active_n"]},
"cowlib": {:git, "https://github.com/ninenines/cowlib", "c6553f8308a2ca5dcd69d845f0a7d098c40c3363", [ref: "2.8.0"]},
"ranch": {:git, "https://github.com/ninenines/ranch", "3190aef88aea04d6dce8545fe9b4574288903f44", [ref: "1.7.1"]},
}
@echo off
rem Set the release to work across nodes. If using the long name format like
rem the one below (my_app@127.0.0.1), you need to also uncomment the
rem RELEASE_DISTRIBUTION variable below.
rem set RELEASE_DISTRIBUTION=name
rem set RELEASE_NODE=<%= @release.name %>@127.0.0.1
#!/bin/sh
# Sets and enables heart (recommended only in daemon mode)
# case $RELEASE_COMMAND in
# daemon*)
# HEART_COMMAND="$RELEASE_ROOT/bin/$RELEASE_NAME $RELEASE_COMMAND"
# export HEART_COMMAND
# export ELIXIR_ERL_OPTIONS="-heart"
# ;;
# *)
# ;;
# esac
# Set the release to work across nodes. If using the long name format like
# the one below (my_app@127.0.0.1), you need to also uncomment the
# RELEASE_DISTRIBUTION variable below.
# export RELEASE_DISTRIBUTION=name
# export RELEASE_NODE=<%= @release.name %>@127.0.0.1
+P 16777216
+Q 16777216
+K true
+A 64
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment