I copied the following code from the inets User's Guide:
$ erl
Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V8.2 (abort with ^G)
1> inets:start().
ok
2> httpc:set_options([{proxy, {{"www-proxy.mycompany.com", 8000}, ["localhost"]}}]).
ok
3> {ok, {{Version, 200, ReasonPhrase}, Headers, Body}} = httpc:request("http://www.erlang.org").
* exception error: no match of right hand side value
{error,
{failed_connect,
[{to_address,{"www-proxy.mycompany.com",8000}},
{inet,[inet],etimedout}]}}
I need advice on how to get that request to complete successfully.
This seems to work:
$ erl
Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V8.2 (abort with ^G)
1> inets:start().
ok
2> {ok, {{Version, 200, ReasonPhrase}, Headers, Body}} = httpc:request("http://www.erlang.org").
{ok,{{"HTTP/1.1",200,"OK"},
[{"connection","keep-alive"},
{"date","Sun, 25 Feb 2018 13:44:59 GMT"},
{"server","nginx"},
{"vary","Accept-Encoding"},
{"content-length","12816"},
{"content-type","text/html; charset=UTF-8"}],
"<!DOCTYPE html>\n<html>\n <head>\n <title>Erlang Programming Language</title>\n <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\n <meta name=\"description\" content=\"Erlang Programming Language\"/>\n <meta name=\"keywords\" content=\"erlang, functional, programming, fault-tolerant, distributed, multi-platform, portable, software, multi-core, smp, concurrency\"/>\n
The User's Guide says:
The following calls use the default client profile. Use the proxy
"www-proxy.mycompany.com:8000", except from requests to localhost.
This applies to all the following requests.
which makes as much sense to me as:
Maecenas in tincidunt diam. Pellentesque in orci sed dolor vulputate
tincidunt. Etiam malesuada finibus nisi. Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
To stop the client, do I just do:
inets:stop()
?
Edit: I must have figured out how to stop the server because I did it in this code:
Erlang read post request
Related
What is the syntax for the configuration file when you start an httpd server like this:
inets:start(httpd,
[{proplist_file, "./server_config.txt"}]
).
The httpd docs say:
{proplist_file, path()}
If this property is defined, Inets expects to find all other
properties defined in this file.
And:
the properties are to be fetched from a configuration file that can
consist of a regular Erlang property list
But with this file:
server_config.txt:
[
{port, 0},
{server_name, "httpd_test"},
{server_root, "/Users/7stud/erlang_programs/inets_proj"},
{document_root, "/Users/7stud/erlang_programs/inets_proj/htdocs"},
{ipfamily, inet6},
{ bind_address, {0,0,0,0,0,0,0,1} }
]
I get the error:
$ erl
Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V8.2 (abort with ^G)
1> inets:start().
ok
2> inets:start(httpd, [{proplist_file, "/Users/7stud/erlang_programs/inets_proj/server_config.txt"}]).
** exception error: no try clause matching {error,{8,erl_parse,["syntax error before: ",[]]}}
in function httpd_sup:httpd_config/1 (httpd_sup.erl, line 144)
in call from httpd_sup:start_child/1 (httpd_sup.erl, line 52)
in call from inets:call_service/3 (inets.erl, line 461)
Next, I tried the Apache syntax, and that didn't work either:
server_config.txt:
Port 0
ServerName "httpd_test"
ServerRoot "/Users/7stud/erlang_programs/inets_proj"
DocumentRoot "./htdocs"
Ipfamily inet6
BindAddress {0,0,0,0,0,0,0,1}
3> inets:start(httpd, [{file, "./server_config.txt"}]).
{error,"httpd_conf: \"/Users/7stud/erlang_programs/inets_proj\" is an invalid ServerRoot"}
4>
Okay, I made some progress on the Apache style syntax by getting rid of the quotes:
Port 0
ServerName httpd_test
ServerRoot /Users/7stud/erlang_programs/inets_proj
DocumentRoot ./htdocs
Ipfamily inet6
BindAddress 0:0:0:0:0:0:0:1
Now, I get the error:
8> inets:start(httpd, [{file, "./server_config.txt"}]).
{error,"httpd_conf: 0:0:0:0:0:0:0:1 is an invalid address"}
I figured out the proplist syntax. I shortened up the paths once I got the proplist syntax to work:
server_config.txt:
[
{port, 0},
{server_name, "httpd_test"},
{server_root, "."},
{document_root, "./htdocs"},
{ipfamily, inet6},
{ bind_address, {0,0,0,0,0,0,0,1} }
].
Notice the . at the end! The syntax is so obvious no wonder the docs don't give an example. :(
$ erl
Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V8.2 (abort with ^G)
1> inets:start().
ok
2> {ok, Server} = inets:start(httpd, [{proplist_file, "./server_config.txt"}]).
{ok,<0.73.0>}
3> httpd:info(Server).
[{mime_types,[{"htm","text/html"},{"html","text/html"}]},
{ipfamily,inet6},
{server_name,"httpd_test"},
{bind_address,{0,0,0,0,0,0,0,1}},
{server_root,"."},
{port,49400},
{document_root,"./htdocs"}]
I'm still wondering how to specify an ipv6 bind address with the Apache syntax. Maybe ipv6 came after the erlang Apache syntax was implemented?
I followed the tutorial many times and, created a small app using rebar and release it successfully. But when I come to the main application (calendarApp), crash dump was returned. I made some changes but the result is the same. I would like to know what I am doing wrong, and how I can fix this.
At the end, when I do start and attach, it returns "Node is not running!".
I will show you:
sonu#sonu-Ideapad-Z570:~/calendarApp/rel$ ./calendarApp/bin/calendarApp console
Exec: /home/sonu/release/calendarApp/rel/calendarApp/erts-5.10.4/bin/erlexec -boot /home/sonu/release/calendarApp/rel/calendarApp/releases/1/calendarApp -mode embedded -config /home/sonu/release/calendarApp/rel/calendarApp/releases/1/sys.config -args_file /home/sonu/release/calendarApp/rel/calendarApp/releases/1/vm.args -- console
Root: /home/sonu/release/calendarApp/rel/calendarApp
Erlang R16B03 (erts-5.10.4) [source] [smp:4:4] [async-threads:10] [kernel-poll:false]
{global,calendarApp_sup} (<0.216.0>) starting....
{global,calendarApp_server} (<0.217.0>) starting ......
Eshell V5.10.4 (abort with ^G)
(calendarApp#127.0.0.1)1>
=INFO REPORT==== 19-Jan-2016::09:50:45 ===
application: calendarApp
exited: {{shutdown,
{failed_to_start_child,calendarApp_server,
{undef,
[{mnesia,create_schema,
[['calendarApp#127.0.0.1']],
[]},
{calendarApp_db,init,0,
[{file,"src/calendarApp_db.erl"},{line,7}]},
{calendarApp_server,init,1,
[{file,"src/calendarApp_server.erl"},{line,49}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},{line,304}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,239}]}]}}},
{calendarApp_app,start,[normal,[]]}}
type: permanent
{"Kernel pid terminated",application_controller," {application_start_failure,calendarApp,{{shutdown,{failed_to_start_child,calendarApp_server,{undef,[{mnesia,create_schema,[['calendarApp#127.0.0.1']],[]},{calendarApp_db,init,0,[{file,\"src/calendarApp_db.erl\"},{line,7}]},{calendarApp_server,init,1,[{file,\"src/calendarApp_server.erl\"},{line,49}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,304}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,239}]}]}}},{calendarApp_app,start,[normal,[]]}}}"}
Crash dump was written to: erl_crash.dump
Kernel pid terminated (application_controller) ({application_start_failure,calendarApp,{{shutdown,{failed_to_start_child,calendarApp_server,{undef,[{mnesia,create_schema, [['calendarApp#127.0.0.1']],
sonu#sonu-Ideapad-Z570:~/calendarApp/rel$ ./calendarApp/bin/calendarApp console
If anyone knows the problem, please help me to fix this.
I have a 4GB ram in my system and it used 2GB of ram before the insertion completed wen using disc_copies. I was wondering what would happen if 100 percent of the ram was consumed? Is there any option to limit the ram consumed during disc_copies, like limiting the ram usage to 2GB?
If you are looking how to limit erlang VM memory usage you should use control groups for it. But if you like to monitor memory usage you should use memory monitor memsup from os_mon application.
$ erl -boot start_sasl
Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
...
=PROGRESS REPORT==== 22-Oct-2015::22:39:46 ===
application: sasl
started_at: nonode#nohost
Eshell V7.0 (abort with ^G)
1> application:start(os_mon).
...
=PROGRESS REPORT==== 22-Oct-2015::22:40:03 ===
application: os_mon
started_at: nonode#nohost
ok
2>
...
2> memsup:get_memory_data().
{8162500608,6514708480,{<0.7.0>,426616}}
3> memsup:get_system_memory_data().
[{system_total_memory,8162500608},
{free_swap,5996748800},
{total_swap,5997850624},
{cached_memory,3290759168},
{buffered_memory,444370944},
{free_memory,1647222784},
{total_memory,8162500608}]
4>
Read os_mon documentation about usage and alarms.
Using Erlang R16B02, riakc 2.0.0 and meck 0.82:
When trying to mock riakc_pb_socket in my unit tests it blows up. Here's what I get:
> erl -pa ebin deps/*/ebin
Erlang R16B02 (erts-5.10.3) [source-b44b726] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V5.10.3 (abort with ^G)
1> meck:new(riakc_pb_socket).
** exception exit: {compile_forms,{error,[{[],
[{75,erl_lint,{bad_deprecated,{get_index,'_'}}}]}],
[{[],[{75,erl_lint,{undefined_behaviour,[gen_server]}}]}]}}
2>
I found that if I comment this line in riakc_pb_socket.erl and recompile - the problem goes away. Is there a better solution?
-deprecated({get_index,'_', eventually}).
so afterwards....
> erl -pa ebin deps/*/ebin
Erlang R16B02 (erts-5.10.3) [source-b44b726] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V5.10.3 (abort with ^G)
1> meck:new(riakc_pb_socket).
ok
2>
> erl -pa ebin deps/*/ebin
Erlang R16B02 (erts-5.10.3) [source-b44b726] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V5.10.3 (abort with ^G)
1> code:which(riakc_pb_socket).
"deps/riakc/ebin/riakc_pb_socket.beam"
2>
I get this message when launching RabbitMQ:
=WARNING REPORT==== 8-Feb-2014::10:43:42 ===
Only 2048MB of 23482MB memory usable due to limited address space.
Crashes due to memory exhaustion are possible - see
http://www.rabbitmq.com/memory.html#address-space
When I follow that link, I read about how I should be using a 64-bit Erlang VM. But:
ajax:~ maxvitek$ erl
Erlang R16B03 (erts-5.10.4) [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Eshell V5.10.4 (abort with ^G)
1>
...which certainly appears to be a 64-bit build. This is with the vm_memory_high_watermark set to 1. If I can get rid of the memory address problem so that RabbitMQ could use more of the system's memory, I will set that back to 0.4. Any idea where to look to fix this?
Both Erlang and RabbitMQ are installed via Homebrew, running on Mavericks.