Skip to content

Instantly share code, notes, and snippets.

View kvakvs's full-sized avatar

Dmytro Lytovchenko kvakvs

View GitHub Profile
%%% @doc Calling start() on the socket problem will create a socket client
%%% which will create 100 connections to an echo server (in separate file) and
%%% load them in an uneven random manner.
%%% Find the most busy one.
-module(socket_problem).
%% API
-export([start/0]).
-define(CONNECT_PORT, 11111).
%%% @doc Calling start() will create an echo socket server which will do nothing
%%% but echo the incoming data till it disconnects.
%%% See socket_problem.erl for the problem description.
-module(socket_problem_server).
-export([start/0, server/1, handle_messages/1]).
-define(LISTEN_PORT, 11111).
start() ->
%%%-------------------------------------------------------------------
%%% @copyright (C) 2020, Erlang Solutions Ltd.
%%% @doc Create a long running process which consumes CPU periodically
%%% @end
%%%-------------------------------------------------------------------
-module(problem_cpu).
%% API
-export([start/0]).
defmodule BeamWorkshop do
def start() do
spawn(&process_loop/0)
end
def process_loop() do
big_data =
for _ <- 1..1024 do
big_data(1_048_576)
end
%%%-------------------------------------------------------------------
%%% @copyright (C) 2020, Erlang Solutions Ltd.
%%% @doc Create a long running process which consumes 1 GB of memory
%%% @end
%%%-------------------------------------------------------------------
-module(problem_mem).
%% API
-export([start/0]).
int a;
abstract class PMItem { public bool Match(value) {return false;} }
class PMVar: extends PMItem { public Integer p; public bool Match() { // assign value to p; return true } }
class PM_: extends PMItem { public bool Match(_) { return true;}}
class Obj {
public int a;
public String x;
public int zero;
publie float zerof;
}
@kvakvs
kvakvs / otp13722.erl
Created October 7, 2016 09:58
A test module that enables trace and calls a function that traps via apply and call_bif_e
-module(otp13722).
-export([go/0]).
-compile(export_all).
flush() ->
receive X -> io:format("received: ~p~n", [X]), flush()
after 1000 -> ok
end.
tr_apply(M, F, Args) ->
@kvakvs
kvakvs / fptr.erl
Created September 11, 2016 08:50
Figuring out differences between long calls and apply
-module(fptr).
-export([main1/0, main2/0, main3/1, callable/1]).
main1() ->
fun() -> fptr:callable(111) end.
main2() ->
fun() -> erlang:apply(fptr, callable, [111]) end.
main3(M) ->
fun() -> erlang:apply(M, callable, [111]) end.
-module(otp13722).
-export([main/1]).
flush() ->
receive X -> io:format("received: ~p~n", [X]), flush()
after 1000 -> ok
end.
tr1(M, F, Args) ->
dbg:tracer(),