Changes in YAWS takes a while to take effect - erlang

When I modify a .yaws file it take a few (5, 10) seconds for changes to take effect, it it normal and Do I have to keep terminal open while I use YAWS server?

When you modify a .yaws file, Yaws recompiles it to an Erlang .beam file, which contains bytecode for the Erlang virtual machine, and reloads it. This won't be instantaneous of course, but it should not take 5-10 seconds; you should report a Yaws issue in that case, and please include a test case.
As for requiring a terminal, Yaws can run such that it gives you an interactive Erlang shell, or it can be run as a background daemon if you supply the --daemon command-line option. Yaws comes with a number of startup scripts for running it as a daemon on various operating systems.

Related

Running Erlang code and projects in Yaws (ebin_dir)

I'm exploring Yaws and I've read the Yaws manual and the Building Web Applications with Erlang book. I've followed every step in the book's last chapter where a multi_cast app is built, but I can't run it. I believe it's the Erlang code which isn't being found or used.
I've got a project dir in my home directory and I've pointed Yaws docroot for this particular Virtual Server to my project directory where a htdocs dir with the .yaws files reside.
<server localhost>
port = 8001
listen = 127.0.0.1
docroot = <my_path_here>/erlang_yaws/multi_cast
</server>
and I've changed the ebin_dir to also point to the project´s ebin directory:
ebin_dir = <my_path_here>/erlang_yaws/multi_cast/_build/default/lib/multi_cast/ebin
Upon starting Yaws with yaws -i I can go to some simple .yaws files I've got which do not rely on any of the project´s .beam files. However, when I change my browser's location to a .yaws files which rely on the app's compiled files I get the following error:
=ERROR REPORT==== 21-Jan-2017::14:27:17 ===
ERROR erlang code threw an uncaught exception:
File: <my_path_here>/erlang_yaws/multi_cast/htdocs/status.yaws:1
Class: exit
Exception: {noproc,{gen_server,call,[multi_cast_front,{get_etag}]}}
Req: {http_request,'GET',{abs_path,"/htdocs/status.yaws"},{1,1}}
Stack: [{gen_server,call,2,[{file,"gen_server.erl"},{line,204}]},
{m_27449121_1,out,1,
[{file,"<my_path_here>/.yaws/yaws/default/m_27449121_1.erl"},
{line,35}]},
{yaws_server,deliver_dyn_part,8,
[{file,"yaws_server.erl"},{line,2872}]},
{yaws_server,aloop,4,[{file,"yaws_server.erl"},{line,1242}]},
{yaws_server,acceptor0,2,[{file,"yaws_server.erl"},{line,1065}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]
I believe this is due to the fact that my gen_server app isn't starting correctly or not being found? The source code seems to compile successfully.
I'm on MacOS Sierra with Yaws 2.0.4, Erlang 19 and I did a regular Yaws install with homebrew.
Also, is there a resource which thoroughly explains how to structure Yaws and a simple application? Reading both the manual and the book and both fail at explaining this (or I'm really thick), and it's quite frustrating to get stuck from a user experience viewpoint.
You've correctly added your modules to the load path using the ebin_dir configuration variable, but that's not enough to actually start and run your application. The book you're following doesn't address this — see page 101, where it says, "It is also possible to run Yaws as an OTP app inside an existing Erlang setup, but this is beyond the scope of this book."
An easy way to start your server is to use the runmod configuration variable, documented in the yaws_config man page:
runmod = ModuleName At startup Yaws will invoke ModuleName:start() in a separate process. It is possible to have several runmods. This is useful if we want to reuse the Yaws startup shell script for our own application.
Assuming your gen_server provides a start/0 function, set the name of your module as the value of runmod and Yaws will start it. A problem with this approach, though, is that it works fine for experimentation but not for production because there's nothing supervising your gen_server.
A better approach is to have a full OTP application running alongside Yaws. With this approach, your application's supervisors manage your workers. One way to do this is by using yapps (Yaws applications). Another way is to create a release containing both Yaws and your application. Still another way is to let Yaws supervise your workers.
Addressing the second part of your question requires defining what you mean by "a simple application". Is it a simple static page application? A simple application using .yaws pages? A simple SSE application? A simple appmod application? A simple websocket application? A simple application running as a sibling of Yaws? There are a variety of possible definitions. The best short answer is to always structure your application using OTP design principles. You might also consider sending questions on this topic to the Yaws mailing list.

pstack equivalent in erlang

When a Erlang system hangs I want to know what the system is doing during that time. For a c/c++ program, I can easily run the pstack, but I didn't find out a handy tool for this purpose in Erlang.
What is the pstack equivalent in Erlang?
Actually I want to check the running stack trace of the following process.
"/opt/couchbase/lib/erlang/erts-5.10.4.0.0.1/bin/beam.smp -P 327680 -K true -- -root /opt/couchbase/lib/erlang -progname erl --... "
and I started a new Erlang shell and start the webtool and check the appmon however I can't find the above application. What may cause this?
Thanks
Concerning pstack equivalent, have you read Erlang Profiling from official guide? It gives you lot of example on how to profile your application and find where your code stuck.
Another useful tools is observer it will show all working process, CPU usage, process stack and lot of more information.
If you don't see anything with these tools, you can try with Erlang debugger.
Now concerning couchbase, if your application is currently running, you can connect to it with Erlang shell and launch previous quoted commands and applications.
I don't know if you are using couchbase alone or with couchdb, but, if you want to use observer or other tools from command line, you can start couchdb with -i flag:
# -i use the interactive Erlang shell
couchdb -i
In case of your application run remotely without GUI, you can use etop, its a CLI alternative to observer. You can also dump etop output to file if you don't want to run it directly from your Erlang shell. IHMO, if you want more information concerning I/O or debug, use eprof, fprof and other profiling tools with dump file (see also eep profiling tool, easy to use).
Another alternative, if you are using SSH and want to see observer window, you can use X11Forwarding with ssh: ssh -X $yourserver or ssh -Y $yourserver and simply run observer:start(). in your Erlang shell.

How to run Elixir from a thumb drive and without batch file launchers?

I have Erlang and Elixir installed on my thumb drive. The launcher for Elixir is a Windows Batch file rather than a standalone executable.
One of the computers that I use regularly for school blocks the command prompt, but Erlang runs without command prompt, so I am able to use Erlang on the school computer.
I was wondering if I could run Elixir manually or potentially with PowerShell, so that I could code at school.
If you look at the bottom of the batch file you'll see that elixir.bat is just building up an argument string to use when invoking the Erlang executable. You can just build the argument string by hand, and if you launch Erlang correctly you'll be in Elixir-land.
Alternatively, if you can run any executable, maybe you should try putting a copy of PowerShell on your thumb drive.

getting process ID of a pub serve to then kill that thread/process

So when I run my Polymer Dart application, i use pub serve and the serve is created and served. It will stay running until until i break out of it. I was curious if there is a way to programmatically stop it.
One of the options I was looking at was looking at the running processes and then killing the pub serve process.
I was not sure though how i would get the process id to kill it, or unless there was another option.
Maybe someone has an even better approach to shutdown pub serve on the machine automatically, as a form of cleanup?
The issue I have noticed is that if i get the running proceesses, i only see "cmd" as a process so that isnt the best determining factor.
I was not sure if there was a way via pub on serve to get its process if, if it set a flag or global of sorts I could leverage
This is not a Dart or Pub question really, it's a Windows, MacOS, Linux etc. shell process control question.
The question is more suited to Stack Exchange Superuser https://superuser.com/ I believe. You could look over there for more detailed answer ... but ... assuming you are using the windows command prompt:
start /B starts a process in the background.
tasklist can be used to look up running process PIDs.
taskkill /PID kills a running process.
You can use help <command> or search for documentation.
I have not used these personally but it looks awkward as start /B does not give you the PID of the process it ran. Unix shells such as Bash have good facilities for running processes in the background. Windows Powershell may have better support also.

Start Erlang on startup.

I'm working on using erlang development server. Is there a way fro me to start the erlang vm and continue from the commandline or add a script to the startup files? To be clear I want to start erlang and keep it running outside of the command prompt.
You can use the -detached flag. See http://www.erlang.org/doc/man/erl.html for more information.
I usually use scripts, which rebar create-node do provide. There is such commands as: start, stop, ping and attach. Although you must use erlang releases in order to use this scripts (at list take a look at template, maybe it would be helpful)

Resources