[erlang-questions] Maze alternate example for Rosetta Code

Sean Cribbs seancribbs@REDACTED
Fri Feb 12 18:53:25 CET 2016


I'm poking at a refactoring of it, but my first impression is that the
author didn't know the memory/complexity implications of list concatenation
(++) vs cons/reverse, elements of the standard library like sets (they used
a fixed array), and various other things that make the code more confusing.
As a result, there is probably some hidden waste.

I'll post a refactoring to this later. I wouldn't be so concerned with LoC,
but you might find that clearer, simpler implementations tend to have less
code anyway.

On Fri, Feb 12, 2016 at 10:33 AM, Felix Gallo <felixgallo@REDACTED> wrote:

> my suspicion (without having run that code yet) is that you're running out
> of memory somehow, and your computer's becoming slow as programs are
> getting paged in and out.  You might try starting the program while
> windows' process monitor is running and watching the CPU and memory graphs
> to see if there are any unnatural or explosive spikes.  If you've compiled
> with wx in your otp installation, then you could also start observer (type
> o() in the shell before kicking off your program) and watch the pretty
> lights while it runs.
> 10,000 erlang processes is not a heck of a lot, unless each of those
> processes, say, recurses over a megabyte of local state or, unbeknownst to
> you, starts another 100 processes each or tries to send every other process
> a message.
> epmd is, as you guess, super unlikely to be the root cause of any
> problems; it's just a name service.
> F.
> On Fri, Feb 12, 2016 at 7:31 AM, Bill Durksen <bdurksen@REDACTED>
> wrote:
>> Hi there,
>> To learn Erlang, I have recently switched from "learn you some Erlang" (
>> http://learnyousomeerlang.com) to building actual programs.
>> My first real Erlang program was a multi-process, multi-host,
>> wxWidgets-based file-transfer application with 768 lines of Erlang code.
>> I was surprised how simple it is to get this distributed functionality
>> built, cleanly, in Erlang.
>> Much appreciation goes to [erlang-questions]-subscribers, who guided me
>> to various solutions when I needed an Erlang implementation of the
>> Singleton design pattern.
>> The 'ets' dictionary solution worked for me, after I figured it out.
>> Currently, I am finishing a Maze-generation program (114 lines of packed
>> Erlang code), and have put the final version up on the Rosetta Code
>> web-site.
>> (see the http://rosettacode.org/wiki/Maze_generation#Erlang
>> ...Alternative example (implemented with 2 diagraphs)).
>> From doing this experiment, I have a few questions:
>> 1. The original Erlang maze-generation code (same Rosetta web-site page)
>> used a light-weight process for each vertex in the maze.
>>     This is a very good example of how the Erlang process architecture
>> can support many light-weight processes.
>>     I was surprised that it actually worked, until I tried generating a
>> bigger maze.
>>     When I used the original Erlang maze example to generate a maze of 25
>> columns x 4000 rows, it brought my PC down to a crawl.
>>     I couldn't do anything (I am running Windows 7 64-bit on 9 GB of RAM)
>> until I killed EPMD from Task Manager.
>>     Even after killing EPMD, it took quite a while for the computer to
>> get back to normal again, which indicates that it may not have been EPMD
>> causing the problem.
>>     Here is the question (part a): should I expect EPMD (or the WERL
>> process) to slow to a crawl with 100,000 Erlang processes running on a
>> single machine?
>>                                        (part b): If yes, what would be
>> the Erlang programmer's defence tactic against this scenario?
>> 2. 114 packed lines of Erlang code just seems to over-coded for such a
>> powerful language.
>>     Not being an expert, yet, in all the nuances of Erlang, can someone
>> suggest ways I can decrease maze.erl code down to 99 lines or less, without
>> cheating (removing too many newlines)?
>> Thanks,
>> Bill
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160212/348e69df/attachment.htm>

More information about the erlang-questions mailing list