From stonecypher@REDACTED Thu Jan 1 04:21:20 2009 From: stonecypher@REDACTED (John Haugeland) Date: Wed, 31 Dec 2008 20:21:20 -0700 Subject: [erlang-questions] A possible problem with the canonical listener idiom Message-ID: <8f24f4b10812311921k217831cdkfac24d85a6502377@mail.gmail.com> I'm not really 100% on this, but I think there might be a race condition in the canonical example listener under serious load which can lead to the initial packet(s) from an active or once-active socket being delivered to the accepting process rather than the handling process. I've documented what I believe the problem is, and how to fix it (including a standard fix in my utility library scutil, under the name standard_listener), here: http://fullof.bs/a-better-erlang-tcp-listening-pattern-addressingthe-fast-packet-loss-problem I would appreciate commentary. If I'm wrong, please let me know. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dbudworth@REDACTED Thu Jan 1 04:27:46 2009 From: dbudworth@REDACTED (David Budworth) Date: Wed, 31 Dec 2008 21:27:46 -0600 Subject: [erlang-questions] spawn_link In-Reply-To: References: Message-ID: <2e23d1d20812311927t41666be8u330c337b5fb7734f@mail.gmail.com> quick side note. while John's answer is correct. I think that Thilani is trying to spawn a short lived process that creates a socket connection. problem with that is that when the call (connect_to_server) returns, the process will exit and the socket will close since the socket lives and dies with the process calling gen_tcp:connect(...) you could hand control over to another process to keep this from happening, but this code is clearly not doing so. the function is: gen_tcp:controlling_process(Socket, NewSocketOwnerPid) but from a client perspective, this kind of defeats the purpose. what you really want to do is have the gen server initiate the connection itself (from the init method most likely). then it will own the process. and if it fails to connect, the gen server will bomb out letting you know it failed. if you are trying to make the gen server "generic" and not understand how the socket is created, you could always pass in a fun to gen_server:start(M,[fun() -> gen_tcp:connect(...)]) then in your gen_server: init([ConFun]) -> {ok,Socket} = ConFun(). benefits are: gen_server doesn't know how the socket is created, but it owns the socket itself. so as long as the gen_server is alive, the socket lives with it (unless closed by the other end). Hopefully that was helpful, -David On Mon, Dec 29, 2008 at 10:39 AM, John Hughes wrote: > Hi Thilani, > > As Chandru said, you just send the result back to the parent process as a > message. Here's some code: > > spawn_call(M,F,As) -> > Parent = self(), > Child = spawn_link(fun() -> Parent ! {self(),apply(M,F,As)} end), > receive {Child,X} -> X end. > > Note the receive matches on the child's pid, so can't be confused by any > other messages in the parent's mailbox. Sample call: > > 76> foo:spawn_call(lists,reverse,[[1,2,3]]). > [3,2,1] > > John > > > From: "Thilani Abeysinghe" > > Subject: [erlang-questions] spawn_link > > To: erlang-questions@REDACTED > > Message-ID: > > > > Content-Type: text/plain; charset="iso-8859-1" > > > > I have a problem of how to get the return value of a function when > > > > spawn_link(Fun) ->pid() is used. > > > > Im going to use above function in following manner. > > > > init([]) -> > > > > ChildPid = erlang:spawn_link(?MODULE, connect_to_server, [Ip,Port, ConId, > > self(),State]). > > > > connect_to_server(Ip, Port, ConId, ParentPid,State) -> > > case Result= gen_tcp:connect(Ip, Port, > > [binary, {packet, 0}]) of > > {ok, Socket} -> > > io:format("Socket Received:~w~n",[Socket]), > > ok =(catch gen_server:call(g_srv, {add_conn, self(), ConId, > > Socket})), > > NewState = State#state{socket= Socket}; > > {error, Reason} -> > > io:format("connection error host Ip:~w Port: ~w ~w ~n", > > [Ip,Port,Reason]) , > > connect_to_server(Ip, Port, ConId, ParentPid,State) > > end. > > > > I want to get the return value of connect_to_server function. How can I > do > > that. > > > > Regards > > > > Thilani > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From saleyn@REDACTED Thu Jan 1 16:21:23 2009 From: saleyn@REDACTED (Serge Aleynikov) Date: Thu, 01 Jan 2009 10:21:23 -0500 Subject: [erlang-questions] A possible problem with the canonical listener idiom In-Reply-To: <8f24f4b10812311921k217831cdkfac24d85a6502377@mail.gmail.com> References: <8f24f4b10812311921k217831cdkfac24d85a6502377@mail.gmail.com> Message-ID: <495CDF73.5070005@gmail.com> I believe that canonical examples you refer to are not the real-life guidelines one should use in writing production-grade TCP servers. The problem you found is indeed real when you are dealing with serious load. However if you read documentation of inet:setopts/2, at the end it clearly states that the use of {active, true} is not advised for high traffic conditions as it doesn't have flow control. Consequences can be rather drastic - race conditions, message queue overflow leading to high CPU utilization of the emulator and a subsequent crash. Therefore, every writer of a network server dealing with serious load (whether it involves TCP or UDP transport) should pay very close attention to the value of 'active' socket setting. It seems to me that {active, false} in the listening/accepting socket and {active, once} is the most preferable choice as it gives one the ability to have the "mailbox" message delivery non-blocking semantics as Erlang OTP programmers are accustomed to. This example is illustrated here: http://trapexit.org/Building_a_Non-blocking_TCP_server_using_OTP_principles Regards, Serge John Haugeland wrote: > I'm not really 100% on this, but I think there might be a race condition > in the canonical example listener under serious load which can lead to > the initial packet(s) from an active or once-active socket being > delivered to the accepting process rather than the handling process. > I've documented what I believe the problem is, and how to fix it > (including a standard fix in my utility library scutil, under the name > standard_listener), here: > > http://fullof.bs/a-better-erlang-tcp-listening-pattern-addressingthe-fast-packet-loss-problem > > I would appreciate commentary. If I'm wrong, please let me know. > > > ------------------------------------------------------------------------ > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From vinoski@REDACTED Thu Jan 1 19:26:30 2009 From: vinoski@REDACTED (Steve Vinoski) Date: Thu, 1 Jan 2009 13:26:30 -0500 Subject: [erlang-questions] A possible problem with the canonical listener idiom In-Reply-To: <495CDF73.5070005@gmail.com> References: <8f24f4b10812311921k217831cdkfac24d85a6502377@mail.gmail.com> <495CDF73.5070005@gmail.com> Message-ID: <65b2728e0901011026ib4bb19fw4f467e21c06706e7@mail.gmail.com> +1 to everything Serge says. Also, unless I'm missing something, I don't see how the original code can work with active set to anything but false anyway, since it never sets the controlling process for the connected socket to that of the spawned handler. --steve On 1/1/09, Serge Aleynikov wrote: > I believe that canonical examples you refer to are not the real-life > guidelines one should use in writing production-grade TCP servers. The > problem you found is indeed real when you are dealing with serious load. > However if you read documentation of inet:setopts/2, at the end it > clearly states that the use of {active, true} is not advised for high > traffic conditions as it doesn't have flow control. Consequences can be > rather drastic - race conditions, message queue overflow leading to high > CPU utilization of the emulator and a subsequent crash. Therefore, > every writer of a network server dealing with serious load (whether it > involves TCP or UDP transport) should pay very close attention to the > value of 'active' socket setting. It seems to me that {active, false} > in the listening/accepting socket and {active, once} is the most > preferable choice as it gives one the ability to have the "mailbox" > message delivery non-blocking semantics as Erlang OTP programmers are > accustomed to. This example is illustrated here: > > http://trapexit.org/Building_a_Non-blocking_TCP_server_using_OTP_principles > > Regards, > > Serge > > > John Haugeland wrote: > > I'm not really 100% on this, but I think there might be a race condition > > in the canonical example listener under serious load which can lead to > > the initial packet(s) from an active or once-active socket being > > delivered to the accepting process rather than the handling process. > > I've documented what I believe the problem is, and how to fix it > > (including a standard fix in my utility library scutil, under the name > > standard_listener), here: > > > > http://fullof.bs/a-better-erlang-tcp-listening-pattern-addressingthe-fast-packet-loss-problem > > > > I would appreciate commentary. If I'm wrong, please let me know. > > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions@REDACTED > > http://www.erlang.org/mailman/listinfo/erlang-questions > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From stonecypher@REDACTED Thu Jan 1 19:45:18 2009 From: stonecypher@REDACTED (John Haugeland) Date: Thu, 1 Jan 2009 11:45:18 -0700 Subject: [erlang-questions] A possible problem with the canonical listener idiom In-Reply-To: <495CDF73.5070005@gmail.com> References: <8f24f4b10812311921k217831cdkfac24d85a6502377@mail.gmail.com> <495CDF73.5070005@gmail.com> Message-ID: <8f24f4b10901011045t16a3a14fj7f303ffbaf514aaa@mail.gmail.com> > > at the end it clearly states that the use of {active, true} is not advised > for high traffic conditions as it doesn't have flow control. This isn't about flow control. This is about losing initial packets because they're going to the wrong process. {active,once} is immune to the flow control problem, and if you write a server capable of managing its own flow control, the initial packets are still at risk of being lost. Indeed, the code you linked to suffers the defect I'm discussing, and can lose packets for the same reason that the prior example can. The example you gave does not resolve the perceived defect. -------------- next part -------------- An HTML attachment was scrubbed... URL: From stonecypher@REDACTED Thu Jan 1 19:46:44 2009 From: stonecypher@REDACTED (John Haugeland) Date: Thu, 1 Jan 2009 11:46:44 -0700 Subject: [erlang-questions] A possible problem with the canonical listener idiom In-Reply-To: <65b2728e0901011026ib4bb19fw4f467e21c06706e7@mail.gmail.com> References: <8f24f4b10812311921k217831cdkfac24d85a6502377@mail.gmail.com> <495CDF73.5070005@gmail.com> <65b2728e0901011026ib4bb19fw4f467e21c06706e7@mail.gmail.com> Message-ID: <8f24f4b10901011046g7c01663dne6220a593874e4fc@mail.gmail.com> > +1 to everything Serge says. Unfortunately, he missed the point: this isn't about flow control, this is about missing initial packets, and the code he linked to suffers the exact same defect. > Also, unless I'm missing something, I > don't see how the original code can work with active set to anything > but false anyway, since it never sets the controlling process for the > connected socket to that of the spawned handler. Setting inet options should implicitly set the owner process. (Note that I said should, not "does": I'm not saying this is correct, I'm saying this is what I expected.) My belief in that regard is reinforced by the fact that the code does work as expected. However, I will explicitly set the owner process now, both in the blog example and in the library code. Thank you for pointing out this problem. -------------- next part -------------- An HTML attachment was scrubbed... URL: From saleyn@REDACTED Thu Jan 1 19:56:43 2009 From: saleyn@REDACTED (Serge Aleynikov) Date: Thu, 01 Jan 2009 13:56:43 -0500 Subject: [erlang-questions] A possible problem with the canonical listener idiom In-Reply-To: <8f24f4b10901011031i77684498m87ed8cfd72221657@mail.gmail.com> References: <8f24f4b10812311921k217831cdkfac24d85a6502377@mail.gmail.com> <495CDF73.5070005@gmail.com> <8f24f4b10901011031i77684498m87ed8cfd72221657@mail.gmail.com> Message-ID: <495D11EB.50107@gmail.com> John Haugeland wrote: > > at the end it clearly states that the use of {active, true} is not > advised for high traffic conditions as it doesn't have flow control. > > > This isn't about flow control. This is about losing initial packets > because they're going to the wrong process. The Erlang network driver presents another logical middleman "actor" in communication between TCP client and an Erlang TCP server process. Since TCP has built-in flow control and recovery from packet loss, the flow control and race conditions we are talking about are not so much between TCP client and a TCP server processes, but is between the network driver and the process receiving messages coming from a TCP client through the driver. Proper synchronization of that message delivery is the flow control that can guarantee that messages make it to correct mailboxes. {active, false} says to the driver: "Hey, don't read anything from that socket until the socket's owner instructs you to do so, or someone reads the message explicitly". If you prefer not to call this "flow control" you can come up with a more pleasing name for it. > {active,once} is immune to > the flow control problem, and if you write a server capable of managing > its own flow control, the initial packets are still at risk of being > lost. Indeed, the code you linked to suffers the defect I'm discussing, > and can lose packets for the same reason that the prior example can. Could you kindly point me to the place in code in that tutorial at trapexit where you see the race condition? The process owning the listening socket has it open with {active, false}. After accepting a client's socket that socket *inherits socket options* (including {active, false}) from the listener, and transfers ownership of the socket to the newly spawned client handling process by calling Module:set_socket/2, which does inet:setopts(Socket, [{active, once}]) in the context of the process different from the listener. I don't see a race condition here. Serge From stonecypher@REDACTED Thu Jan 1 20:34:45 2009 From: stonecypher@REDACTED (John Haugeland) Date: Thu, 1 Jan 2009 12:34:45 -0700 Subject: [erlang-questions] A possible problem with the canonical listener idiom In-Reply-To: <495D11EB.50107@gmail.com> References: <8f24f4b10812311921k217831cdkfac24d85a6502377@mail.gmail.com> <495CDF73.5070005@gmail.com> <8f24f4b10901011031i77684498m87ed8cfd72221657@mail.gmail.com> <495D11EB.50107@gmail.com> Message-ID: <8f24f4b10901011134td87e313tec2d7ff601c7d894@mail.gmail.com> > Could you kindly point me to the place in code in that tutorial at trapexit > where you see the race condition? The process owning the listening socket > has it open with {active, false}. After accepting a client's socket that > socket *inherits socket options* (including {active, false}) from the > listener, and transfers ownership of the socket to the newly spawned client > handling process by calling Module:set_socket/2, which does > inet:setopts(Socket, [{active, once}]) in the context of the process > different from the listener. > > I don't see a race condition here. > I apologize. I misread. You are correct. (Also, I need to quit accidentally sending responses to people, rather than the list.) -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik.svahn@REDACTED Thu Jan 1 21:14:46 2009 From: fredrik.svahn@REDACTED (Fredrik Svahn) Date: Thu, 1 Jan 2009 21:14:46 +0100 Subject: [erlang-questions] The If expression Message-ID: I would like to hear your views and proposals for an alternative syntax for the 'if' expression. If the majority thinks that the result of the discussion in this thread is interesting enough I will sum it up and submit it as an Erlang Enhancement Proposal. The background is the intensive discussion on this mailing list back in March. There has also been quite a number of questions to the mailing list on how to use the 'if'-expression, generally leading to a recommendation to use the 'case'-expression instead of 'if'. Some have even argued that the 'if' expression should be retired/obsoleted since it is useless in its current form. I find myself almost never ever using the 'if'-expression due to the limitations listed below. At the same time I feel that the 'case'-expression is to "heavy-weight" or clumsy when used for branching on bools. Today an 'if'-expression is defined as: if GuardSeq1 -> Body1; ...; GuardSeqN -> BodyN end With the added (undocumented?) twist that if a guard throws an exception the guard simply evaluates to false. In addition to the above (which is kept for backwards compatibility) I suggest adding an alternative form with the following syntax: if Expression -> Body else -> ElseBody end which should act as syntactical sugar for the more clumsy and unintuitive: case Expression of true -> Body; _Else -> ElseBody end My hope is that with this improvement 'if'-statements would be the recommended choice for expressions evaluating to a bool() and 'case'-statements the natural choice for all other expressions. This proposal is in no way competing with other recently proposed control flow improvements, such as using the already reserved word 'cond' and "unnesting case statements". I think this would be rather simple to implement. I believe it could for instance be done with just a 4-5 lines in the parser. It would also be "almost 100%" backwards compatible ('else' would need to become a reserved word, but this could very well be needed already by earlier enhancement proposals, e.g. by EEP-25). The proposal would address two of the problems with the current syntax: 1. Today only guards are allowed, not full expressions. For instance, today it is NOT ok to write: if erlang:system_info(smp_support) -> init_smp(); true -> init() end. which many believe is a rather serious limitation of the usefulness. 2. At least of of the guards have to evaluate to true, otherwise a runtime error will occur. This leads to unintuitive constructs like: if Bool -> do_true(); true -> do_false() end. Which could be replaced by a more intuitive: if Bool -> do_true() else -> do_false() end. An open question is if it should also be allowed to have expressions without an 'else' clause, as proposed by Damien Katz, i.e.: if Expression -> Body end Which might be useful in some cases, e.g. if Logging -> log:write("Aiee") end, This could be handled by introducing a default return value for the else clause in the odd cases where we might sometimes care about the value of the "if"-expression, i.e.: LoggingSucceded = if Logging -> log:write("Aiee") end In this particular case returning false might seem like a good idea, but in other cases e.g. an empty list might be just as natural. I am just not sure how to apply the rule of least surprise to this... Another proposal might be to allow "if"-expressions without an else clause only when it is obvious to the compiler that the return value will be discarded. The second example would thus result in a "LoggingSucceded is unsafe in 'if' (line x)" error when compiling (similar to what exists for e.g. case clauses today). BR /Fredrik From vinoski@REDACTED Thu Jan 1 22:45:16 2009 From: vinoski@REDACTED (Steve Vinoski) Date: Thu, 1 Jan 2009 16:45:16 -0500 Subject: [erlang-questions] A possible problem with the canonical listener idiom In-Reply-To: <8f24f4b10901011046g7c01663dne6220a593874e4fc@mail.gmail.com> References: <8f24f4b10812311921k217831cdkfac24d85a6502377@mail.gmail.com> <495CDF73.5070005@gmail.com> <65b2728e0901011026ib4bb19fw4f467e21c06706e7@mail.gmail.com> <8f24f4b10901011046g7c01663dne6220a593874e4fc@mail.gmail.com> Message-ID: <65b2728e0901011345u561ffc92qc6db2461003b5e29@mail.gmail.com> On 1/1/09, John Haugeland wrote: > Setting inet options should implicitly set the owner process. (Note that I > said should, not "does": I'm not saying this is correct, I'm saying this is > what I expected.) My belief in that regard is reinforced by the fact that > the code does work as expected. I still contend that it doesn't work as expected, or more accurately didn't work in your svn version 98. I posted a test program that shows the problem, along with a patch for your code, to your blog: Also, I don't believe inet:setopts sets the controlling process, judging from the Erlang source code, but I'm sure someone will correct me if I'm wrong. --steve From rvirding@REDACTED Thu Jan 1 23:07:18 2009 From: rvirding@REDACTED (Robert Virding) Date: Thu, 1 Jan 2009 23:07:18 +0100 Subject: [erlang-questions] New version of Leex - a lexical analyser generator Message-ID: <3dbc6d1c0901011407x260b2a8es3b6d4b788723ed8e@mail.gmail.com> I have just released version 0.3 of Leex. New features and changes from the previous version are: - Added options to push back characters into the input stream. - Can now handle full unicode character sets in both input file and generated scanner. Of course i/o system can't generate such an input file yet. - Enforce headings for all sections of .xrl file. - Added verbose flag to control printing of parsing information. - Fixed bug with completely empty erlang code section. You can get from either trapexit.org or github. The links are: http://forum.trapexit.org/viewtopic.php?p=44352#44352 http://github.com/rvirding/leex/tree Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From saleyn@REDACTED Fri Jan 2 03:45:32 2009 From: saleyn@REDACTED (Serge Aleynikov) Date: Thu, 01 Jan 2009 21:45:32 -0500 Subject: [erlang-questions] A possible problem with the canonical listener idiom In-Reply-To: <65b2728e0901011345u561ffc92qc6db2461003b5e29@mail.gmail.com> References: <8f24f4b10812311921k217831cdkfac24d85a6502377@mail.gmail.com> <495CDF73.5070005@gmail.com> <65b2728e0901011026ib4bb19fw4f467e21c06706e7@mail.gmail.com> <8f24f4b10901011046g7c01663dne6220a593874e4fc@mail.gmail.com> <65b2728e0901011345u561ffc92qc6db2461003b5e29@mail.gmail.com> Message-ID: <495D7FCC.9030004@gmail.com> Steve Vinoski wrote: > Also, I don't believe inet:setopts sets the controlling process, > judging from the Erlang source code, but I'm sure someone will correct > me if I'm wrong. There's no documentation supporting the fact that inet:setopts(S, [{active, N}]) call is claimed to set the controlling process. Its mere purpose is to tell the driver *how* to enforce message delivery rather than *where to*. gen_{tcp,udp}:controlling_process/2 is used for setting the controlling process (i.e. the recipient of actively delivered messages). Serge From rasmussen.bryan@REDACTED Fri Jan 2 10:45:37 2009 From: rasmussen.bryan@REDACTED (bryan rasmussen) Date: Fri, 2 Jan 2009 10:45:37 +0100 Subject: [erlang-questions] Problem with XML validation using xmerl_xsd:validate(). In-Reply-To: <6a3ae47e0812300515u62b671e0pa08d063fc74bfcaa@mail.gmail.com> References: <42EC95E4-C48C-453C-80F5-2A0EC7901B4E@gmail.com> <6a3ae47e0812300515u62b671e0pa08d063fc74bfcaa@mail.gmail.com> Message-ID: <3bb44c6e0901020145x5c8fef50v8ebb3de116f0c82c@mail.gmail.com> The string datatype in XML Schema can be zero length. So by default the text value of an XSD string is optional. Thus from what I can see of your example, in my gmail, is valid. If you have valid results from other validating parsers I would assume it is likely valid. I tried it with XSV just to see if there was something I overlooked. passed fine. Looks like a bug. Cheers, Bryan Rasmussen On Tue, Dec 30, 2008 at 2:15 PM, Robert Raschke wrote: > 2008/12/30 Andrey Sedinin : >> Hi >> >> Of course i have tested this case: >> >> >> >> It does not work too (or it work with the same result :). >> >> But in XML it is equivalent: >> >> =:= >> >> But any way -- thank you for your guessing. > > I don't know very much about XML and schemas, but is it actually > possible to distinguish an empty text content from a non-existant one > (that would be kind of like "" == NULL)? I mean the text, not the > presence of the node itself. > > If empty == non-existant then I don't think you can easily represent > that in a schema. But, as I say, I am not an expert. > > Do schemas not allow you to state that text content of a node is optional? > > Robby > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From hakan@REDACTED Fri Jan 2 12:05:32 2009 From: hakan@REDACTED (Hakan Mattsson) Date: Fri, 2 Jan 2009 12:05:32 +0100 (CET) Subject: [erlang-questions] The If expression In-Reply-To: References: Message-ID: On Thu, 1 Jan 2009, Fredrik Svahn wrote: > if Expression -> Body else -> ElseBody end > > which should act as syntactical sugar for the more clumsy and unintuitive: > > case Expression of > true -> Body; > _Else -> ElseBody > end > > My hope is that with this improvement 'if'-statements would be the > recommended choice for expressions evaluating to a bool() and > 'case'-statements the natural choice for all other expressions. This > proposal is in no way competing with other recently proposed control > flow improvements, such as using the already reserved word 'cond' and > "unnesting case statements". I do not fancy any of these two code examples as they promote a sloppy programming style. In my opinion, a boolean expression should be a boolean expression and nothing else. If a boolean expression evaluates to anything else than 'true' or 'false', the evaluation should fail in the normal case. Sometimes catch-all-clauses are useful, but in many cases they may delay detection of bugs. > 2. At least of of the guards have to evaluate to true, otherwise a > runtime error will occur. This leads to unintuitive constructs like: > > if Bool -> do_true(); > true -> do_false() end. > Which could be replaced by a more intuitive: > > if Bool -> do_true() else -> do_false() end. How realistic is it to expect that the common form of future if-statements are written as one-liners? If the if-statement does not fit in one line, I think that the the new proposed syntax and the classic case-statement are very similar: if Bool -> do_true() else -> do_false() end. case Bool of true -> do_true(); false -> do_false() end. They are in fact so similar so that I see no point in adding a new language construct. You argued that the following code is unintuitive if Bool -> do_true(); true -> do_false() end. while the following is intuitive if Bool -> do_true() else -> do_false() end. I find the new proposed syntax to be very similar to the old if-statement. The old syntax may be a little bit uglier than the new syntax, but that is not the same as unintuitive. I definitely prefer the case-syntax, for if-then-else statements. > An open question is if it should also be allowed to have expressions > without an 'else' clause, as proposed by Damien Katz, i.e.: > > if Expression -> Body end > > Which might be useful in some cases, e.g. > > if Logging -> log:write("Aiee") end, This would be an incompatible language change that breaks lots of code. I frequently write code that is intended to provoke a crash (for example by not having a catch-all-clause in if-statements) in those cases when some variable has an unexpected value. > This could be handled by introducing a default return value for the > else clause in the odd cases where we might sometimes care about the > value of the "if"-expression, i.e.: > > LoggingSucceded = if Logging -> log:write("Aiee") end > > In this particular case returning false might seem like a good idea, > but in other cases e.g. an empty list might be just as natural. I am > just not sure how to apply the rule of least surprise to this... > > Another proposal might be to allow "if"-expressions without an else > clause only when it is obvious to the compiler that the return value > will be discarded. The second example would thus result in a > "LoggingSucceded is unsafe in 'if' (line x)" error when compiling > (similar to what exists for e.g. case clauses today). Is this what you mean with intuitive? ;-) /H?kan --- H?kan Mattsson (uabhams) Erlang/OTP, Ericsson AB From sedinin@REDACTED Fri Jan 2 13:54:51 2009 From: sedinin@REDACTED (Andrey Sedinin) Date: Fri, 2 Jan 2009 04:54:51 -0800 (PST) Subject: [erlang-questions] Problem with XML validation using xmerl_xsd:validate(). In-Reply-To: <3bb44c6e0901020145x5c8fef50v8ebb3de116f0c82c@mail.gmail.com> References: <42EC95E4-C48C-453C-80F5-2A0EC7901B4E@gmail.com> <6a3ae47e0812300515u62b671e0pa08d063fc74bfcaa@mail.gmail.com> <3bb44c6e0901020145x5c8fef50v8ebb3de116f0c82c@mail.gmail.com> Message-ID: Hello Bryan. I tried different validating parsers. Netbeans validates fine. Also i found some in the web, they validates as well. So i think same - looks like a bug. Is Someone know, how to fire a bug? Regards -- Sedinin On 2 ???, 11:45, "bryan rasmussen" wrote: > The string datatype in XML Schema can be zero length. So by default > the text value of an XSD string is optional. > > Thus from what I can see of your example, in my gmail, is valid. If > you have valid results from other validating parsers I would assume it > is likely valid. > > I tried it with XSV just to see if there was something I overlooked. > passed fine. > Looks like a bug. > > Cheers, > Bryan Rasmussen > From fredrik.svahn@REDACTED Fri Jan 2 13:54:56 2009 From: fredrik.svahn@REDACTED (Fredrik Svahn) Date: Fri, 2 Jan 2009 13:54:56 +0100 Subject: [erlang-questions] The If expression In-Reply-To: References: Message-ID: > I do not fancy any of these two code examples as they promote a sloppy > programming style. In my opinion, a boolean expression should be a > boolean expression and nothing else. If a boolean expression evaluates > to anything else than 'true' or 'false', the evaluation should fail in > the normal case. Sometimes catch-all-clauses are useful, but in many > cases they may delay detection of bugs. You are right, of course. The catch-all should be replaced with a false-clause. > I find the new proposed syntax to be very similar to the old > if-statement. The old syntax may be a little bit uglier than the new > syntax, but that is not the same as unintuitive. The first unintuitive part about the current "if" (at least for beginners) is that the true clause in my example is evaluated when the Bool evaluates to false. This problem does not exist with an else clause. The second unintuitive part is that exceptions are silently swallowed. if length({}) == 0 -> its_empty; true -> its_not_empty end. By the way, just found this: http://www.trapexit.org/If_Then BR /Fredrik From chris.newcombe@REDACTED Fri Jan 2 16:31:08 2009 From: chris.newcombe@REDACTED (Chris Newcombe) Date: Fri, 2 Jan 2009 07:31:08 -0800 Subject: [erlang-questions] A possible problem with the canonical listener idiom In-Reply-To: <8f24f4b10812311921k217831cdkfac24d85a6502377@mail.gmail.com> References: <8f24f4b10812311921k217831cdkfac24d85a6502377@mail.gmail.com> Message-ID: <781dd98c0901020731h792c9437x3330a77dab50ac4e@mail.gmail.com> > a race condition in > the canonical example listener under serious load which can lead to the > initial packet(s) from an active or once-active socket being delivered to > the accepting process rather than the handling process. When I first started using gen_tcp in active mode I was worried about this too. So I did a little digging and found that inet:controlling_process contains code that 'fixes' the race condition. See the code from inet.erl (in R12B-2), pasted below for convenience. i.e. inet:controlling_process specifically looks for any packets that have arrived at the 'wrong' (old owner) process and moves them to the new owner process. It correctly preserves any semantic-significance in the order of packet messages that it moves (it moves data packets in order, and then moves 'closed' messages etc. after them). And it also ensures that such 'old' packets are delivered before any newer packets that arrive while controlling_process is moving the old packets (it temporarily changes the socket to 'active false' mode while doing the move, and then restores the previous 'active' mode. Note that controlling_process may only be called by the current owner of the socket (i.e. the 'acceptor' process), so this mechanism is guaranteed to have access to the mailbox that might contain 'old' packets. It seems safe to me. I wrote a simple test (also pasted below) to verify that 'old' packets are in fact moved, and their relative order is preserved. Chris >From erlang/lib/kernel-2.12.2/src/inet.erl %% Set controlling process for TCP socket. tcp_controlling_process(S, NewOwner) when is_port(S), is_pid(NewOwner) -> case erlang:port_info(S, connected) of {connected, Pid} when Pid =/= self() -> {error, not_owner}; undefined -> {error, einval}; _ -> case prim_inet:getopt(S, active) of {ok, A0} -> prim_inet:setopt(S, active, false), case tcp_sync_input(S, NewOwner, false) of true -> %% %% socket already closed, ok; false -> case catch erlang:port_connect(S, NewOwner) of true -> unlink(S), %% unlink from port prim_inet:setopt(S, active, A0), ok; {'EXIT', Reason} -> {error, Reason} end end; Error -> Error end end. tcp_sync_input(S, Owner, Flag) -> receive {tcp, S, Data} -> Owner ! {tcp, S, Data}, tcp_sync_input(S, Owner, Flag); {tcp_closed, S} -> Owner ! {tcp_closed, S}, tcp_sync_input(S, Owner, true); {S, {data, Data}} -> Owner ! {S, {data, Data}}, tcp_sync_input(S, Owner, Flag); {inet_async, S, Ref, Status} -> Owner ! {inet_async, S, Ref, Status}, tcp_sync_input(S, Owner, Flag); {inet_reply, S, Status} -> Owner ! {inet_reply, S, Status}, tcp_sync_input(S, Owner, Flag) after 0 -> Flag end. My test program: % Run with %% %% erlc -v -W test_controlling_process.erl && erl -noshell -s test_controlling_process main -module(bug_controlling_process). -export([main/0]). main() -> Port = 40000, _Acceptor = spawn_link( fun() -> {ok, ListenSocket} = gen_tcp:listen(Port, [{reuseaddr, true}, binary, {packet, 2}, {active, true}, {exit_on_close, false}]), acceptor(ListenSocket) end), %% Send data to the port and then close the connection {ok, ClientSocket} = gen_tcp:connect("localhost", Port, [binary, {packet, 2}]), gen_tcp:send(ClientSocket, "data1"), gen_tcp:send(ClientSocket, "data2"), gen_tcp:shutdown(ClientSocket, write), %%gen_tcp:close(ClientSocket), timer:sleep(infinity). acceptor(ListenSocket) -> case gen_tcp:accept(ListenSocket) of {error, Reason} -> exit({accept_error, Reason}); {ok, Socket} -> Worker = spawn_link(fun() -> order_sensitive_worker(Socket) end), %% Increase the probability of the race-condition by %% waiting for until some data has arrived on the socket %% before we transfer ownership timer:sleep(1000), %% Confirm that we have the expected messages %% {messages, [{tcp, Socket, <<"data1">>}, %% {tcp, Socket, <<"data2">>}, %% {tcp_closed, Socket} %% ]} %% = process_info(self(), messages), io:format("messages before transfering ownership: ~p~n", [process_info(self(), messages)]), %% Now transfer ownership ok = gen_tcp:controlling_process(Socket, Worker), timer:sleep(infinity) end. order_sensitive_worker(Socket) -> io:format("order_sensitive_worker waiting for active messages on socket ~w~n", [Socket]), order_sensitive_worker_loop(). order_sensitive_worker_loop() -> receive Msg -> io:format("Received ~p~n", [Msg]), order_sensitive_worker_loop() end. 2008/12/31 John Haugeland : > I'm not really 100% on this, but I think there might be a race condition in > the canonical example listener under serious load which can lead to the > initial packet(s) from an active or once-active socket being delivered to > the accepting process rather than the handling process. I've documented > what I believe the problem is, and how to fix it (including a standard fix > in my utility library scutil, under the name standard_listener), here: > > http://fullof.bs/a-better-erlang-tcp-listening-pattern-addressingthe-fast-packet-loss-problem > > I would appreciate commentary. If I'm wrong, please let me know. > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From dmorton@REDACTED Fri Jan 2 19:04:36 2009 From: dmorton@REDACTED (damien morton) Date: Sat, 3 Jan 2009 05:04:36 +1100 Subject: [erlang-questions] next(Erlang) a report Message-ID: <8092dc770901021004s409eb263s4af26630d2a1adb1@mail.gmail.com> A month or so ago, there was some discussion about future erlang ideas, and I created a Google Moderator site for collecting these ideas and allowing people to cast their 'votes' on them. Obviously, the 'votes' aren't binding, but they may help identify areas of interest. The next(Erlang) site is available at http://moderator.appspot.com/#16/e=bbc4 Google Moderator have proved not to be the ideal medium for this, because it doesn't allow for any discussion of the suggestions - only voting and proposing. Close, but no pyjamas. So far 40 or so people have dropped by to propose suggestions and vote on the suggestions already there.Some of the more recently added suggestions havent been voted on much, and I would encourage anyone who is interested to drop by. If you have already voted, please drop by again to see suggestions added since you last visited. So far the suggestions with near unanimous support are as follows: * "Fix up the collections library" and "Refactor the basic data structures (list,set,proplists,tree,dict,ets,dets) to conform to a common set of interfaces and protocols?" * "increasing the maximum table size of DETS" * "Fix up records so that records are first-class citizens and not just syntax saccharine for tuples?" From kaiduanx@REDACTED Fri Jan 2 22:35:07 2009 From: kaiduanx@REDACTED (Kaiduan Xie) Date: Fri, 2 Jan 2009 16:35:07 -0500 Subject: [erlang-questions] Best practice to hot update .hrl Message-ID: Hi, OTP Design principles talks a lot on how to do release handling. However it does not discuss the case where .hrl file is updated. For example, how to deal the the following cases? 1. A new record is added, 2. An element is removed/added from an existing record, 3. A value of macro is changed. Thanks for inputs, kaiduan -------------- next part -------------- An HTML attachment was scrubbed... URL: From hasan.veldstra@REDACTED Fri Jan 2 23:44:30 2009 From: hasan.veldstra@REDACTED (Hasan Veldstra) Date: Fri, 2 Jan 2009 22:44:30 +0000 Subject: [erlang-questions] Best practice to hot update .hrl In-Reply-To: References: Message-ID: <73C56B5E-9B31-4FF7-ACBD-1D8682EDA902@gmail.com> definitons from header files get inserted into erl files directly by the preprocessor. (i don't think the Erlang runtime has a concept of a "header file" ? someone please correct me if i'm wrong.) so you simply (re)compile the modules that make use of the updated hrl file and reload them. On 2 Jan 2009, at 21:35PM, Kaiduan Xie wrote: > Hi, > > OTP Design principles talks a lot on how to do release handling. > However it does not discuss the case where .hrl file is updated. > For example, how to deal the the following cases? > > 1. A new record is added, > 2. An element is removed/added from an existing record, > 3. A value of macro is changed. > > Thanks for inputs, > > kaiduan > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From bengt.kleberg@REDACTED Sat Jan 3 16:09:54 2009 From: bengt.kleberg@REDACTED (Bengt Kleberg) Date: Sat, 03 Jan 2009 16:09:54 +0100 Subject: [erlang-questions] Are packaged modules the way to go ? In-Reply-To: <49583292.8040903@laposte.net> References: <49583292.8040903@laposte.net> Message-ID: <1230995394.4583.8.camel@seasc1137.dyn.rnd.as.sw.ericsson.se> Greetings, This is a thread from when packaged modules was last(?) discussed on the list: http://forum.trapexit.org/mailinglists/viewtopic.php?p=22616&highlight=&sid=2ff3904329e85e18ccf70ca20e79c042 I belive it shows that the existing packaged modules are not a sufficiently good idea to warrant official adaptation. bengt On Mon, 2008-12-29 at 03:14 +0100, cyril Romain wrote: > Hi, > > This mail is about packaged modules (module with namespace), aimed to > extend Erlang with structured module packages [1]. > You can find a quick introduction [2] and the packages module > documentation [3]. > > Using packaged modules or not has little impact on code but quite big > impact on: > - project file structure and naming > - tools analyzing Erlang files or project file structure (such as > debugger, dialyzer, Emakefile, etc.). > - and consequently on package structure (I mean Erlang software > packaging here, such as done by CEAN [4]). > The support for packaged module has been introduced in Erlang/OTP before > 2003 for evaluation purpose [5], but its adoption (or the intent of > adoption) seems still unclear today. > > So my question is: for the sake of Erlang software consistency, should > Erlang developers - be it core developers or developers using Erlang - > adopt packaged modules ? > Does it need improvement before official adoption ? Should packaged > modules be ignored (or even removed from Erlang?) instead ? > > Best regards, > > Cyril > > [1] http://www.it.uu.se/research/publications/reports/2000-001/ > [2] http://www.erlang.se/publications/packages.html > [3] http://erlang.org/doc/man/packages.html ; For some reason exported > methods are not documented. > [4] http://cean.process-one.net/ > [5] http://www.erlang.org/pipermail/erlang-questions/2003-April/008575.html > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From yubao.liu@REDACTED Sun Jan 4 04:15:46 2009 From: yubao.liu@REDACTED (Liu Yubao) Date: Sun, 04 Jan 2009 11:15:46 +0800 Subject: [erlang-questions] openssl s_client hangs when accessing https service in inets application In-Reply-To: <495AE082.1050502@gmail.com> References: <495AE082.1050502@gmail.com> Message-ID: <496029E2.6030107@gmail.com> Hi, The documentation and code of inets application are not consistent, the corresponding option in {proplist_file, path()} to "SocketType" option in {file, path()} is "com_type", not "socket_type". Liu Yubao wrote: > Hi, > > The https services in inets application doesn't work, I guess > I got something wrong. Below is the steps to recur: > > a. use gen-cert.sh to generate server.pem; > (All scripts and configuration are provided at > http://jff.googlecode.com/files/inets-https-test.tar > ) > > b. execute runerl.sh and input these clauses in the erlang shell: > application:start(ssl). > application:start(inets). > > c. execute `openssl s_client -connect localhost:8443 -debug -msg`, > you can see openssl hangs after sending a CLIENT-HELLO message, > the TCP connection is established successfully but https server > doesn't response to the CLIENT-HELLO message. > > > I tested "ssl:listen" in erlang shell and succeed to communication between > openssl and erlang shell: > > application:start(ssl). > {ok, S} = ssl:listen(8443, [{certfile, "server.pem"}, {active, false}]). > {ok, S2} = ssl:accept(S). > # execute in another bash: openssl s_client -connect localhost:8443 > ssl:send(S2, <<"hello world\n">>). > # "openssl s_client" can receive this greeting. > > > I tested against the latest erlang 5.6.5 under Windows XP and 5.6.3 under > Debian Lenny. > > I'm looking forward your help! > > > Best regards, > > Liu Yubao > From cliff@REDACTED Sun Jan 4 18:53:37 2009 From: cliff@REDACTED (Cliff Moon) Date: Sun, 04 Jan 2009 09:53:37 -0800 Subject: [erlang-questions] mocking libraries? Message-ID: <4960F7A1.5080902@moonpolysoft.com> Does anyone know of any Erlang mocking libraries for testing? I'm endeavoring to create my own, but I'd rather not reinvent the wheel. From nc@REDACTED Sun Jan 4 19:10:36 2009 From: nc@REDACTED (Nicolas Charpentier) Date: Sun, 04 Jan 2009 19:10:36 +0100 Subject: [erlang-questions] mocking libraries? In-Reply-To: <4960F7A1.5080902@moonpolysoft.com> References: <4960F7A1.5080902@moonpolysoft.com> Message-ID: <4960FB9C.6040703@charpi.net> Cliff Moon wrote: > Does anyone know of any Erlang mocking libraries for testing? I'm > endeavoring to create my own, but I'd rather not reinvent the wheel. Hi, you can have a look at some posts I wrote about mock in erlang (http://charpi.net/blog/tag/mock-object) The packaging of the library isn't yet done, but you can access to the git repository on git-hub (http://github.com/charpi/erl_mock/tree/master) Regards, ---- Nicolas Charpentier http://charpi.net From vychodil.hynek@REDACTED Sun Jan 4 22:09:23 2009 From: vychodil.hynek@REDACTED (Hynek Vychodil) Date: Sun, 4 Jan 2009 22:09:23 +0100 Subject: [erlang-questions] How implicit inlining works? Message-ID: <20090104210924.C3BDC24013@relay.gooddata.com> Hello everybody, I want ask how in-lining works. In documentation http://www.erlang.org/doc/man/compile.html I can read how to switch on implicit inlining %% Aggressive inlining - will increase code size. -compile(inline). -compile({inline_size,100}). but I never have seen it works. When I want inline something I must specify it explicitly using -compile({inline, [{fun, arity}]}). Is it bug or I do something wrong? Best regards. -- --Hynek (Pichi) Vychodil Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero! Try Good Data now for free: www.gooddata.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From pat@REDACTED Sun Jan 4 22:33:52 2009 From: pat@REDACTED (Patrick Mahoney) Date: Sun, 4 Jan 2009 14:33:52 -0700 Subject: [erlang-questions] Problems writing ncurses port and undocumented erl -nouser flag Message-ID: <20090104213352.GA23708@localhost.localdomain> I'm trying to write an ncurses port for simple client software in erlang (e.g. irc client). My initial problem was that both ncurses and erlang seem to be competing for input on fd 0 so ncurses doesn't get all the user input. I was able to solve it by using "-noinput -nouser" flags to erl, but "-nouser" is undocumented, so I'm wondering if this I'm using it correctly. My initial idea was something like this: Port = open_port({spawn, "./ncurses_port 3 4"}, [{packet,2}, nouse_stdio, binary]) ncurses_port is a C program using ei and fds 3,4 for communicating with erlang and inherits fds 0,1 which are the tty that ncurses routines will control. erl(3) states that the -noinput flag "Ensures that the Erlang runtime system never tries to read any input". So I started erlang like this: erl -noinput ncurses.erl -run ncurses But when reading user input, I don't get all the chars because erlang is also reading from fd 0. I can extract these missing chars from the user process (lib/kernel/src/user.erl) like this: user ! {io_request, self(), result, {get_chars, '', 2}}, receive {io_reply, result, Data} -> io:format("got chars: ~p~n", [Data]) end Looking in lib/kernel/src/user_sup.erl, when the "noinput" flag is present, the user process is started with user:start_out() which does open_port({fd,0,1}, [out,binary]); the "out" option to open_port makes that port only available for output as stated in the erlang(3) manpage. I spotted a "nouser" flag in lib/kernel/src/user_sup.erl, which causes it to not start the user process. Is this a supported flag (it's not documented in the erl(3) manpage)? When I start erlang like this: erl -noinput -nouser ncurses.erl -run ncurses ncurses input seems to behave as I expect. So, is there something ncurses might be doing to the file descriptors that would break whatever the "out" option does? Is the erlang documentation in error? Is using "-nouser" to avoid the user process an appropriate solution? Thanks. From ryeguy1@REDACTED Mon Jan 5 00:59:02 2009 From: ryeguy1@REDACTED (Ryan Lepidi) Date: Sun, 4 Jan 2009 18:59:02 -0500 Subject: [erlang-questions] Flash client communication with Erlang Server problem Message-ID: This is an erlang problem, it seems. I have this code to test the client sending data, written in Actionscript 3: Code:var socket:Socket=new Socket("localhost", 2345); socket.addEventListener(Event.CONNECT, connected); private function connected(event:Event):void { socket.writeInt(12); //packet length, should be correct? 4 bytes each? socket.writeInt(3); socket.writeInt(6); socket.writeInt(9); socket.flush(); } Then I have this small server, written in Erlang: Code:start_nano_server() -> {ok, Listen} = gen_tcp:listen(2345, [binary, {packet, 0}, {reuseaddr, true}, {active, true}, {packet_size, 128}]), {ok, Socket} = gen_tcp:accept(Listen), gen_tcp:close(Listen), receive_data(Socket, []). receive_data(Socket, SoFar) -> receive {tcp,Socket,Bin} -> receive_data(Socket, [Bin|SoFar]); {tcp_closed,Socket} -> Bytes=list_to_binary(reverse(SoFar)), io:format("~p~n",[Bytes]) end. Now, no matter what I send from the client, I ALWAYS get [<<0,0,0,4,0,0,0,32>>] as the response. I can try writing bytes to the socket directly instead of ints, and I get the same thing. I can write more or less data, same result. UTF strings same result. Even when specifying "4" as the packet header length, I just get the same consistant result of [<<0,0,0,32>>] instead. I don't understand what I'm doing wrong here. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ryeguy1@REDACTED Mon Jan 5 01:18:55 2009 From: ryeguy1@REDACTED (Ryan Lepidi) Date: Sun, 4 Jan 2009 19:18:55 -0500 Subject: [erlang-questions] Flash client communication with Erlang Server problem In-Reply-To: References: Message-ID: This is an erlang problem, it seems. I have this code to test the client sending data, written in Actionscript 3: Code:var socket:Socket=new Socket("localhost", 2345); socket.addEventListener(Event.CONNECT, connected); private function connected(event:Event):void { socket.writeInt(12); //packet length, should be correct? 4 bytes each? socket.writeInt(3); socket.writeInt(6); socket.writeInt(9); socket.flush(); } Then I have this small server, written in Erlang: Code:start_nano_server() -> {ok, Listen} = gen_tcp:listen(2345, [binary, {packet, 0}, {reuseaddr, true}, {active, true}, {packet_size, 128}]), {ok, Socket} = gen_tcp:accept(Listen), gen_tcp:close(Listen), receive_data(Socket, []). receive_data(Socket, SoFar) -> receive {tcp,Socket,Bin} -> receive_data(Socket, [Bin|SoFar]); {tcp_closed,Socket} -> Bytes=list_to_binary(reverse(SoFar)), io:format("~p~n",[Bytes]) end. Now, no matter what I send from the client, I ALWAYS get [<<0,0,0,4,0,0,0,32>>] as the response. I can try writing bytes to the socket directly instead of ints, and I get the same thing. I can write more or less data, same result. UTF strings same result. Even when specifying "4" as the packet header length, I just get the same consistant result of [<<0,0,0,32>>] instead. I don't understand what I'm doing wrong here. -------------- next part -------------- An HTML attachment was scrubbed... URL: From vinoski@REDACTED Mon Jan 5 02:53:54 2009 From: vinoski@REDACTED (Steve Vinoski) Date: Sun, 4 Jan 2009 20:53:54 -0500 Subject: [erlang-questions] Flash client communication with Erlang Server problem In-Reply-To: References: Message-ID: <65b2728e0901041753oa07dff2n84feb4b7f23da46f@mail.gmail.com> On 1/4/09, Ryan Lepidi wrote: > This is an erlang problem, it seems. I have this code to test the client > sending data, written in Actionscript 3: > > > Code: > var socket:Socket=new Socket("localhost", 2345); > socket.addEventListener(Event.CONNECT, connected); > > private function connected(event:Event):void { > socket.writeInt(12); //packet length, should be correct? 4 bytes each? Sending a packet length isn't needed given your Erlang code, since you specify {packet, 0}. If you want packets to have a 4-byte length, you should specify {packet, 4} in your server. > socket.writeInt(3); > socket.writeInt(6); > socket.writeInt(9); > socket.flush(); > } Just curious: are these integers written big-endian or little-endian? > Then I have this small server, written in Erlang: > > > Code: > start_nano_server() -> > {ok, Listen} = gen_tcp:listen(2345, [binary, {packet, 0}, > {reuseaddr, true}, > {active, true}, > {packet_size, 128}]), > {ok, Socket} = gen_tcp:accept(Listen), > gen_tcp:close(Listen), > receive_data(Socket, []). > > receive_data(Socket, SoFar) -> > receive > {tcp,Socket,Bin} -> > receive_data(Socket, [Bin|SoFar]); > {tcp_closed,Socket} -> > Bytes=list_to_binary(reverse(SoFar)), > io:format("~p~n",[Bytes]) > end. > > Now, no matter what I send from the client, I ALWAYS get > [<<0,0,0,4,0,0,0,32>>] as the response. By "response" here, do you mean that your io:format call in your tcp_closed clause always prints <<0,0,0,4,0,0,0,32>> ? Also, just to be clear, are you really seeing [<<0,0,0,4,0,0,0,32>>], i.e., a binary within a list, or are you seeing just a binary? > I can try writing bytes to the > socket directly instead of ints, and I get the same thing. I can write more > or less data, same result. UTF strings same result. Even when specifying "4" > as the packet header length, I just get the same consistant result of > [<<0,0,0,32>>] instead. I don't understand what I'm doing wrong here. I took your code, compiled it with R12B-5 on OS X, and ran an Erlang client against it that did what your ActionScript code does, and it worked as expected. I ran a similar Python client against it, and that worked as expected too. I don't have ActionScript to try. So either the ActionScript client isn't doing what you think it is, or maybe some other client is interfering on that port (maybe try another port), or you're not showing us all the code. Have you tried using wireshark to see what's actually going across the network? --steve From kaiduanx@REDACTED Mon Jan 5 04:13:50 2009 From: kaiduanx@REDACTED (Kaiduan Xie) Date: Sun, 4 Jan 2009 22:13:50 -0500 Subject: [erlang-questions] get_stacktrace() question Message-ID: erlang:get_stacktrace() only returns the list of {Module, Function, Arity} (The Arity field in the first tuple may be the argument list of that function call instead of an arity integer, depending on the exception). Is there any way to return the argument list for ALL functions? Thanks, kaiduan -------------- next part -------------- An HTML attachment was scrubbed... URL: From sandeepkampati@REDACTED Mon Jan 5 06:34:32 2009 From: sandeepkampati@REDACTED (sandeep_k) Date: Sun, 4 Jan 2009 21:34:32 -0800 (PST) Subject: [erlang-questions] Query about wsdl file parsing and supporting tools Message-ID: <21285848.post@talk.nabble.com> Hi, Is there any library or tool that pare all kinds of WSDL file and make Soap request I has gone through erlsom it has lot of limitation, 1, it supports Soap 'document' binding style 2, erlsom is fetching lot of supporting files from outside world Thanks, sandeep.k -- View this message in context: http://www.nabble.com/Query-about-wsdl-file-parsing-and-supporting-tools-tp21285848p21285848.html Sent from the Erlang Questions mailing list archive at Nabble.com. From bgustavsson@REDACTED Mon Jan 5 08:22:13 2009 From: bgustavsson@REDACTED (Bjorn Gustavsson) Date: Mon, 5 Jan 2009 08:22:13 +0100 Subject: [erlang-questions] get_stacktrace() question In-Reply-To: References: Message-ID: <6672d0160901042322m727ad97ah98a9082e500a5e34@mail.gmail.com> 2009/1/5 Kaiduan Xie : > erlang:get_stacktrace() only returns the list of {Module, Function, Arity} > (The Arity field in the first tuple may be the argument list of that > function call instead of an arity integer, depending on the exception). Is > there any way to return the argument list for ALL functions? No. The way the BEAM virtual machine works, the arguments are discarded as soon as they are no longer needed. Only values that will be used again will be saved in the stack frame. /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB From jebenitez@REDACTED Mon Jan 5 07:52:10 2009 From: jebenitez@REDACTED (Jose Enrique Benitez Jimenez) Date: Mon, 5 Jan 2009 01:52:10 -0500 Subject: [erlang-questions] Yet Another Web Server Message-ID: Greetings, I want include a web server to my Erlang application, can I do this with YAWS? Thanks. From richardc@REDACTED Mon Jan 5 10:14:25 2009 From: richardc@REDACTED (Richard Carlsson) Date: Mon, 05 Jan 2009 10:14:25 +0100 Subject: [erlang-questions] get_stacktrace() question In-Reply-To: References: Message-ID: <4961CF71.3060507@it.uu.se> Kaiduan Xie wrote: > erlang:get_stacktrace() only returns the list of {Module, Function, Arity} > (The Arity field in the first tuple may be the argument list of that > function call instead of an arity integer, depending on the exception). Is > there any way to return the argument list for ALL functions? No. You could use tracing to get more information about your program, but the stacktrace functionality does not provide this. /Richard From erlang@REDACTED Mon Jan 5 11:29:49 2009 From: erlang@REDACTED (Peter Lund) Date: Mon, 05 Jan 2009 11:29:49 +0100 Subject: [erlang-questions] Best practice to hot update .hrl In-Reply-To: References: Message-ID: <4961E11D.5010109@lundata.se> My 2 eurocent: 1. You need to identify all .erl files that uses the updated part of in your .hrl file. 2. You need to identify processes that runs code those .erl (beam) files. 3. Then you a) suspend, b) update datastructures and c) resume these processes (if not more/all) /Peter Kaiduan Xie skrev: > Hi, > > OTP Design principles talks a lot on how to do release handling. > However it does not discuss the case where .hrl file is updated. For > example, how to deal the the following cases? > > 1. A new record is added, > 2. An element is removed/added from an existing record, > 3. A value of macro is changed. > > Thanks for inputs, > > kaiduan > > ------------------------------------------------------------------------ > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From jack@REDACTED Mon Jan 5 18:01:10 2009 From: jack@REDACTED (Jack Moffitt) Date: Mon, 5 Jan 2009 10:01:10 -0700 Subject: [erlang-questions] gethostbyname ipv6 timeouts Message-ID: <9b58f4550901050901o6f63a65ft81b5cf2ec7f071d5@mail.gmail.com> By default Erlang does ipv6 lookups and then falls back to ipv4 if that fails. Unfortunately for all my systems the ipv6 failure takes a long time (5-8 seconds) which means that any code I run using http:request (for example) is really crippled. I can work around the issue by using http:set_options([{ipv6, disabled}]) in my own code, but is there any way to actually fix the underlying issue? I've tried disabling IPv6 on the machine (not sure how to do this for lo0 interface though) and enabling it both on the machine and on the wifi router. Neither has made a difference. jack. From masse@REDACTED Mon Jan 5 17:38:04 2009 From: masse@REDACTED (mats cronqvist) Date: Mon, 05 Jan 2009 17:38:04 +0100 Subject: [erlang-questions] Best practice to hot update .hrl In-Reply-To: (Kaiduan Xie's message of "Fri\, 2 Jan 2009 16\:35\:07 -0500") References: Message-ID: <87tz8d7loz.fsf@sterlett.hq.kred> "Kaiduan Xie" writes: > Hi, > > OTP Design principles talks a lot on how to do release handling. However it > does not discuss the case where .hrl file is updated. For example, how to deal > the the following cases? > 1. A new record is added, > 2. An element is removed/added from an existing record, > 3. A value of macro is changed. included files (the .hrl suffix is just a convention) are inserted in the .erl file by the compiler. recompiling/reloading all .erl files that include your .hrl will cover the easy cases, i.e. when no process has the old version of the record/macro on the stack/in a register. this is why all long-lived processes should be gen_servers; you can use the code_change method to transform the state. but no matter how you do it, the combination records-upgrades will always suck. in this respect, proplists or dicts are much better if you can live with the (modest) preformance hit. mats From oscar@REDACTED Mon Jan 5 17:36:52 2009 From: oscar@REDACTED (=?ISO-8859-1?Q?Oscar_Hellstr=F6m?=) Date: Mon, 05 Jan 2009 16:36:52 +0000 Subject: [erlang-questions] spawn_link In-Reply-To: <2e23d1d20812311927t41666be8u330c337b5fb7734f@mail.gmail.com> References: <2e23d1d20812311927t41666be8u330c337b5fb7734f@mail.gmail.com> Message-ID: <49623724.9080100@erlang-consulting.com> Hi, Another side note embedded. David Budworth wrote: > quick side note. while John's answer is correct. I think that > Thilani is trying to spawn a short lived process that creates a socket > connection. > > problem with that is that when the call (connect_to_server) returns, > the process will exit and the socket will close since the socket lives > and dies with the process calling gen_tcp:connect(...) > > you could hand control over to another process to keep this from > happening, but this code is clearly not doing so. > the function is: > gen_tcp:controlling_process(Socket, NewSocketOwnerPid) > > but from a client perspective, this kind of defeats the purpose. > > what you really want to do is have the gen server initiate the > connection itself (from the init method most likely). Be careful with doing too much work (or at least calling blocking functions) in the init function of any worker since the supervisor is blocked until the child returns. If the supervisor is starting a lot of dynamic children this will become a bottleneck. Connecting a TCP socket can typically take a long time and will then stop any other child from being started until the connection has been made. > then it will own the process. and if it fails to connect, the gen > server will bomb out letting you know it failed. > > if you are trying to make the gen server "generic" and not understand > how the socket is created, you could always pass in a fun to > gen_server:start(M,[fun() -> gen_tcp:connect(...)]) > > then in your gen_server: > init([ConFun]) -> > {ok,Socket} = ConFun(). > > benefits are: > gen_server doesn't know how the socket is created, but it owns the > socket itself. so as long as the gen_server is alive, the socket > lives with it (unless closed by the other end). > > Hopefully that was helpful, > > -David > > > On Mon, Dec 29, 2008 at 10:39 AM, John Hughes > wrote: > > Hi Thilani, > > As Chandru said, you just send the result back to the parent > process as a > message. Here's some code: > > spawn_call(M,F,As) -> > Parent = self(), > Child = spawn_link(fun() -> Parent ! {self(),apply(M,F,As)} end), > receive {Child,X} -> X end. > > Note the receive matches on the child's pid, so can't be confused > by any > other messages in the parent's mailbox. Sample call: > > 76> foo:spawn_call(lists,reverse,[[1,2,3]]). > [3,2,1] > > John > > > From: "Thilani Abeysinghe" > > > Subject: [erlang-questions] spawn_link > > To: erlang-questions@REDACTED > > Message-ID: > > > > > Content-Type: text/plain; charset="iso-8859-1" > > > > I have a problem of how to get the return value of a function when > > > > spawn_link(Fun) ->pid() is used. > > > > Im going to use above function in following manner. > > > > init([]) -> > > > > ChildPid = erlang:spawn_link(?MODULE, connect_to_server, > [Ip,Port, ConId, > > self(),State]). > > > > connect_to_server(Ip, Port, ConId, ParentPid,State) -> > > case Result= gen_tcp:connect(Ip, Port, > > [binary, {packet, 0}]) of > > {ok, Socket} -> > > io:format("Socket Received:~w~n",[Socket]), > > ok =(catch gen_server:call(g_srv, {add_conn, self(), ConId, > > Socket})), > > NewState = State#state{socket= Socket}; > > {error, Reason} -> > > io:format("connection error host Ip:~w Port: ~w ~w ~n", > > [Ip,Port,Reason]) , > > connect_to_server(Ip, Port, ConId, ParentPid,State) > > end. > > > > I want to get the return value of connect_to_server function. > How can I do > > that. > > > > Regards > > > > Thilani > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > > > ------------------------------------------------------------------------ > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions Best regards -- Oscar Hellstr?m, oscar@REDACTED Office: +44 20 7655 0337 Mobile: +44 798 45 44 773 Erlang Training and Consulting http://www.erlang-consulting.com/ From oscar@REDACTED Mon Jan 5 16:27:03 2009 From: oscar@REDACTED (=?ISO-8859-1?Q?Oscar_Hellstr=F6m?=) Date: Mon, 05 Jan 2009 15:27:03 +0000 Subject: [erlang-questions] announce: yet-another-PostgreSQL driver In-Reply-To: References: Message-ID: <496226C7.1080005@erlang-consulting.com> Hi, Tried to clone it but the URL doesn't point to repository :/ Will wrote: > Hello, > > I've written a pure Erlang PostgreSQL driver, available here: > > hg clone http://glozer.net/src/epgsql > > Some highlights are: a simple interface, common db types returned as > native Erlang types, and binary format used for common types. > > -Will > > ------------------------------------------------------------------------ > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions Cheers -- Oscar Hellstr?m, oscar@REDACTED Office: +44 20 7655 0337 Mobile: +44 798 45 44 773 Erlang Training and Consulting http://www.erlang-consulting.com/ From wglozer@REDACTED Mon Jan 5 17:46:32 2009 From: wglozer@REDACTED (Will) Date: Mon, 5 Jan 2009 08:46:32 -0800 Subject: [erlang-questions] announce: yet-another-PostgreSQL driver In-Reply-To: <496226C7.1080005@erlang-consulting.com> References: <496226C7.1080005@erlang-consulting.com> Message-ID: On Mon, Jan 5, 2009 at 7:27 AM, Oscar Hellstr?m wrote: > Hi, > > Tried to clone it but the URL doesn't point to repository :/ > Ahh sorry, I'm not using the hgweb CGI script, so if you aren't using mercurial 1.1+ you'll need to use the static-http scheme: hg clone static-http://glozer.net/src/epgsql > Will wrote: > > Hello, > > > > I've written a pure Erlang PostgreSQL driver, available here: > > > > hg clone http://glozer.net/src/epgsql > > > > Some highlights are: a simple interface, common db types returned as > > native Erlang types, and binary format used for common types. > > > > -Will > > Cheers > > -- > Oscar Hellstr?m, oscar@REDACTED > Office: +44 20 7655 0337 > Mobile: +44 798 45 44 773 > Erlang Training and Consulting > http://www.erlang-consulting.com/ > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kaiduanx@REDACTED Mon Jan 5 20:43:10 2009 From: kaiduanx@REDACTED (Kaiduan Xie) Date: Mon, 5 Jan 2009 14:43:10 -0500 Subject: [erlang-questions] Best practice to hot update .hrl In-Reply-To: <87tz8d7loz.fsf@sterlett.hq.kred> References: <87tz8d7loz.fsf@sterlett.hq.kred> Message-ID: Many thanks for all the excellent explanations. Mats, can you explain a bit more on following? "In this respect, proplists or dicts are much better if you can live with the (modest) performance hit." Thanks, kaiduan On 1/5/09, mats cronqvist wrote: > > "Kaiduan Xie" writes: > > > Hi, > > > > OTP Design principles talks a lot on how to do release handling. However > it > > does not discuss the case where .hrl file is updated. For example, how to > deal > > the the following cases? > > 1. A new record is added, > > 2. An element is removed/added from an existing record, > > 3. A value of macro is changed. > > included files (the .hrl suffix is just a convention) are inserted > in the .erl file by the compiler. recompiling/reloading all .erl > files that include your .hrl will cover the easy cases, i.e. when no > process has the old version of the record/macro on the stack/in a > register. > > this is why all long-lived processes should be gen_servers; you can > use the code_change method to transform the state. but no matter how > you do it, the combination records-upgrades will always suck. in > this respect, proplists or dicts are much better if you can live > with the (modest) preformance hit. > > mats > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vinoski@REDACTED Tue Jan 6 04:51:21 2009 From: vinoski@REDACTED (Steve Vinoski) Date: Mon, 5 Jan 2009 22:51:21 -0500 Subject: [erlang-questions] Yet Another Web Server In-Reply-To: References: Message-ID: <65b2728e0901051951j11ff3f8bk20c7e634d0f25a63@mail.gmail.com> On 1/5/09, Jose Enrique Benitez Jimenez wrote: > > Greetings, > > I want include a web server to my Erlang application, can I do this with YAWS? Most definitely, it's very straightforward. See: --steve From nick@REDACTED Tue Jan 6 06:27:36 2009 From: nick@REDACTED (Nick Gerakines) Date: Mon, 5 Jan 2009 21:27:36 -0800 Subject: [erlang-questions] Yet Another Web Server In-Reply-To: References: Message-ID: Jose, There are several ways to go about it. I've got a few example applications on GitHub if you would like to see how its done. * http://github.com/ngerakines/facebook_wiiinfo/ -- An example Facebook application in Erlang, using Yaws in embedded mode * http://github.com/ngerakines/wrs/tree/master/wrsd -- A really small XML-based web service using MochiWeb * http://github.com/ngerakines/s3imagehost -- Another web service with Yaws, shows file uploads and content parsing # Nick Gerakines On Sun, Jan 4, 2009 at 10:52 PM, Jose Enrique Benitez Jimenez wrote: > > Greetings, > > I want include a web server to my Erlang application, can I do this with YAWS? > > Thanks. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From ed.stow@REDACTED Tue Jan 6 07:17:18 2009 From: ed.stow@REDACTED (Edward Stow) Date: Tue, 6 Jan 2009 17:17:18 +1100 Subject: [erlang-questions] xmerl documentation Message-ID: Hi, I am having a hard time working my way through some simple xml processing because I cannot understand the documentation. Q. From the xmerl reference, one of the exports is callbacks(M::atom()) -> [atom()] Find the list of inherited callback modules for a given module. What does the double colon notation mean : M::atom() in the above? What is the purpose of the function - what is an example of its usage. I tried this: 31> xmerl:callbacks(xmerl). ** exception error: undefined function xmerl:'#xml-inheritance#'/0 in function xmerl:check_inheritance/2 in call from xmerl:callbacks/1 32> xmerl:callbacks(xmerl_xml). [xmerl_xml] So what is the point? Another example: export_simple(Data::Content, Callback, RootAttrs::RootAttributes) -> ExportedFormat Types: Content = [Element] Callback = atom() RootAttributes = [XmlAttributes] Exports "simple-form" XML content, using the specified callback-module. Q: What are the atoms that can be used as the Callback. They are not defined in the reference manual. From reading the tutorial and list messages I know about xmerl_xml, and xmerl_html but have not seen any definitions of the effect of these on the content. Q: What is ExportedFormat ? AFAICT it is not defined in the reference manual. 27> Data. {ewaygateway,[{ewayCustomerID,["87654321"]}]} 28> xmerl:export_simple_content([Data], xmerl_xml). [[["<","ewaygateway",">"], [[["<","ewayCustomerID",">"], ["87654321"], [""]]], [""]]] 29> lists:flatten(xmerl:export_simple_content([Data], xmerl_xml)). "87654321" Anoher examle: export_simple_content(Data, Callback) -> term() Exports simple XML content directly, without further context. Comment: A term() is any erlang data structure -- but a list is returned. Comment: I would not call the output from this function 'simple XML content', I was expecting a string. Q. What is the 'context' that this and many other functions in xmerl can do without? Sorry for so many questions in total frustration .... -- Edward Stow From nc@REDACTED Tue Jan 6 07:57:12 2009 From: nc@REDACTED (Nicolas Charpentier) Date: Tue, 06 Jan 2009 07:57:12 +0100 Subject: [erlang-questions] code:lib_dir and dialyzer Message-ID: <496300C8.7010107@charpi.net> Hi, Running Dialyzer (1.8.3) on my code, I got an error on a call to code:lib_dir/1. Here is the code:lib_dir/1 source: %% XXX is_list() is for backwards compatibility -- take out in future version -spec lib_dir(App :: atom()) -> string() | {'error', 'bad_name'}. lib_dir(App) when is_atom(App) ; is_list(App) -> call({dir,{lib_dir,App}}). And here is my test code: test_lib_dir() -> Path = code:lib_dir(kernel), Path = code:lib_dir("kernel"). Both calls to code:lib_dir/1 are valid on a runtime system even if the clause with the string parameter is kept for backward compatibility Running Dialyzer on my code, I'm expecting an error like this: "The call code:lib_dir([101 | 107 | 108 | 110 | 114,...]) breaks the contract (atom()) -> string() | {'error', 'bad_name'}". But I got this one: "The call code:lib_dir([101 | 107 | 108 | 110 | 114,...]) will never return since it differs in argument position 1 from the success typing arguments: (atom())" Is it a dialyzer bug ? Additional information: - My PLT is up-to-date and contains the kernel application. - I'm running dialyzer from the source files. --- Nicolas Charpentier http://charpi.net From sandeepkampati@REDACTED Tue Jan 6 14:17:06 2009 From: sandeepkampati@REDACTED (sandeep_k) Date: Tue, 6 Jan 2009 05:17:06 -0800 (PST) Subject: [erlang-questions] Query about wsdl file parsing and supporting tools Message-ID: <21285848.post@talk.nabble.com> Hi, Is there any library or tool that pare all kinds of WSDL file and make Soap request I has gone through erlsom it has lot of limitation, - it supports Soap 'document' binding style - erlsom is fetching lot of supporting files from outside world Thanks, sandeep.k -- View this message in context: http://www.nabble.com/Query-about-wsdl-file-parsing-and-supporting-tools-tp21285848p21285848.html Sent from the Erlang Questions mailing list archive at Nabble.com. From francesco@REDACTED Tue Jan 6 17:28:00 2009 From: francesco@REDACTED (Francesco Cesarini (Erlang Training and Consulting)) Date: Tue, 06 Jan 2009 16:28:00 +0000 Subject: [erlang-questions] What websites/webapps use Erlang? In-Reply-To: References: Message-ID: <49638690.6070305@erlang-consulting.com> Just saw this thread. Other sites which are powered by Erlang Web are listed at http://www.erlang-web.org/about.html They include: http://www.erlang-web.org/ http://www.erlang-consulting.com/ http://www.protest-project.eu/ https://www.streamfile.com/ There are a few more in the pipeline which will be launched in the next few weeks / months. Regards, Francesco -- http://www.erlang-consulting.com Daniel Cer wrote: > On Tue, Dec 16, 2008 at 4:07 PM, Daniel Cer > wrote: > > > Does anyone here have an Erlang powered website or webapp? If you do, > would you mind sharing the URL and what other support components > you're using (e.g, ErlyWeb, Erlang-Web, MochiWeb, Mnesia, etc.)? > > > Thanks. The responses so far have been great. > > Any other sites that could be listed? It doesn't have to be anything > big, small personal projects are just fine. > > Also, would anybody mind if I listed their name with their site? This > would just be your name (e.g., 'Michael McDaniel'), and not your > e-mail address. > > -Dan > > > > ------------------------------------------------------------------------ > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From erlang@REDACTED Tue Jan 6 17:41:29 2009 From: erlang@REDACTED (Dominic Williams) Date: Tue, 6 Jan 2009 11:41:29 -0500 (EST) Subject: [erlang-questions] mocking libraries? In-Reply-To: <4960F7A1.5080902@moonpolysoft.com> References: <4960F7A1.5080902@moonpolysoft.com> Message-ID: Hi Cliff, > Does anyone know of any Erlang mocking libraries for testing? I'm > endeavoring to create my own, but I'd rather not reinvent the wheel. My recommendation, especially in Erlang, is to avoid mocking if possible (and in Erlang it is usually possible). If you are even tempted to mock it is quite likely that you are doing something un-erlangy ;-) Cf. previous posts: http://www.erlang.org/pipermail/erlang-questions/2006-September/022704.html http://www.erlang.org/pipermail/erlang-questions/2006-September/022712.html http://www.erlang.org/pipermail/erlang-questions/2008-May/035272.html http://www.erlang.org/pipermail/erlang-questions/2008-June/035544.html Regards, Dominic Williams http://dominicwilliams.net From rvirding@REDACTED Wed Jan 7 00:22:58 2009 From: rvirding@REDACTED (Robert Virding) Date: Wed, 7 Jan 2009 00:22:58 +0100 Subject: [erlang-questions] New version of Leex - a lexical analyser generator In-Reply-To: <3dbc6d1c0901011407x260b2a8es3b6d4b788723ed8e@mail.gmail.com> References: <3dbc6d1c0901011407x260b2a8es3b6d4b788723ed8e@mail.gmail.com> Message-ID: <3dbc6d1c0901061522x58b023d4y5a18b2f846dbc4a4@mail.gmail.com> I made a small mistake in the release in that the included ebin/leex.beam file was the old one and did not contain the new features. This has been corrected and the current file contains a new .beam file. Otherwise this is easily fixed by doing a "make compile". I apologize for the inconvenience, Robert 2009/1/1 Robert Virding > I have just released version 0.3 of Leex. New features and changes from the > previous version are: > > - Added options to push back characters into the input stream. > > - Can now handle full unicode character sets in both input file and > generated scanner. Of course i/o system can't generate such an input file > yet. > > - Enforce headings for all sections of .xrl file. > > - Added verbose flag to control printing of parsing information. > > - Fixed bug with completely empty erlang code section. > > You can get from either trapexit.org or github. The links are: > > http://forum.trapexit.org/viewtopic.php?p=44352#44352 > http://github.com/rvirding/leex/tree > > Robert > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gilbertbgarza@REDACTED Wed Jan 7 04:30:39 2009 From: gilbertbgarza@REDACTED (Gilbert B Garza) Date: Tue, 6 Jan 2009 21:30:39 -0600 Subject: [erlang-questions] Evaluating Erlang/erl_interface for the iPhone Message-ID: <5879e51d0901061930w170d4f6axff95fc96446c5a78@mail.gmail.com> Hello, I'm new to Erlang, and have been learning it for the past two weeks (and enjoying it, I might add). Currently I'm evaluating whether Erlang/erl_interface is a good choice to use for a server-side language for an iPhone application. The application will require a persistant connection to the Erlang server, as it will be constantly sending/receiving data. Does erl_interface function correctly in Objective-C, specifically in an iPhone environment? How does erl_interface handle connections when being used as a client? Thanks very much for any insight, -Gilbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From dgud@REDACTED Wed Jan 7 09:35:24 2009 From: dgud@REDACTED (Dan Gudmundsson) Date: Wed, 07 Jan 2009 09:35:24 +0100 Subject: [erlang-questions] SHA256 support in crypto In-Reply-To: <90E71B9E-207B-4718-86EC-DF6B3ED5DA22@sriramkrishnan.com> References: <90E71B9E-207B-4718-86EC-DF6B3ED5DA22@sriramkrishnan.com> Message-ID: <4964694C.6070406@erix.ericsson.se> Well check the code, it is in there but removed due to that some os'es have an old ssl version (cough *bsd) and I couldn't decide if we wanted an crypto api that maybe have some functions (i.e. depending on the ssl-version on the os). /Dan Sriram Krishnan wrote: > Are there plans to add sha256 support to the crypto module? I see a > patch at http://www.erlang.org/pipermail/erlang-patches/2007-June/000177.html > - will that be added to the official crypto module? > > -- > Sriram Krishnan > www.sriramkrishnan.com > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From sten.gruener@REDACTED Wed Jan 7 10:35:02 2009 From: sten.gruener@REDACTED (Sten Gruener) Date: Wed, 7 Jan 2009 10:35:02 +0100 Subject: [erlang-questions] [noob-question]: Run modules outside of the directory Message-ID: Hi, I have got a somehow noob question. I am trying to find a possibility to run a function from a module which is not inside of the directory. Is there a way to do it? Like modifying the path variable? Cheers, Sten From samb@REDACTED Wed Jan 7 07:53:01 2009 From: samb@REDACTED (Sam Bobroff) Date: Wed, 7 Jan 2009 17:53:01 +1100 Subject: [erlang-questions] Starting Erlang as a Unix daemon Message-ID: <20090107175301.3d64ee6d@samb-cm> Hello everyone, I'm working on a project in Erlang that needs to run as a daemon on a Unix machine. I would like to provide feedback from the init script that starts the daemon but I'm having trouble finding a good way of doing it. For example, I would like this to happen from the shell: # /etc/init.d/foo start Starting foo... OK or # /etc/init.d/foo start Starting foo... FAILED (If there was a fatal error during startup.) I've tried using both "run_erl" and "erl -detached" but both of them seem to fork and exit before any user code is run. Does anyone know a good way to handle this? Thanks in advance, Sam. -- Sam Bobroff | sam@REDACTED | M5 Networks From ulf.wiger@REDACTED Wed Jan 7 10:59:23 2009 From: ulf.wiger@REDACTED (Ulf Wiger (TN/EAB)) Date: Wed, 07 Jan 2009 10:59:23 +0100 Subject: [erlang-questions] [noob-question]: Run modules outside of the directory In-Reply-To: References: Message-ID: <49647CFB.50303@ericsson.com> The functions code:add_path([Dir|...]) and code:add_patha([Dir|...]) will do the trick. The code:add_path/1 function adds the list of directories to the end of the path, while code:add_patha/1 adds it to the beginning. The latter is useful if you want to load an alternative version of an existing module. BR, Ulf W Sten Gruener skrev: > Hi, > > I have got a somehow noob question. I am trying to find a possibility > to run a function from a module which is not inside of the directory. > Is there a way to do it? Like modifying the path variable? > > Cheers, > Sten > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From ext@REDACTED Wed Jan 7 11:06:44 2009 From: ext@REDACTED (David Sveningsson) Date: Wed, 07 Jan 2009 11:06:44 +0100 Subject: [erlang-questions] [noob-question]: Run modules outside of the directory In-Reply-To: References: Message-ID: <49647EB4.7040709@sidvind.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Sten Gruener wrote: > Hi, > > I have got a somehow noob question. I am trying to find a possibility > to run a function from a module which is not inside of the directory. > Is there a way to do it? Like modifying the path variable? > Hi, run erl with the -pa flag, like "erl -pa /path/to/files". You can read more about it in the man-pages. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAklkfrQACgkQ6pa1H/H5pqXgeACePKW1GQVL17pgoJYBvvTFyyRL rXAAnA+LsFeouivBQ4jc491uW2lXgHLA =gQfv -----END PGP SIGNATURE----- From puzza007@REDACTED Wed Jan 7 11:29:20 2009 From: puzza007@REDACTED (Paul Oliver) Date: Wed, 7 Jan 2009 10:29:20 +0000 Subject: [erlang-questions] SHA256 support in crypto In-Reply-To: <4964694C.6070406@erix.ericsson.se> References: <90E71B9E-207B-4718-86EC-DF6B3ED5DA22@sriramkrishnan.com> <4964694C.6070406@erix.ericsson.se> Message-ID: Hi, Steve Vinoski has just written an Erlang version ( http://steve.vinoski.net/blog/2009/01/03/more-sha-in-erlang/). Cheers, Paul. On Wed, Jan 7, 2009 at 8:35 AM, Dan Gudmundsson wrote: > Well check the code, it is in there but removed due to that some os'es have > an old > ssl version (cough *bsd) and I couldn't decide if we wanted an crypto api > that maybe have some functions (i.e. depending on the ssl-version on the > os). > > /Dan > > Sriram Krishnan wrote: > > Are there plans to add sha256 support to the crypto module? I see a > > patch at > http://www.erlang.org/pipermail/erlang-patches/2007-June/000177.html > > - will that be added to the official crypto module? > > > > -- > > Sriram Krishnan > > www.sriramkrishnan.com > > > > > > > > > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions@REDACTED > > http://www.erlang.org/mailman/listinfo/erlang-questions > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ryeguy1@REDACTED Wed Jan 7 11:29:26 2009 From: ryeguy1@REDACTED (Ryan Lepidi) Date: Wed, 7 Jan 2009 05:29:26 -0500 Subject: [erlang-questions] Shell doesn't seem to recognize code changes. Message-ID: Hello, I am new to Erlang so this is probably some stupid oversight. Basically, I have a module that is an implementation of gen_server. I start the server in the shell, execute some function, then terminate it. My problem is that if I change a function in the module, recompile it, and then execute it in the shell again (without closing the shell inbetween the compile), the OLD version of the function still remains - the only way to get my new functionality is to restart the shell. I make sure to terminate the server before starting it up again to test the modified function, and I have verified it is indeed stopping with processes(). Am I doing something wrong? -------------- next part -------------- An HTML attachment was scrubbed... URL: From bernie@REDACTED Wed Jan 7 11:34:31 2009 From: bernie@REDACTED (Bernard Duggan) Date: Wed, 07 Jan 2009 21:34:31 +1100 Subject: [erlang-questions] [noob-question]: Run modules outside of the directory In-Reply-To: References: Message-ID: <49648537.4040805@m5net.com> As an alternative to Ulf and David's suggestions, you can also set the ERL_LIBS environment variable to much the same effect. Any paths you provide in it will be searched in addition to the default ones. From memory, the separator for multiple paths is a colon. Cheers, Bernard Sten Gruener wrote: > Hi, > > I have got a somehow noob question. I am trying to find a possibility > to run a function from a module which is not inside of the directory. > Is there a way to do it? Like modifying the path variable? > > Cheers, > Sten > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From oscar@REDACTED Wed Jan 7 11:40:36 2009 From: oscar@REDACTED (=?ISO-8859-1?Q?Oscar_Hellstr=F6m?=) Date: Wed, 07 Jan 2009 10:40:36 +0000 Subject: [erlang-questions] Shell doesn't seem to recognize code changes. In-Reply-To: References: Message-ID: <496486A4.9080309@erlang-consulting.com> Hi, How do you compile the module? If you use erlc or erl -make outside of the shell you also need to load the new module in the shell. You can do that by executing l(ModuleName). A module is loaded by the code server the first time it is used (or at boot in embedded mode) and the loaded version will be kept until the something (user or program) tells the code server to reload the module. If a module is recompiled from the shell (using c/1 or c/2) the module will also be reloaded. Ryan Lepidi wrote: > Hello, > > I am new to Erlang so this is probably some stupid oversight. > Basically, I have a module that is an implementation of gen_server. I > start the server in the shell, execute some function, then terminate > it. My problem is that if I change a function in the module, recompile > it, and then execute it in the shell again (without closing the shell > inbetween the compile), the OLD version of the function still remains > - the only way to get my new functionality is to restart the shell. I > make sure to terminate the server before starting it up again to test > the modified function, and I have verified it is indeed stopping with > processes(). > > Am I doing something wrong? > ------------------------------------------------------------------------ > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions Best regards -- Oscar Hellstr?m, oscar@REDACTED Office: +44 20 7655 0337 Mobile: +44 798 45 44 773 Erlang Training and Consulting http://www.erlang-consulting.com/ From gleber.p@REDACTED Wed Jan 7 11:42:34 2009 From: gleber.p@REDACTED (Gleb Peregud) Date: Wed, 7 Jan 2009 11:42:34 +0100 Subject: [erlang-questions] Shell doesn't seem to recognize code changes. In-Reply-To: References: Message-ID: <14f0e3620901070242h58119eacheeb9b9914b3d8135@mail.gmail.com> 2009/1/7 Ryan Lepidi : > Hello, > > I am new to Erlang so this is probably some stupid oversight. Basically, I > have a module that is an implementation of gen_server. I start the server in > the shell, execute some function, then terminate it. My problem is that if I > change a function in the module, recompile it, and then execute it in the > shell again (without closing the shell inbetween the compile), the OLD > version of the function still remains - the only way to get my new > functionality is to restart the shell. I make sure to terminate the server > before starting it up again to test the modified function, and I have > verified it is indeed stopping with processes(). > > Am I doing something wrong? > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > You have to reload the module with l(module_name) to update module's code in the VM. Additionally take a look at module "code" Best regards, Gleb Peregud From ed.stow@REDACTED Wed Jan 7 12:04:54 2009 From: ed.stow@REDACTED (Edward Stow) Date: Wed, 7 Jan 2009 22:04:54 +1100 Subject: [erlang-questions] Record to Xml Message-ID: Hi I am trying to marshal an erlang record to a xml document. In my code the record field name becomes the element name. Is this a reasonable way to produce the Xml. I was hoping to be able to "iterate" over the field names (with a list comprehension perhaps) but I could not find a way to convert a record to a List in the form list( {fieldname1, value1}, {fieldname2, value2}). My attempts follow: -module(eway_xml). -compile(export_all). -import(xmerl). -record(ewayRequest, { ewayCustomerID, %required ewayCustomerFirstName, %required ewayCustomerLastName, %required ewayOption1 %optional }). asXml(EwayRecord) -> SimpleContent = asSimpleContent(EwayRecord), lists:flatten(xmerl:export_simple_content(SimpleContent, xmerl_xml)). asSimpleContent(EwayRequest) -> [{ewaygateway, [{ewayCustomerID, [EwayRequest#ewayRequest.ewayCustomerID]}, {ewayCustomerFirstName , [EwayRequest#ewayRequest.ewayCustomerFirstName ]}, {ewayCustomerLastName, [EwayRequest#ewayRequest.ewayCustomerLastName]}, {ewayOption1, [EwayRequest#ewayRequest.ewayOption1]} ] }]. testRecord() -> #ewayRequest{ ewayCustomerID = "87654321", ewayCustomerFirstName = "Jackie", ewayCustomerLastName = "Chan" }. Running form the command line produces the xml 12> eway_xml:asXml(eway_xml:testRecord()). "87654321JackieChan" -- Edward Stow From gordon@REDACTED Wed Jan 7 12:07:42 2009 From: gordon@REDACTED (Gordon Guthrie) Date: Wed, 7 Jan 2009 11:07:42 +0000 Subject: [erlang-questions] Shell doesn't seem to recognize code changes. In-Reply-To: References: Message-ID: The mochiweb stuff also includes a reloader module that will detect externally compiled changes and load them. It can be found here: http://code.google.com/p/mochiweb/source/browse/trunk/src/reloader.erl?r=65 Gordon 2009/1/7 Ryan Lepidi : > Hello, > > I am new to Erlang so this is probably some stupid oversight. Basically, I > have a module that is an implementation of gen_server. I start the server in > the shell, execute some function, then terminate it. My problem is that if I > change a function in the module, recompile it, and then execute it in the > shell again (without closing the shell inbetween the compile), the OLD > version of the function still remains - the only way to get my new > functionality is to restart the shell. I make sure to terminate the server > before starting it up again to test the modified function, and I have > verified it is indeed stopping with processes(). > > Am I doing something wrong? > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From ingela@REDACTED Wed Jan 7 12:08:53 2009 From: ingela@REDACTED (Ingela Anderton Andin) Date: Wed, 07 Jan 2009 12:08:53 +0100 Subject: [erlang-questions] openssl s_client hangs when accessing, https service in inets application In-Reply-To: References: Message-ID: <49648D45.3010700@erix.ericsson.se> erlang-questions-request@REDACTED wrote: Hi! Yes there is an inconsistency here which is the root to the problem of that https-servers does not always work as expected. The inets application has been around for quite some time and gone through some major rewrites, but with the need to keep old code around for quite some while to retain backwards compatibility unfortunately some legacy code did not get cleaned out creating the inconsistency. Alas the old-apache-like configuration files so to speak fixed the inconsistency so that it happens to work anyway. When modernizing the API we alas did not write an explicit test-case for using https (strictly speaking should not make any difference, have you heard that one before ;)), if we had we could have caught this a little earlier , but anyway this problem has already been fixed for the upcoming release. So the workaround until then is to use old style apache-like configuration files. Regards Ingela Erlang/OTP - Ericsson > Hi, > > The documentation and code of inets application are not consistent, > the corresponding option in {proplist_file, path()} to "SocketType" > option in {file, path()} is "com_type", not "socket_type". > > Liu Yubao wrote: > >> Hi, >> >> The https services in inets application doesn't work, I guess >> I got something wrong. Below is the steps to recur: >> >> a. use gen-cert.sh to generate server.pem; >> (All scripts and configuration are provided at >> http://jff.googlecode.com/files/inets-https-test.tar >> ) >> >> b. execute runerl.sh and input these clauses in the erlang shell: >> application:start(ssl). >> application:start(inets). >> >> c. execute `openssl s_client -connect localhost:8443 -debug -msg`, >> you can see openssl hangs after sending a CLIENT-HELLO message, >> the TCP connection is established successfully but https server >> doesn't response to the CLIENT-HELLO message. >> >> >> I tested "ssl:listen" in erlang shell and succeed to communication between >> openssl and erlang shell: >> >> application:start(ssl). >> {ok, S} = ssl:listen(8443, [{certfile, "server.pem"}, {active, false}]). >> {ok, S2} = ssl:accept(S). >> # execute in another bash: openssl s_client -connect localhost:8443 >> ssl:send(S2, <<"hello world\n">>). >> # "openssl s_client" can receive this greeting. >> >> >> I tested against the latest erlang 5.6.5 under Windows XP and 5.6.3 under >> Debian Lenny. >> >> I'm looking forward your help! >> >> From torben.lehoff@REDACTED Wed Jan 7 13:27:39 2009 From: torben.lehoff@REDACTED (Torben Hoffmann) Date: Wed, 7 Jan 2009 13:27:39 +0100 Subject: [erlang-questions] Record to Xml In-Reply-To: References: Message-ID: On Wed, Jan 7, 2009 at 12:04 PM, Edward Stow wrote: > Hi > > I am trying to marshal an erlang record to a xml document. In my code > the record field name becomes the element name. > > Is this a reasonable way to produce the Xml. > > I was hoping to be able to "iterate" over the field names (with a list > comprehension perhaps) but I could not > find a way to convert a record to a List in the form You should have a look at the preprocessor function record_info/2 which could give you a list of the field names like this: FieldNames = record_info(fields,ewayRequest), The problem is that the record name has to be known at compile time so you need a function along these lines: record_fields(#evayRequest{}) -> record_info(fields,ewayRequest); record_fields(#other_record{}) -> record_info(fields, other_record). The downside is that you need to add a clause every time you define a new record. The record_fields could be auto-generated using a script by keeping all record definitions in a .hrl file and generate a module with the record_fields function. Any scripting language will suffice here - I have used both sed and Erlang for the job in the past. When you have record_fields/2 in your hands you have to get all the values out of the record which can be done by mis-using the fact that the internal representation of a record is a tuple where the first value is the name of the record. Then zip the two lists and you are done. Is this ugly? Yes. Will it work? Yes - I have it working and live with the pain. I would also recommend that you take a look at ehtml and how it is used in yaws. In the yaws_api.erl file you will find a function that translates ehtml to html and I am pretty sure that function will generate good, clean XML for you as well. Cheers, Torben > > list( {fieldname1, value1}, {fieldname2, value2}). > > My attempts follow: > > -module(eway_xml). > -compile(export_all). > -import(xmerl). > > -record(ewayRequest, { > ewayCustomerID, %required > ewayCustomerFirstName, %required > ewayCustomerLastName, %required > ewayOption1 %optional > }). > > asXml(EwayRecord) -> > SimpleContent = asSimpleContent(EwayRecord), > lists:flatten(xmerl:export_simple_content(SimpleContent, xmerl_xml)). > > asSimpleContent(EwayRequest) -> > [{ewaygateway, > [{ewayCustomerID, [EwayRequest#ewayRequest.ewayCustomerID]}, > {ewayCustomerFirstName , > [EwayRequest#ewayRequest.ewayCustomerFirstName ]}, > {ewayCustomerLastName, > [EwayRequest#ewayRequest.ewayCustomerLastName]}, > {ewayOption1, [EwayRequest#ewayRequest.ewayOption1]} > ] > }]. > > testRecord() -> > #ewayRequest{ > ewayCustomerID = "87654321", > ewayCustomerFirstName = "Jackie", > ewayCustomerLastName = "Chan" > }. > > Running form the command line produces the xml > > 12> eway_xml:asXml(eway_xml:testRecord()). > > "87654321JackieChan" > > > > > > -- > > Edward Stow > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From saleyn@REDACTED Wed Jan 7 14:07:46 2009 From: saleyn@REDACTED (Serge Aleynikov) Date: Wed, 07 Jan 2009 08:07:46 -0500 Subject: [erlang-questions] [noob-question]: Run modules outside of the directory In-Reply-To: <49648537.4040805@m5net.com> References: <49648537.4040805@m5net.com> Message-ID: <4964A922.10201@gmail.com> One caveat to this is that if that module is not located in the /path/to/*/ebin directory (i.e. ending with "ebin" subdir) the ERL_LIBS setting won't find it, whereas "erl -pa /path/to/some/dir" option will. Bernard Duggan wrote: > As an alternative to Ulf and David's suggestions, you can also set the > ERL_LIBS environment variable to much the same effect. Any paths you > provide in it will be searched in addition to the default ones. From > memory, the separator for multiple paths is a colon. > > Cheers, > > Bernard > > Sten Gruener wrote: >> Hi, >> >> I have got a somehow noob question. I am trying to find a possibility >> to run a function from a module which is not inside of the directory. >> Is there a way to do it? Like modifying the path variable? >> >> Cheers, >> Sten >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions@REDACTED >> http://www.erlang.org/mailman/listinfo/erlang-questions > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From ulf.wiger@REDACTED Wed Jan 7 14:25:15 2009 From: ulf.wiger@REDACTED (Ulf Wiger (TN/EAB)) Date: Wed, 07 Jan 2009 14:25:15 +0100 Subject: [erlang-questions] Record to Xml In-Reply-To: References: Message-ID: <4964AD3B.7010609@ericsson.com> Torben Hoffmann skrev: > > You should have a look at the preprocessor function record_info/2 which > could give you a list of the field names like this: > > FieldNames = record_info(fields,ewayRequest), > > The problem is that the record name has to be known at compile time so > you need a function along these lines: > > record_fields(#evayRequest{}) -> > record_info(fields,ewayRequest); > record_fields(#other_record{}) -> > record_info(fields, other_record). > > The downside is that you need to add a clause every time you define a > new record. > The record_fields could be auto-generated using a script by keeping all > record definitions in a .hrl file and generate a module with the > record_fields function. Any scripting language will suffice here - I > have used both sed and Erlang for the job in the past. You can also use the exprecs library which does exactly this, and then some, via a parse transform. http://forum.trapexit.org/viewtopic.php?p=21790#21790 BR, Ulf W From thomasl_erlang@REDACTED Wed Jan 7 13:39:10 2009 From: thomasl_erlang@REDACTED (Thomas Lindgren) Date: Wed, 7 Jan 2009 04:39:10 -0800 (PST) Subject: [erlang-questions] get_stacktrace() question In-Reply-To: <4961CF71.3060507@it.uu.se> Message-ID: <675165.80394.qm@web111411.mail.gq1.yahoo.com> --- On Mon, 1/5/09, Richard Carlsson wrote: > Kaiduan Xie wrote: > > erlang:get_stacktrace() only returns the list of > {Module, Function, Arity} > > (The Arity field in the first tuple may be the > argument list of that > > function call instead of an arity integer, depending > on the exception). Is > > there any way to return the argument list for ALL > functions? > > No. You could use tracing to get more information about > your program, > but the stacktrace functionality does not provide this. Unfortunately, it seems difficult to get this right -- parameters are normally passed in beam registers x(0)...x(N-1), but these registers are basically reused at each call, with only live parameters (or subterms of parameters) saved in the stack frame. So not all variables may be available. The curse of efficiency, I guess. One approach might be to add a debug mode where parameters are passed on the stack instead, but that's somewhat nontrivial compiler surgery. Also, doing this introduces space leaks: it hangs on to values after they ought to be dead. And undead values can't be GCd. (Could the erlang interpreter do stacktraces right? I haven't tried using it in ages ...) Best, Thomas From torben.lehoff@REDACTED Wed Jan 7 14:59:34 2009 From: torben.lehoff@REDACTED (Torben Hoffmann) Date: Wed, 7 Jan 2009 14:59:34 +0100 Subject: [erlang-questions] Record to Xml In-Reply-To: <4964AD3B.7010609@ericsson.com> References: <4964AD3B.7010609@ericsson.com> Message-ID: On Wed, Jan 7, 2009 at 2:25 PM, Ulf Wiger (TN/EAB) wrote: > Torben Hoffmann skrev: > >> >> You should have a look at the preprocessor function record_info/2 which >> could give you a list of the field names like this: >> >> FieldNames = record_info(fields,ewayRequest), >> >> The problem is that the record name has to be known at compile time so you >> need a function along these lines: >> >> record_fields(#evayRequest{}) -> >> record_info(fields,ewayRequest); >> record_fields(#other_record{}) -> >> record_info(fields, other_record). >> >> The downside is that you need to add a clause every time you define a new >> record. >> The record_fields could be auto-generated using a script by keeping all >> record definitions in a .hrl file and generate a module with the >> record_fields function. Any scripting language will suffice here - I have >> used both sed and Erlang for the job in the past. >> > > You can also use the exprecs library which does exactly this, > and then some, via a parse transform. > > http://forum.trapexit.org/viewtopic.php?p=21790#21790 > > BR, > Ulf W > Bummer - I should have googled this a lot better before I wrote my own code. Thanks for the tip, Torben -------------- next part -------------- An HTML attachment was scrubbed... URL: From ext@REDACTED Wed Jan 7 15:01:59 2009 From: ext@REDACTED (David Sveningsson) Date: Wed, 07 Jan 2009 15:01:59 +0100 Subject: [erlang-questions] dialyzer fails when using packages and -r Message-ID: <4964B5D7.4000501@sidvind.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I ran into some issues when trying to run dialyzer on some source code I wrote. I rewrote a module called discovery into a package in the src/discovery directory. I want to run dialyzer to analyze the code and the package. Dialyzer worked fine before the splitting to a package. Any ideas what might be wrong? % dialyzer -r src -I include --src -DSVN_REVISION=\"1020M\" -Werror_handling Checking whether the PLT /Users/ext/.dialyzer_plt is up-to-date... yes Proceeding with analysis... =ERROR REPORT==== 7-Jan-2009::14:50:45 === Error in process <0.30.0> with exit value: {function_clause,[{dict,fetch_val,['discovery.com',[]]},{dialyzer_codeserver,fetch_and_expand,2},{dialyzer_codeserver,table__loop,2}]} Analysis failed with error: {function_clause,[{dict,fetch_val,['discovery.com',[]]}, {dialyzer_codeserver,fetch_and_expand,2}, {dialyzer_codeserver,table__loop,2}]} Last messages in log cache: ["Typesig analysis for scc: [{network,get_ip,1}]\n", "Typesig analysis for scc: [{network,match_ip,2}]\n", "Typesig analysis for scc: [{network,validate_local_ip,1}]\n", "Typesig analysis for scc: [{discovery,module_info,1}]\n", "Typesig analysis for scc: [{discovery,flush,0}]\n", "Typesig analysis for scc: [{discovery,match_field,2}]\n", "Typesig analysis for scc: [{discovery,module_info,0}]\n", "Typesig analysis for scc: [{discovery,match_entry,2}]\n", "Typesig analysis for scc: [{discovery,match,2}]\n", "Typesig analysis for scc: [{'discovery.com',module_info,0}]\n"] dialyzer: Internal problems were encountered in the analysis. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAklktdcACgkQ6pa1H/H5pqUzFwCglX/4MGyutsaDUTntdNRf4JRY LuoAn2Cb97h7f1RLe7UydQmwQPNyVXkh =+liL -----END PGP SIGNATURE----- From masse@REDACTED Wed Jan 7 15:08:55 2009 From: masse@REDACTED (mats cronqvist) Date: Wed, 07 Jan 2009 15:08:55 +0100 Subject: [erlang-questions] Best practice to hot update .hrl In-Reply-To: (Kaiduan Xie's message of "Mon\, 5 Jan 2009 14\:43\:10 -0500") References: <87tz8d7loz.fsf@sterlett.hq.kred> Message-ID: <87ljtn6weg.fsf@sterlett.hq.kred> "Kaiduan Xie" writes: > "In this respect, proplists or dicts are much better if you can live with the > (modest) performance hit." a record is really a tuple. -define(rec,{a="A",b="B"}). Rec = #rec{}. In this case, Rec will be {rec,"A","B"}. If you change the record definition, and there is a old version of Rec hanging around somewhere (e.g. in Mnesia, on another node, on the stack), you can't access ANY field in that record using the record syntax(*). Real dicts obviously does not have this problem. mats (*) unless you have a module for each version of the record, and no two record versions have the same length. This "solution" is of course completly idiotic. From kostis@REDACTED Wed Jan 7 15:22:23 2009 From: kostis@REDACTED (Kostis Sagonas) Date: Wed, 07 Jan 2009 16:22:23 +0200 Subject: [erlang-questions] code:lib_dir and dialyzer In-Reply-To: <496300C8.7010107@charpi.net> References: <496300C8.7010107@charpi.net> Message-ID: <4964BA9F.40805@cs.ntua.gr> Nicolas Charpentier wrote: > Hi, > > Running Dialyzer (1.8.3) on my code, I got an error on a call to > code:lib_dir/1. > > Here is the code:lib_dir/1 source: > %% XXX is_list() is for backwards compatibility -- take out in future > version > -spec lib_dir(App :: atom()) -> string() | {'error', 'bad_name'}. > lib_dir(App) when is_atom(App) ; is_list(App) -> call({dir,{lib_dir,App}}). > > And here is my test code: > test_lib_dir() -> > Path = code:lib_dir(kernel), > Path = code:lib_dir("kernel"). > > Both calls to code:lib_dir/1 are valid on a runtime system even if the > clause with the string parameter is kept for backward compatibility > > Running Dialyzer on my code, I'm expecting an error like this: > "The call code:lib_dir([101 | 107 | 108 | 110 | 114,...]) breaks the > contract (atom()) -> string() | {'error', 'bad_name'}". > > But I got this one: > "The call code:lib_dir([101 | 107 | 108 | 110 | 114,...]) will never > return since it differs in argument position 1 from the success typing > arguments: (atom())" > > > Is it a dialyzer bug ? In some sense yes, but I would really describe/classify this as an inconsistency more than a bug. The problem is that Dialyzer (still) has hard-coded information about some library functions in hipe/cerl/erl_bif_types.erl. This information pre-dates the language of contracts and shadows the -spec information. For the function in question dialyzer knows that: arg_types(code, lib_dir, 1) -> [t_atom()]; which explains why you get the error message that you get. Now that contracts are present in code, arguably this information is no longer needed and can (should?) be taken out -- at least for functions of this module. Regardless, I would suggest that you fix your code to adhere to the published documentation and use code:lib_dir/1 with a string() instead. Kostis From kostis@REDACTED Wed Jan 7 15:30:01 2009 From: kostis@REDACTED (Kostis Sagonas) Date: Wed, 07 Jan 2009 16:30:01 +0200 Subject: [erlang-questions] dialyzer fails when using packages and -r In-Reply-To: <4964B5D7.4000501@sidvind.com> References: <4964B5D7.4000501@sidvind.com> Message-ID: <4964BC69.10302@cs.ntua.gr> David Sveningsson wrote: > > Hi, I ran into some issues when trying to run dialyzer on some source > code I wrote. I rewrote a module called discovery into a package in the > src/discovery directory. I want to run dialyzer to analyze the code and > the package. Dialyzer worked fine before the splitting to a package. Any > ideas what might be wrong? This is a known issue. Dialyzer does not support packages (at least not yet) but the situation is not that different than those of many other tools that manipulating Erlang code, which currently do not support packages either. Supporting packages is on our TODO list, but its priority is quite low and the decision to promote it to a higher priority is to some extent dependent on the general future of packages in Erlang. Kostis PS. Personally, I am positively inclined towards packages, but only mildly so. From ext@REDACTED Wed Jan 7 15:42:13 2009 From: ext@REDACTED (David Sveningsson) Date: Wed, 07 Jan 2009 15:42:13 +0100 Subject: [erlang-questions] dialyzer fails when using packages and -r In-Reply-To: <4964BC69.10302@cs.ntua.gr> References: <4964B5D7.4000501@sidvind.com> <4964BC69.10302@cs.ntua.gr> Message-ID: <4964BF45.4060207@sidvind.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Kostis Sagonas wrote: > David Sveningsson wrote: >> >> Hi, I ran into some issues when trying to run dialyzer on some source >> code I wrote. I rewrote a module called discovery into a package in the >> src/discovery directory. I want to run dialyzer to analyze the code and >> the package. Dialyzer worked fine before the splitting to a package. Any >> ideas what might be wrong? > > This is a known issue. Dialyzer does not support packages (at least not > yet) but the situation is not that different than those of many other > tools that manipulating Erlang code, which currently do not support > packages either. Supporting packages is on our TODO list, but its > priority is quite low and the decision to promote it to a higher > priority is to some extent dependent on the general future of packages > in Erlang. > > Kostis > > PS. Personally, I am positively inclined towards packages, but only > mildly so. > Ok, thanks for the info. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAklkv0UACgkQ6pa1H/H5pqWNeACeMM2x5mS4EpqO4Tph0iW+xmVh wVsAnilPYRg94oEBNhdLXxU3EOpZEMB8 =RPaG -----END PGP SIGNATURE----- From rtrlists@REDACTED Wed Jan 7 17:10:13 2009 From: rtrlists@REDACTED (Robert Raschke) Date: Wed, 7 Jan 2009 16:10:13 +0000 Subject: [erlang-questions] Calling into Lua from Erlang Message-ID: <6a3ae47e0901070810n5184c90brc8f230452c88e0ba@mail.gmail.com> Hi, I will need to call Lua scripts from within Erlang soon. I was wondering if anyone has already looked into a slightly closer binding than calling an external program to run the Lua script and marshalling via stdin/out? I am currently undecided whether to make the Lua API available to be invoked from Erlang (via a linked-in driver) or if it might be more useful to write a Lua library that allows a Lua script to function as an Erlang node (similar to the Erlang Jinterface lib for Java). I would gratefully receive opinions and wisdom on this kind of stuff? Thanks, Robby From icfp.publicity@REDACTED Wed Jan 7 17:40:57 2009 From: icfp.publicity@REDACTED (Matthew Fluet (ICFP Publicity Chair)) Date: Wed, 7 Jan 2009 10:40:57 -0600 Subject: [erlang-questions] ICFP: Child care at conference Message-ID: <53ff55480901070840mcae4976k54a349abcea58fbe@mail.gmail.com> Potential ICFP attendees: The ACM-SIGPLAN Executive Committee, which oversees and sponsors ICFP, is considering expanding its travel grants for event participants in need of child care assistance. (Such expansion would also apply to other major SIGPLAN-sponsored conferences, such as PLDI, POPL, OOPSLA.) The purpose of this message is to solicit feedback from potential attendees regarding the desirability for child care assistance and what forms of assistance be most appropriate. If child care assistance at ICFP (or other SIGPLAN events) is of interest to you, please contact me (at icfp.publicity@REDACTED -or- fluet@REDACTED) with your comments. Some questions of particular interest: * What age groups of children are most appropriate to cover? * What types of costs might SIGPLAN cover to facilitate your participation in events? Sincerely, -Matthew Fluet (ICFP Publicity Chair) From geoff.cant@REDACTED Wed Jan 7 18:47:09 2009 From: geoff.cant@REDACTED (Geoff Cant) Date: Wed, 07 Jan 2009 18:47:09 +0100 Subject: [erlang-questions] Stuck disk_log_server Message-ID: Hi all, I have discovered a weird problem on a customer cluster - mnesia experiencing overload/dump_log problems that appear to be due to a broken disk_log_server process. The system involved is R12B-3 running on 64 bit debian linux. The backtrace and process_info for the disk_log_server process are: Program counter: 0x00007f61c4365af8 (gen_server:loop/6 + 288) CP: 0x00007f61c0e23fe8 (proc_lib:init_p/5 + 400) arity = 0 0x00007f60fb043f78 Return addr 0x00007f61c0e23fe8 (proc_lib:init_p/5 + 400) y(0) [] y(1) infinity y(2) disk_log_server y(3) {state,[]} y(4) disk_log_server y(5) <0.30.0> 0x00007f60fb043fb0 Return addr 0x000000000084bd18 () y(0) Catch 0x00007f61c0e24008 (proc_lib:init_p/5 + 432) y(1) gen y(2) init_it y(3) [gen_server,<0.30.0>,<0.30.0>,{local,disk_log_server},disk_log_server,[],[]] process_info(whereis(disk_log_server)). [{registered_name,disk_log_server}, {current_function,{gen_server,loop,6}}, {initial_call,{proc_lib,init_p,5}}, {status,waiting}, {message_queue_len,1}, {messages,[{'$gen_call',{<0.22681.260>,#Ref<0.0.992.227035>}, {close,<0.22681.260>}}]}, {links,[<0.111.0>,<0.22677.260>,<0.22681.260>,<0.30.0>]}, {dictionary,[{<0.111.0>,latest_log}, {<0.22677.260>,previous_log}, {'$ancestors',[kernel_safe_sup,kernel_sup,<0.8.0>]}, {<0.22681.260>,decision_tab}, {'$initial_call',{gen,init_it, [gen_server,<0.30.0>,<0.30.0>, {local,disk_log_server}, disk_log_server,[],[]]}}]}, {trap_exit,true}, {error_handler,error_handler}, {priority,normal}, {group_leader,<0.7.0>}, {total_heap_size,246}, {heap_size,233}, {stack_size,12}, {reductions,2366165}, {garbage_collection,[{fullsweep_after,0},{minor_gcs,0}]}, {suspending,[]}] We think it's this process as mnesia_controller:get_workers(2000) shows a dumper pid of <0.22676.260> whose backtrace showed it waiting for a gen_call response in mnesia_log:save_decision_tab/1 (doing {close_log, decision_tab}) from <0.62.0> (mnesia_monitor) which itself was waiting for a reply in disk_log:monitor_request/2 from the decision_tab disk_log process (<0.22681.260>) which was waiting for an answer to gen_server:call(disk_log_server, {close, <0.22681.260>}) which seems to be stuck in disk_log_server's message queue. *phew* The status of disk_log_server is 'waiting', but it has a message in its queue and it appears to be sitting in gen_server:loop/6 - why wouldn't it be making progress? Any ideas would be appreciated here. The server has been scheduled for a restart and we're hoping mnesia can limp on until then without any log dumps (or probably any disk_log activity on the node at all). I investigated doing some kind of evil manual restart of the disk_log_server process + manual repopulation of its ets tables and a fake reply to the decision_log process, but disk_log_server lives under kernel_safe_sup indicating that fooling with it is likely to have dire consequences. For future reference, is it worth trying something like that to save a node restart? Cheers, -- Geoff Cant From rvirding@REDACTED Wed Jan 7 20:08:16 2009 From: rvirding@REDACTED (Robert Virding) Date: Wed, 7 Jan 2009 20:08:16 +0100 Subject: [erlang-questions] How implicit inlining works? In-Reply-To: <20090104210924.C3BDC24013@relay.gooddata.com> References: <20090104210924.C3BDC24013@relay.gooddata.com> Message-ID: <3dbc6d1c0901071108i4562abbalc4ec0ebbb5503a46@mail.gmail.com> How do you mean that you have never seen it work? You shouldn't see anything, the code should behave as before. Robert 2009/1/4 Hynek Vychodil > Hello everybody, > I want ask how in-lining works. In documentation > http://www.erlang.org/doc/man/compile.html I can read how to switch on > implicit inlining > > %% Aggressive inlining - will increase code size. > -compile(inline). > -compile({inline_size,100}). > > but I never have seen it works. When I want inline something I must specify > it explicitly using > > -compile({inline, [{fun, arity}]}). > > Is it bug or I do something wrong? > > Best regards. > > -- > --Hynek (Pichi) Vychodil > > Analyze your data in minutes. Share your insights instantly. Thrill your > boss. Be a data hero! > Try Good Data now for free: www.gooddata.com > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pjdtech2000@REDACTED Wed Jan 7 20:26:38 2009 From: pjdtech2000@REDACTED (PJ Durai) Date: Wed, 7 Jan 2009 19:26:38 +0000 (UTC) Subject: [erlang-questions] Calling into Lua from Erlang References: <6a3ae47e0901070810n5184c90brc8f230452c88e0ba@mail.gmail.com> Message-ID: Robert Raschke googlemail.com> writes: > > Hi, > > I will need to call Lua scripts from within Erlang soon. I was > wondering if anyone has already looked into a slightly closer binding > than calling an external program to run the Lua script and marshalling > via stdin/out? > > I am currently undecided whether to make the Lua API available to be > invoked from Erlang (via a linked-in driver) or if it might be more > useful to write a Lua library that allows a Lua script to function as > an Erlang node (similar to the Erlang Jinterface lib for Java). > > I would gratefully receive opinions and wisdom on this kind of stuff? Aren't linked in drivers supposed to be dangerous in general? A bug in the C code can destabilize Erlang VM. I would vote for Option 'Lua node'. You can have multiple Lua VM's on multiple threads processing requests coming in from Erlang nodes. The possibilities are interesting. From dae@REDACTED Wed Jan 7 20:40:59 2009 From: dae@REDACTED (Doug Edmunds) Date: Wed, 7 Jan 2009 11:40:59 -0800 (PST) Subject: [erlang-questions] appearance of [8] and [9] in shell Message-ID: <21338764.post@talk.nabble.com> I want [8] to look like [8] instead of "\b", and [9] to look like [9] instead of "\t", when printing to the shell. 4> [8]. "\b" 5> [9]. "\t" Is there a shell setting control this? - Doug Edmunds -- View this message in context: http://www.nabble.com/appearance-of--8--and--9--in-shell-tp21338764p21338764.html Sent from the Erlang Questions mailing list archive at Nabble.com. From michael.truog@REDACTED Wed Jan 7 21:37:01 2009 From: michael.truog@REDACTED (michael.truog@REDACTED) Date: Wed, 7 Jan 2009 22:37:01 +0200 Subject: [erlang-questions] Calling into Lua from Erlang In-Reply-To: References: <6a3ae47e0901070810n5184c90brc8f230452c88e0ba@mail.gmail.com> Message-ID: An erlang port (reading from stdin/stdout in a separate OS process) could be used. If there were absolutely no errors, it would be trivial to switch it to an erlang port driver (running as a VM process in a more efficient way), but that is at your own risk of being harder to debug. -----Original Message----- From: erlang-questions-bounces@REDACTED [mailto:erlang-questions-bounces@REDACTED] On Behalf Of ext PJ Durai Sent: Wednesday, January 07, 2009 11:27 AM To: erlang-questions@REDACTED Subject: Re: [erlang-questions] Calling into Lua from Erlang Robert Raschke googlemail.com> writes: > > Hi, > > I will need to call Lua scripts from within Erlang soon. I was > wondering if anyone has already looked into a slightly closer binding > than calling an external program to run the Lua script and marshalling > via stdin/out? > > I am currently undecided whether to make the Lua API available to be > invoked from Erlang (via a linked-in driver) or if it might be more > useful to write a Lua library that allows a Lua script to function as > an Erlang node (similar to the Erlang Jinterface lib for Java). > > I would gratefully receive opinions and wisdom on this kind of stuff? Aren't linked in drivers supposed to be dangerous in general? A bug in the C code can destabilize Erlang VM. I would vote for Option 'Lua node'. You can have multiple Lua VM's on multiple threads processing requests coming in from Erlang nodes. The possibilities are interesting. _______________________________________________ erlang-questions mailing list erlang-questions@REDACTED http://www.erlang.org/mailman/listinfo/erlang-questions From mbj@REDACTED Wed Jan 7 21:54:38 2009 From: mbj@REDACTED (Martin Bjorklund) Date: Wed, 07 Jan 2009 21:54:38 +0100 (CET) Subject: [erlang-questions] Stuck disk_log_server In-Reply-To: References: Message-ID: <20090107.215438.92189511.mbj@tail-f.com> Hi, Geoff Cant wrote: > > Hi all, I have discovered a weird problem on a customer cluster - mnesia > experiencing overload/dump_log problems that appear to be due to a > broken disk_log_server process. Are you sure it's really stuck? I.e. if you do process_info() some time later, is the reductions the same? /martin From geoff.cant@REDACTED Wed Jan 7 23:19:02 2009 From: geoff.cant@REDACTED (Geoff Cant) Date: Wed, 07 Jan 2009 23:19:02 +0100 Subject: [erlang-questions] Stuck disk_log_server In-Reply-To: <20090107.215438.92189511.mbj@tail-f.com> (Martin Bjorklund's message of "Wed, 07 Jan 2009 21:54:38 +0100 (CET)") References: <20090107.215438.92189511.mbj@tail-f.com> Message-ID: Martin Bjorklund writes: > Hi, > > Geoff Cant wrote: >> >> Hi all, I have discovered a weird problem on a customer cluster - mnesia >> experiencing overload/dump_log problems that appear to be due to a >> broken disk_log_server process. > > Are you sure it's really stuck? I.e. if you do process_info() some > time later, is the reductions the same? I'm reasonably sure it was stuck - the reductions stayed the same for at least 30s with that message in the queue. There didn't appear to be a huge number of outstanding log dumping jobs that were all slowly making progress - just the one sitting there (for a long time - more than a few minutes) waiting for a reply from disk_log_server while the disk_log_server wasn't consuming its message queue. Cheers, --Geoff From andreas.koehler@REDACTED Wed Jan 7 22:44:57 2009 From: andreas.koehler@REDACTED (=?ISO-8859-1?Q?Andreas_K=F6hler?=) Date: Wed, 07 Jan 2009 22:44:57 +0100 Subject: [erlang-questions] Stuck disk_log_server In-Reply-To: <20090107.215438.92189511.mbj@tail-f.com> References: <20090107.215438.92189511.mbj@tail-f.com> Message-ID: <49652259.3090102@1und1.de> Hi Martin, Martin Bjorklund schrieb: > Geoff Cant wrote: >> Hi all, I have discovered a weird problem on a customer cluster - mnesia >> experiencing overload/dump_log problems that appear to be due to a >> broken disk_log_server process. > > Are you sure it's really stuck? I.e. if you do process_info() some > time later, is the reductions the same? Yes, the reductions did not change for at least 15 minutes, so it was really stuck. I did not check it once again though. Even if I did not report it anywhere, I have seen other processes before, ones not related to mnesia or disk_log, got stuck for several hours until the node got restarted or process exited. Unfortunately, I have no idea how to reliably reproduce this symptom. Ciao, -- Andreas From john.hughes@REDACTED Wed Jan 7 23:37:43 2009 From: john.hughes@REDACTED (John Hughes) Date: Wed, 7 Jan 2009 23:37:43 +0100 Subject: [erlang-questions] Erlang FFI References: Message-ID: <007FD77CC2394BF5A9C2EBF5965D49DC@JTablet2007> What's the current status of EEP-007 (the Erlang FFI)? The most recent patches I've found are against R11B-5... are there patches that work with R12B? Is this likely to be accepted and incorporated into the standard distribution? And if so, is there a timescale? John From c.romain@REDACTED Thu Jan 8 00:59:35 2009 From: c.romain@REDACTED (cyril Romain) Date: Thu, 08 Jan 2009 00:59:35 +0100 Subject: [erlang-questions] Are packaged modules the way to go ? In-Reply-To: <1230995394.4583.8.camel@seasc1137.dyn.rnd.as.sw.ericsson.se> References: <49583292.8040903@laposte.net> <1230995394.4583.8.camel@seasc1137.dyn.rnd.as.sw.ericsson.se> Message-ID: <496541E7.10505@laposte.net> Hi, Bengt Kleberg wrote: > I belive it shows that the existing packaged modules are not a > sufficiently good idea to warrant official adaptation. > Indeed.... Thanks for the link, it's a long but worth reading thread! After a deeper look, here is my feedback about packaged modules. I'll give objective facts first, before somewhat subjective notes about packaged modules. _WITHOUT PACKAGED MODULES_ A project without packaged modules: - has a flat module structure (i.e. there are no modules within modules). - generally has, if not always, its sources files (*.erl) in one directory with no subdirectory. Same things for binary files (*.beam). - the name of a module is the name of the Erlang file (without extension) and vice versa. And consequently: - tends to use the following name convention to avoid file/module name clashes: myapplication_mycomponent_mymodule.erl (sometimes there is no mycomponent, and more rarely no myapplication in the name). Abbreviations such as myapp instead of myapplication are often use to avoid very long name. - can use macros to avoid using long module name within the code. E.g. -define(MYMOD, myapplication_mycomponent_mymodule), and calling ?MYMOD:foo(). - the project file structure makes Emakefile quite straightforward to write. A one liner Emakefile may even suffice: {'src/*', [debug_info, {outdir, "ebin"}, {i, "include"}]}. - tools analyzing Erlang files or project file structure [1] can rely on the following statement: the file name is the module name and vice versa. _WITH PACKAGED MODULES_ A project with packaged modules: - has a tree module structure. - generally suggest (resp. require) the source (resp. the binary) file structure to follow the tree module structure. - the name of a module can differ from the file name (the full module name is actually a part of the file path, with . instead of /). - a module in a package requires additional import of the top-most modules used in the code. Indeed you need to either: - use the prefix . to specify that you are referring to the root package. - add an 'import' statement at the top of the module. E.g. to use the standard library 'lists' module: you would either use '.lists:reverse' instead of 'lists:reverse', or you have to -import(lists). Anther example if a module in a package defines -behaviour(supervisor), you have to -import(supervisor) or to use the . prefix to call supervisor functions. And consequently: - short file names can be used. mymodule.erl can actually defines -module(myapplication.mycomponent.mymodule). - make code more readable and easier to maintain, because no need to specify the namespace when calling function defined in mymodule. - require more complex Emakefile to dispatch .beam files in a directory structure following the module namespace structure. - allow multiple Erlang files to have the same name, as long as they define modules in different namespace. E.g the ~/ebin/core/net.beam, ~/ebin/plugin/net.beam and Erlang kernel's net.beam files can coexist with the respective core.net, plugin.net and net module names. - the full module name should be read from the Erlang file to be known. Indeed in /a/path/to/mymodule.erl, the module name could be 'mymodule' or 'to.mymodule' or etc. _NOTES_: Packages modules suggest to the developers to split their software into sub-component, which is good IMHO. Project containing ton of source files are indeed easier to work with when split into orthogonal components, with one directory per component and where code dependencies are more clear. Of course it can be achieved without packaged module and one can badly design and split their packaged modules, but packages modules just strongly suggest this good software development practice. Packages modules, as they are now, have some drawbacks though: In regards to developer's code: - using the prefix . for top-most module breaks code consistency between top-most and non-to-most modules, unless you or Erlang would enforce that prefix to be used everywhere. - additional import tends to conflict with the 'don't use import' Erlang programming rule [1]. However it nicely solves the too_much_long_names in code issue without using UPPERCASEMACROS. Some unexpected "bugs" can also show up when using module packages. For instance: - code:where_is_code(Filename) looks for the file in code path but not in sub-directories, so it is unable to find packaged module. - code:get_object_code(Mod) can succeed while Mod:module_info() fails, when e.g. Mod = test.plugin.net but the module name actually is plugin.net. It is also worth noting that packaged modules: 1. does not solves name clash issues. It only substitutes name clash issues by module namespace clash issues. Indeed if you use for instance two Erlang projects using packages that pick the same name and namespace for a module, the code will clash. 2. implies more complexity in tools analyzing Erlang files or project file structure such as debugger, dialyzer, Emakefile, etc. Indeed those tools cannot assume the filename is the module name and vice versa anymore. 3. are not supported yet by some useful tools (dialyzer, Erlang automake, etc.). E.g. dialyzer assumes the file name is the module name and vice versa, and therefore fails to analyze projects with duplicate Erlang files name, even if those files define modules in different namespace. 4. last but not least, it breaks referential transparency in some way [2]. Further discussion about packages can be found on the Erlang mailing list. See [3] and [4]. Although packaged modules seems a good idea, I'm still wondering if they are worth it due the above notes, and in regards to the Erlang code consistency in general. I'm tempted to say that packaged modules are good and can enforce consistency, but only if widely adopted by Erlang developers and widely supported by tools. Unfortunately for now it just look like it adds more confusion than consistency :-( If there is a consensus about no adoption, are packaged modules planned to be removed from Erlang/OTP releases ? Any official decision or thought on this subject ? Sorry for the long mail. Hope it will be useful. Best regards, Cyril PS: for some reason Joe Armstrong does not mention packaged modules in his last book. Hope I'm not reviving an old flame ware here! If you notice something wrong or that I didn't mentioned, please let everyone know. [1] http://www.erlang.se/doc/programming_rules.shtml#HDR26 [2] http://www.erlang.org/pipermail/erlang-questions/2006-October/023749.html [3] http://www.erlang.org/pipermail/erlang-questions/2003-April/008571.html [4] http://www.erlang.org/pipermail/erlang-questions/2006-November/023768.html From jlprasantha@REDACTED Thu Jan 8 06:22:00 2009 From: jlprasantha@REDACTED (prasantha kumara) Date: Thu, 8 Jan 2009 10:52:00 +0530 Subject: [erlang-questions] erlang atom data length is not enough Message-ID: Hi all. i have sent a data steam which is 2048byte long to the c node from the erlang node. i want to process them in the c node.to do that i cast it to ta erl atom using ERL_ATOM_PTR().becouse i suppose to get he byte by byte using a c pointer. the code i have writtenis as follows argp = erl_element(2, tuplep); unsigned char* pp; pp=ERL_ATOM_PTR(argp); int i; for(i=0;i<10;i++){ pp=a[0]; printf(" %d ",*(pp+i)); } but it can prints only 255 bytes from the byte stream .can any body help me get the total byte steam. -------------- next part -------------- An HTML attachment was scrubbed... URL: From asegall@REDACTED Mon Jan 5 22:25:50 2009 From: asegall@REDACTED (Ariel Segall) Date: Mon, 05 Jan 2009 16:25:50 -0500 Subject: [erlang-questions] C nodes and global registration Message-ID: <49627ADE.6050407@mitre.org> We're building an Erlang application that requires access to some C libraries, and have been attempting to implement the Erlang C node instructions from the EI User's Guide. Our C node and Erlang node can pass messages to each other with no problems, but attempting to register the C node with a global name consistently fails. When we call erl_global_register from the C side, it returns a failure and our Erlang node has the following error report: Error in process <0.45.0> on node 'e1@REDACTED' with exit value: {badarg,[{erlang,monitor,[process,<5159.5.0>]},{global,'-do_monitor/1-fun-0-',1}]} When we instead use the global:register_name function from the Erlang shell, to associate our C node's PID with the desired name, register_name returns "yes" (success) but we again get the monitor error. In either case, our name does not show up in the list of registered processes. My best guess as to what's going on here is that the C node can't be monitored, and the global registration code removes or refuses the registration when it can't establish that the C node is still alive. We've found several examples online that seem to use the C erl_global_register function with no trouble, however, and none of them even mention additional monitoring code. Here's the relevant section of C code up to the failure; when attempting to do global registration from Erlang, we comment out the last two lines. int BUFSIZE = 1024; int identification_number = 99; int creation=1; int loop=1; char *cookie="secret"; const char *thisnodename; int openport, sockfd, rc, portdescriptor; int port=1333; ErlConnect conn; char buf[BUFSIZE]; ErlMessage emsg; ETERM *self, *ans[3], *answer, *dest; // Initialize connection erl_init(NULL, 0); if (erl_connect_init(identification_number, cookie, creation) == -1) erl_err_quit("erl_connect_init failed"); fprintf(stderr, "Completed erlang intialization\n"); // Start TCP server if ((openport = initserver(port)) <=0) erl_err_quit("Initialization of server failed"); fprintf(stderr, "Completed TCP server initialization with port result %d\n", openport); portdescriptor = erl_publish(port); if (portdescriptor == -1) erl_err_quit("erl_publish failed"); fprintf(stderr, "Completed Erlang publishing\n"); if ((sockfd = erl_accept(openport, &conn)) == ERL_ERROR) erl_err_quit("erl_accept failed"); fprintf(stderr, "Connected to %s\n", conn.nodename); //Register the TPM interface as a global name for easy accessibility thisnodename = erl_thisnodename(); fprintf(stderr, "Calculated own nodename of %s\n", thisnodename); self = erl_mk_pid(thisnodename, sockfd, 0, erl_thiscreation()); if (erl_global_register(sockfd, "tpm_interface", self) !=0) erl_err_quit("Failed to register process"); (Code after the registration attempt has been removed for clarity.) We'd appreciate any suggestions. Thanks, Ariel From asegall@REDACTED Mon Jan 5 17:37:14 2009 From: asegall@REDACTED (Segall, Ariel E) Date: Mon, 5 Jan 2009 11:37:14 -0500 Subject: [erlang-questions] C nodes and global registration Message-ID: <96A663EA5253F949A8054BF10352F36F0183340DF6@IMCMBX1.MITRE.ORG> We're building an Erlang application that requires access to some C libraries, and have been attempting to implement the Erlang C node instructions from the EI User's Guide. Our C node and Erlang node can pass messages to each other with no problems, but attempting to register the C node with a global name consistently fails. When we call erl_global_register from the C side, it returns a failure and our Erlang node has the following error report: Error in process <0.45.0> on node 'e1@REDACTED' with exit value: {badarg,[{erlang,monitor,[process,<5159.5.0>]},{global,'-do_monitor/1-fun-0-',1}]} When we instead use the global:register_name function from the Erlang shell, to associate our C node's PID with the desired name, register_name returns "yes" (success) but we again get the monitor error. In either case, our name does not show up in the list of registered processes. My best guess as to what's going on here is that the C node can't be monitored, and the global registration code removes or refuses the registration when it can't establish that the C node is still alive. We've found several examples online that seem to use the C erl_global_register function with no trouble, however, and none of them even mention additional monitoring code. Here's the relevant section of C code up to the failure; when attempting to do global registration from Erlang, we comment out the last two lines. int BUFSIZE = 1024; int identification_number = 99; int creation=1; int loop=1; char *cookie="secret"; const char *thisnodename; int openport, sockfd, rc, portdescriptor; int port=1333; ErlConnect conn; char buf[BUFSIZE]; ErlMessage emsg; ETERM *self, *ans[3], *answer, *dest; // Initialize connection erl_init(NULL, 0); if (erl_connect_init(identification_number, cookie, creation) == -1) erl_err_quit("erl_connect_init failed"); fprintf(stderr, "Completed erlang intialization\n"); // Start TCP server if ((openport = initserver(port)) <=0) erl_err_quit("Initialization of server failed"); fprintf(stderr, "Completed TCP server initialization with port result %d\n", openport); portdescriptor = erl_publish(port); if (portdescriptor == -1) erl_err_quit("erl_publish failed"); fprintf(stderr, "Completed Erlang publishing\n"); if ((sockfd = erl_accept(openport, &conn)) == ERL_ERROR) erl_err_quit("erl_accept failed"); fprintf(stderr, "Connected to %s\n", conn.nodename); //Register the TPM interface as a global name for easy accessibility thisnodename = erl_thisnodename(); fprintf(stderr, "Calculated own nodename of %s\n", thisnodename); self = erl_mk_pid(thisnodename, sockfd, 0, erl_thiscreation()); if (erl_global_register(sockfd, "tpm_interface", self) !=0) erl_err_quit("Failed to register process"); (Message parsing code after registration attempt removed for clarity.) We'd appreciate any suggestions. Thanks, Ariel From nc@REDACTED Thu Jan 8 08:11:13 2009 From: nc@REDACTED (Nicolas Charpentier) Date: Thu, 08 Jan 2009 08:11:13 +0100 Subject: [erlang-questions] code:lib_dir and dialyzer In-Reply-To: <4964BA9F.40805@cs.ntua.gr> References: <496300C8.7010107@charpi.net> <4964BA9F.40805@cs.ntua.gr> Message-ID: <4965A711.7040608@charpi.net> Hi, Kostis Sagonas wrote: >>... > In some sense yes, but I would really describe/classify this as an > inconsistency more than a bug. > > The problem is that Dialyzer (still) has hard-coded information about > some library functions in hipe/cerl/erl_bif_types.erl. This information > pre-dates the language of contracts and shadows the -spec information. > For the function in question dialyzer knows that: > > arg_types(code, lib_dir, 1) -> > [t_atom()]; > > which explains why you get the error message that you get. Now that > contracts are present in code, arguably this information is no longer > needed and can (should?) be taken out -- at least for functions of this > module. > > Regardless, I would suggest that you fix your code to adhere to the > published documentation and use code:lib_dir/1 with a string() instead. > Thanks for your answer. Of course that my code need to be fix to match the documentation/contracts, I was just worried that this 'error report confusion' could occurred on my code too. ---- Nicolas Charpentier http://charpi.net From bengt.kleberg@REDACTED Thu Jan 8 08:29:33 2009 From: bengt.kleberg@REDACTED (Bengt Kleberg) Date: Thu, 08 Jan 2009 08:29:33 +0100 Subject: [erlang-questions] erlang atom data length is not enough In-Reply-To: References: Message-ID: <1231399773.4527.7.camel@seasc1137.dyn.rnd.as.sw.ericsson.se> Greetings, In the Erlang documentation, 9.2 System limits, it is written that the maximum number of characters in an atom is 255. What are you sending from Erlang? bengt On Thu, 2009-01-08 at 10:52 +0530, prasantha kumara wrote: > > Hi all. > i have sent a data steam which is 2048byte long to the c node from the > erlang node. > i want to process them in the c node.to do that i cast it to ta erl > atom using ERL_ATOM_PTR().becouse i suppose to get he byte by byte > using a c pointer. > > the code i have writtenis as follows > > argp = erl_element(2, tuplep); > unsigned char* pp; > pp=ERL_ATOM_PTR(argp); > int i; > for(i=0;i<10;i++){ > pp=a[0]; > printf(" %d ",*(pp+i)); > } > but it can prints only 255 bytes from the byte stream .can any body > help me get the total byte steam. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From bengt.kleberg@REDACTED Thu Jan 8 08:44:34 2009 From: bengt.kleberg@REDACTED (Bengt Kleberg) Date: Thu, 08 Jan 2009 08:44:34 +0100 Subject: [erlang-questions] Starting Erlang as a Unix daemon In-Reply-To: <20090107175301.3d64ee6d@samb-cm> References: <20090107175301.3d64ee6d@samb-cm> Message-ID: <1231400675.4527.12.camel@seasc1137.dyn.rnd.as.sw.ericsson.se> Greetings, While I hesitate to call this a good way it is at least possible to use escript (http://erlang.org/doc/man/escript.html), after you have started Erlang with run_erl, to check if init has achieved the desired results. If this sounds unclear I would be glad to help you further. bengt On Wed, 2009-01-07 at 17:53 +1100, Sam Bobroff wrote: > Hello everyone, > > I'm working on a project in Erlang that needs to run as a daemon on a > Unix machine. I would like to provide feedback from the init script > that starts the daemon but I'm having trouble finding a good way of > doing it. For example, I would like this to happen from the shell: > > # /etc/init.d/foo start > Starting foo... OK > > or > > # /etc/init.d/foo start > Starting foo... FAILED > > (If there was a fatal error during startup.) > > I've tried using both "run_erl" and "erl -detached" but both of them > seem to fork and exit before any user code is run. > > Does anyone know a good way to handle this? > > Thanks in advance, > Sam. From ingela@REDACTED Thu Jan 8 09:16:56 2009 From: ingela@REDACTED (Ingela Anderton Andin) Date: Thu, 08 Jan 2009 09:16:56 +0100 Subject: [erlang-questions] odbc unsigned values In-Reply-To: References: Message-ID: <4965B678.2010404@erix.ericsson.se> Hi! What erlang odbc will return depends on which SQL-DATATYPE that the driver you use claims it to be. You can use odbc:describe_table/[2,3] to find out what type will be returned. When we know that maybe we can derive if the erlang-odbc port program needs an update or not. Regards Ingela Erlang/OTP - Ericsson > Hi,I'm trying to port my erlang app to linux. It works fine on windows but I'm > having trouble with odbc on linux. Basically anytime I do something like > this: > > SQL="Select BigInt from Table", > odbc:sql_query(DBRef, SQL). > > If BigInt is over 2147483647 it will just return 2147483647. > > in mysql BigInt is of type: int(10) unsigned > it works fine from isql > I'm using odbc-2.10.2 > > Is this a known problem? Any ideas how to fix? > Thanks for any help, > Jed. > > From zerthurd@REDACTED Thu Jan 8 09:59:13 2009 From: zerthurd@REDACTED (Maxim Treskin) Date: Thu, 8 Jan 2009 14:59:13 +0600 Subject: [erlang-questions] Gentoo overlay for erlang related stuff (with leex) Message-ID: Hello Today I had made repository for Gentoo overlay with erlang related stuff. http://github.com/Zert/gentoo-erlang-layout/tree/master At this time it contains only ebuild for leex (by Robert Virding). If you are gentoo user and erlang programmer you can help me with your ebuild for packages absents in official gentoo portage tree. Thank you -- Maxim Treskin -------------- next part -------------- An HTML attachment was scrubbed... URL: From ryeguy1@REDACTED Thu Jan 8 10:15:55 2009 From: ryeguy1@REDACTED (Ryan Lepidi) Date: Thu, 8 Jan 2009 04:15:55 -0500 Subject: [erlang-questions] QLC vs mnesia:select/read Message-ID: Hello, I am just learning Erlang and was recently reading up on the Mnesia section. It seems that QLC commands and the mnesia:select and mnesia:read functions do the same thing. Are there any drawbacks, functionality wise or speed wise, to using one over the other? Because to me it seems that QLC is simpler and more readable. Is it just a matter of preference? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From masse@REDACTED Thu Jan 8 10:16:04 2009 From: masse@REDACTED (mats cronqvist) Date: Thu, 08 Jan 2009 10:16:04 +0100 Subject: [erlang-questions] Calling into Lua from Erlang In-Reply-To: <6a3ae47e0901070810n5184c90brc8f230452c88e0ba@mail.gmail.com> (Robert Raschke's message of "Wed\, 7 Jan 2009 16\:10\:13 +0000") References: <6a3ae47e0901070810n5184c90brc8f230452c88e0ba@mail.gmail.com> Message-ID: <87hc4a6tuz.fsf@sterlett.hq.kred> "Robert Raschke" writes: > I am currently undecided whether to make the Lua API available to be > invoked from Erlang (via a linked-in driver) or if it might be more > useful to write a Lua library that allows a Lua script to function as > an Erlang node (similar to the Erlang Jinterface lib for Java). I've worked extensively with nodes implemented in C (gtknode.googlecode.com) and Emacs Lisp (distel.googlecode.com), and it's been pleasant. I've also spent weeks trying to find off-by-one errors in linked-in drivers. I wouldn't ever consider using a linked-in driver unless forced to do so for performance reasons. mats From masse@REDACTED Thu Jan 8 10:22:39 2009 From: masse@REDACTED (mats cronqvist) Date: Thu, 08 Jan 2009 10:22:39 +0100 Subject: [erlang-questions] Stuck disk_log_server In-Reply-To: <49652259.3090102@1und1.de> ("Andreas =?iso-8859-1?Q?K=F6hler?= =?iso-8859-1?Q?=22's?= message of "Wed\, 07 Jan 2009 22\:44\:57 +0100") References: <20090107.215438.92189511.mbj@tail-f.com> <49652259.3090102@1und1.de> Message-ID: <87d4ey6tk0.fsf@sterlett.hq.kred> Andreas K?hler writes: > Hi Martin, > > Martin Bjorklund schrieb: >> Geoff Cant wrote: >>> Hi all, I have discovered a weird problem on a customer cluster - mnesia >>> experiencing overload/dump_log problems that appear to be due to a >>> broken disk_log_server process. >> >> Are you sure it's really stuck? I.e. if you do process_info() some >> time later, is the reductions the same? > > Yes, the reductions did not change for at least 15 minutes, so it was > really stuck. I did not check it once again though. > > Even if I did not report it anywhere, I have seen other processes > before, ones not related to mnesia or disk_log, got stuck for several > hours until the node got restarted or process exited. Unfortunately, I > have no idea how to reliably reproduce this symptom. it would be interesting to see a process_info() of those processes... mats From rtrlists@REDACTED Thu Jan 8 10:28:10 2009 From: rtrlists@REDACTED (Robert Raschke) Date: Thu, 8 Jan 2009 09:28:10 +0000 Subject: [erlang-questions] Calling into Lua from Erlang In-Reply-To: <87hc4a6tuz.fsf@sterlett.hq.kred> References: <6a3ae47e0901070810n5184c90brc8f230452c88e0ba@mail.gmail.com> <87hc4a6tuz.fsf@sterlett.hq.kred> Message-ID: <6a3ae47e0901080128j5888bb2fy56fceafdd3bd8ffa@mail.gmail.com> So, I think I will at least spend a day or two trying to see how much work creating a Lua Erlang Node would be. I am guessing, this will essentially be a Lua interface to EI, creating what is in effect a C node within a Lua state. Robby From holger@REDACTED Thu Jan 8 12:54:06 2009 From: holger@REDACTED (Holger Hoffstaette) Date: Thu, 08 Jan 2009 12:54:06 +0100 Subject: [erlang-questions] Gentoo overlay for erlang related stuff (with leex) References: Message-ID: On Thu, 08 Jan 2009 14:59:13 +0600, Maxim Treskin wrote: > Today I had made repository for Gentoo overlay with erlang related stuff. > > http://github.com/Zert/gentoo-erlang-layout/tree/master There's another one at: http://blog.socklabs.com/2008/11/26/erlang_portage_overlay.html Maybe you guys can join forces? That would make things much easier. The idea for rabbitmq was to be moved into Sunrise, but I haven't had the time for more work on it yet. Holger From oscar@REDACTED Thu Jan 8 13:24:13 2009 From: oscar@REDACTED (=?ISO-8859-1?Q?Oscar_Hellstr=F6m?=) Date: Thu, 08 Jan 2009 12:24:13 +0000 Subject: [erlang-questions] Gentoo overlay for erlang related stuff (with leex) In-Reply-To: References: Message-ID: <4965F06D.3080102@erlang-consulting.com> Hi, Have you tried to file bugs for this with the Gentoo project. My experience is that it's not that hard to get new ebuilds accepted. Holger Hoffstaette wrote: > On Thu, 08 Jan 2009 14:59:13 +0600, Maxim Treskin wrote: > > >> Today I had made repository for Gentoo overlay with erlang related stuff. >> >> http://github.com/Zert/gentoo-erlang-layout/tree/master >> > > There's another one at: > http://blog.socklabs.com/2008/11/26/erlang_portage_overlay.html > > Maybe you guys can join forces? That would make things much easier. The > idea for rabbitmq was to be moved into Sunrise, but I haven't had the time > for more work on it yet. > > Holger > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > Best regards -- Oscar Hellstr?m, oscar@REDACTED Office: +44 20 7655 0337 Mobile: +44 798 45 44 773 Erlang Training and Consulting http://www.erlang-consulting.com/ From alceste@REDACTED Thu Jan 8 13:36:02 2009 From: alceste@REDACTED (Alceste Scalas) Date: Thu, 08 Jan 2009 13:36:02 +0100 Subject: [erlang-questions] Erlang FFI In-Reply-To: <007FD77CC2394BF5A9C2EBF5965D49DC@JTablet2007> References: <007FD77CC2394BF5A9C2EBF5965D49DC@JTablet2007> Message-ID: <20090108133602.bh4882kk088ogook@webmail.crs4.it> John Hughes wrote: > What's the current status of EEP-007 (the Erlang FFI)? The most recent > patches I've found are against R11B-5... are there patches that work with > R12B? I've not (yet) ported the FFI patches to R12B, for two reasons: 1. the research project I'm working on (that depends on the FFI) could go ahead with R11B-5, and we are not (yet) planning to switch to R12B (but this *could* change in the next weeks); 2. EEP 7 has not been discussed by the OTP team yet. During the 2008 Erlang User Conference, the FFI (or loadable BIFs) was described as a "tentative goal" for OTP R13B (planned for April 2009) [1]. It *could* be possible to reimplemented the current FFI proposal on top of loadable BIFs (maybe losing some performance), but there are several details to consider (mostly related to DLL handling). If an R12B/R13B port of the FFI patches becomes a requirement for EEP 7 to be accepted, maybe my research project could switch to R12B/R13B sooner (and I could work on the patches again). Regards, alceste Notes: [1] See http://www.erlang.se/euc/08/ErlangOTPNews2.pdf -- Alceste Scalas ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From geoff.cant@REDACTED Thu Jan 8 13:37:40 2009 From: geoff.cant@REDACTED (Geoff Cant) Date: Thu, 08 Jan 2009 13:37:40 +0100 Subject: [erlang-questions] Stuck disk_log_server In-Reply-To: <87d4ey6tk0.fsf@sterlett.hq.kred> (mats cronqvist's message of "Thu, 08 Jan 2009 10:22:39 +0100") References: <20090107.215438.92189511.mbj@tail-f.com> <49652259.3090102@1und1.de> <87d4ey6tk0.fsf@sterlett.hq.kred> Message-ID: The following debug session is pretty long. mats cronqvist writes: > it would be interesting to see a process_info() of those > processes... >From the diagnostic session Andreas and I performed: (in the transcript nodenames and file paths have been slightly but consistently rewritten to obscure some private network information) We tried mnesia:dump_log() which hung, so we tried to figure out why. mnesia_controller:get_workers(2000) => {workers,[],[],<0.22676.260>} process_info(<0.22676.260>) => [{current_function,{gen,wait_resp_mon,3}}, {initial_call,{mnesia_controller,dump_and_reply,2}}, {status,waiting}, {message_queue_len,0}, {messages,[]}, {links,[<0.116.0>]}, {dictionary,[]}, {trap_exit,false}, {error_handler,error_handler}, {priority,normal}, {group_leader,<0.57.0>}, {total_heap_size,233}, {heap_size,233}, {stack_size,21}, {reductions,4311}, {garbage_collection,[{fullsweep_after,0},{minor_gcs,0}]}, {suspending,[]}] Backtrace <0.22676.260>: Program counter: 0x00007f61c0e0c2a8 (gen:wait_resp_mon/3 + 64) CP: 0x00007f61c43645d8 (gen_server:call/3 + 160) arity = 0 0x00007f60f844c108 Return addr 0x00007f61c43645d8 (gen_server:call/3 + 160) y(0) infinity y(1) #Ref<0.0.992.227032> y(2) 'ejabberd@REDACTED' 0x00007f60f844c128 Return addr 0x00007f61c049f1d0 (mnesia_log:save_decision_tab/1 + 248) y(0) infinity y(1) {close_log,decision_tab} y(2) <0.62.0> y(3) Catch 0x00007f61c43645d8 (gen_server:call/3 + 160) 0x00007f60f844c150 Return addr 0x00007f61c03c6ec8 (mnesia_dumper:perform_dump/2 + 1648) y(0) "/fake/path/ejabberd/DECISION_TAB.TMP" y(1) [] 0x00007f60f844c168 Return addr 0x00007f61c056bdd0 (mnesia_controller:dump_and_reply/2 + 152) y(0) [] y(1) [] y(2) [] y(3) 15 y(4) [] y(5) [] 0x00007f60f844c1a0 Return addr 0x000000000084bd18 () y(0) <0.116.0> Here the log dumping process appears to be waiting on gen_server:call(mnesia_monitor, {close_log,decision_tab}). process_info(<0.62.0>) => [{registered_name,mnesia_monitor}, {current_function,{disk_log,monitor_request,2}}, {initial_call,{proc_lib,init_p,5}}, {status,waiting}, {message_queue_len,34}, {messages,[{nodeup,'gc@REDACTED'}, {nodedown,'gc@REDACTED'}, {nodeup,'fakenode1-16-26-06@REDACTED'}, {nodedown,'fakenode1-16-26-06@REDACTED'}, {nodeup,'fakenode1-16-27-20@REDACTED'}, {nodedown,'fakenode1-16-27-20@REDACTED'}, {nodeup,'fakenode1-16-29-25@REDACTED'}, {nodedown,'fakenode1-16-29-25@REDACTED'}, {nodeup,'gc@REDACTED'}, {nodedown,'gc@REDACTED'}, {nodeup,'fakenode2-16-36-53@REDACTED'}, {nodeup,'gc@REDACTED'}, {nodedown,'gc@REDACTED'}, {nodeup,'gc@REDACTED'}, {nodedown,'gc@REDACTED'}, {nodeup,'gc@REDACTED'}, {nodedown,'gc@REDACTED'}, {nodeup,'gc@REDACTED'}, {nodedown,'gc@REDACTED'}, {nodeup,...}, {...}|...]}, {links,[<6749.62.0>,<6753.62.0>,<0.111.0>,<0.22677.260>, <6752.104.0>,<6747.62.0>,<6748.62.0>,<0.61.0>,<6751.62.0>, <6750.62.0>,<0.52.0>]}, {dictionary,[{'$ancestors',[mnesia_kernel_sup,mnesia_sup, <0.58.0>]}, {'$initial_call',{gen,init_it, [gen_server,<0.61.0>,<0.61.0>, {local,mnesia_monitor}, mnesia_monitor, [<0.61.0>], [{timeout,infinity}]]}}]}, {trap_exit,true}, {error_handler,error_handler}, {priority,normal}, {group_leader,<0.57.0>}, {total_heap_size,377}, {heap_size,377}, {stack_size,20}, {reductions,2326000}, {garbage_collection,[{fullsweep_after,0},{minor_gcs,0}]}, {suspending,[]}] We didn't take a backtrace of mnesia_monitor, but {current_function,{disk_log,monitor_request,2}} led us to think that mnesia_monitor was trying to close the decision_tab log file, so we tried to find out which process that was. At this point, disk_log:info(decision_tab) hung, so we tried disk_log_server:get_log_pids(decision_tab) which gave us {local,<0.22681.260>}. Backtrace <0.22681.260>: Program counter: 0x00007f61c0e0c2a8 (gen:wait_resp_mon/3 + 64) CP: 0x00007f61c43645d8 (gen_server:call/3 + 160) arity = 0 0x00007f60f75818a0 Return addr 0x00007f61c43645d8 (gen_server:call/3 + 160) y(0) infinity y(1) #Ref<0.0.992.227035> y(2) 'ejabberd@REDACTED' 0x00007f60f75818c0 Return addr 0x00007f61c03b1610 (disk_log:do_exit/4 + 440) y(0) infinity y(1) {close,<0.22681.260>} y(2) disk_log_server y(3) Catch 0x00007f61c43645d8 (gen_server:call/3 + 160) 0x00007f60f75818e8 Return addr 0x00007f61c0e23fe8 (proc_lib:init_p/5 + 400) y(0) normal y(1) [] y(2) <0.62.0> y(3) ok 0x00007f60f7581910 Return addr 0x000000000084bd18 () y(0) Catch 0x00007f61c0e24008 (proc_lib:init_p/5 + 432) y(1) disk_log y(2) init y(3) [<0.70.0>,<0.71.0>] The disk_log process for 'decision_tab' was waiting for a reply from the disk_log_server to gen_server:call(disk_log_server, {close, self()}). Backtrace disk_log_server: Program counter: 0x00007f61c4365af8 (gen_server:loop/6 + 288) CP: 0x00007f61c0e23fe8 (proc_lib:init_p/5 + 400) arity = 0 0x00007f60fb043f78 Return addr 0x00007f61c0e23fe8 (proc_lib:init_p/5 + 400) y(0) [] y(1) infinity y(2) disk_log_server y(3) {state,[]} y(4) disk_log_server y(5) <0.30.0> 0x00007f60fb043fb0 Return addr 0x000000000084bd18 () y(0) Catch 0x00007f61c0e24008 (proc_lib:init_p/5 + 432) y(1) gen y(2) init_it y(3) [gen_server,<0.30.0>,<0.30.0>,{local,disk_log_server},disk_log_server,[],[]] process_info(whereis(disk_log_server)) => [{registered_name,disk_log_server}, {current_function,{gen_server,loop,6}}, {initial_call,{proc_lib,init_p,5}}, {status,waiting}, {message_queue_len,1}, {messages,[{'$gen_call',{<0.22681.260>,#Ref<0.0.992.227035>}, {close,<0.22681.260>}}]}, {links,[<0.111.0>,<0.22677.260>,<0.22681.260>,<0.30.0>]}, {dictionary,[{<0.111.0>,latest_log}, {<0.22677.260>,previous_log}, {'$ancestors',[kernel_safe_sup,kernel_sup,<0.8.0>]}, {<0.22681.260>,decision_tab}, {'$initial_call',{gen,init_it, [gen_server,<0.30.0>,<0.30.0>, {local,disk_log_server}, disk_log_server,[],[]]}}]}, {trap_exit,true}, {error_handler,error_handler}, {priority,normal}, {group_leader,<0.7.0>}, {total_heap_size,246}, {heap_size,233}, {stack_size,12}, {reductions,2366165}, {garbage_collection,[{fullsweep_after,0},{minor_gcs,0}]}, {suspending,[]}] Which appears to be doing something impossible - blocked in the receive statement in gen_server:loop/6 with a valid message in its queue. This line of investigation is all we have as the server has now been restarted. What other information should we collect if this problem (or a similar problem) happens again? The erlang version information is "Erlang (BEAM) emulator version 5.6.3 [source] [64-bit] [smp:8] [async-threads:0] [hipe] [kernel-poll:false]" - the stock Debian erlang-hipe-base from lenny on amd64 hardware. Cheers, -- Geoff Cant Note to anyone reading who is curious about how we get the backtraces or process_info: io:format("~s~n:", [element(2, process_info(TargetPid, backtrace))]). gives the backtrace and rp(process_info(TargetPid)). gives us the process info list. From saleyn@REDACTED Thu Jan 8 14:21:29 2009 From: saleyn@REDACTED (Serge Aleynikov) Date: Thu, 08 Jan 2009 08:21:29 -0500 Subject: [erlang-questions] C nodes and global registration In-Reply-To: <49627ADE.6050407@mitre.org> References: <49627ADE.6050407@mitre.org> Message-ID: <4965FDD9.8030401@gmail.com> Take a look at this thread: http://www.erlang.org/pipermail/erlang-questions/2008-October/038740.html It discusses the same issue though using otp.net node. I was able to get monitoring to work for .NET, but in case of erl_interface, it would require to patch the library in order to get monitoring support. What you need is to add an appropriate flag to the connect function to indicate that you want monitoring support, process [DE]MONITOR_P[_EXIT] messages, and notify the peer when a monitored pid is deallocated on the C side. See: http://www.erlang.org/doc/apps/erts/erl_dist_protocol.html#9 Serge Ariel Segall wrote: > We're building an Erlang application that requires access to some C libraries, and have been attempting to implement the Erlang C node instructions from the EI User's Guide. Our C node and Erlang node can pass messages to each other with no problems, but attempting to register the C node with a global name consistently fails. > > When we call erl_global_register from the C side, it returns a failure and our Erlang node has the following error report: > > Error in process <0.45.0> on node 'e1@REDACTED' with exit value: {badarg,[{erlang,monitor,[process,<5159.5.0>]},{global,'-do_monitor/1-fun-0-',1}]} > > When we instead use the global:register_name function from the Erlang shell, to associate our C node's PID with the desired name, register_name returns "yes" (success) but we again get the monitor error. In either case, our name does not show up in the list of registered processes. > > My best guess as to what's going on here is that the C node can't be monitored, and the global registration code removes or refuses the registration when it can't establish that the C node is still alive. We've found several examples online that seem to use the C erl_global_register function with no trouble, however, and none of them even mention additional monitoring code. > > Here's the relevant section of C code up to the failure; when attempting to do global registration from Erlang, we comment out the last two lines. > > int BUFSIZE = 1024; > int identification_number = 99; > int creation=1; > int loop=1; > char *cookie="secret"; > const char *thisnodename; > int openport, sockfd, rc, portdescriptor; > int port=1333; > ErlConnect conn; > char buf[BUFSIZE]; > ErlMessage emsg; > ETERM *self, *ans[3], *answer, *dest; > > // Initialize connection > erl_init(NULL, 0); > if (erl_connect_init(identification_number, cookie, creation) == -1) > erl_err_quit("erl_connect_init failed"); > fprintf(stderr, "Completed erlang intialization\n"); > // Start TCP server > if ((openport = initserver(port)) <=0) > erl_err_quit("Initialization of server failed"); > fprintf(stderr, "Completed TCP server initialization with port result %d\n", openport); > portdescriptor = erl_publish(port); > if (portdescriptor == -1) > erl_err_quit("erl_publish failed"); > fprintf(stderr, "Completed Erlang publishing\n"); > if ((sockfd = erl_accept(openport, &conn)) == ERL_ERROR) > erl_err_quit("erl_accept failed"); > fprintf(stderr, "Connected to %s\n", conn.nodename); > //Register the TPM interface as a global name for easy accessibility > thisnodename = erl_thisnodename(); > fprintf(stderr, "Calculated own nodename of %s\n", thisnodename); > self = erl_mk_pid(thisnodename, sockfd, 0, erl_thiscreation()); > if (erl_global_register(sockfd, "tpm_interface", self) !=0) > erl_err_quit("Failed to register process"); > > (Code after the registration attempt has been removed for clarity.) > > We'd appreciate any suggestions. > > Thanks, > Ariel > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From masse@REDACTED Thu Jan 8 14:27:16 2009 From: masse@REDACTED (mats cronqvist) Date: Thu, 08 Jan 2009 14:27:16 +0100 Subject: [erlang-questions] Stuck disk_log_server In-Reply-To: (Geoff Cant's message of "Thu\, 08 Jan 2009 13\:37\:40 +0100") References: <20090107.215438.92189511.mbj@tail-f.com> <49652259.3090102@1und1.de> <87d4ey6tk0.fsf@sterlett.hq.kred> Message-ID: <877i566i8b.fsf@sterlett.hq.kred> Geoff Cant writes: > The following debug session is pretty long. > > mats cronqvist writes: > >> it would be interesting to see a process_info() of those >> processes... > > From the diagnostic session Andreas and I performed: (in the > transcript nodenames and file paths have been slightly but > consistently rewritten to obscure some private network information) > [pretty long debug session] > Which appears to be doing something impossible - blocked in the receive > statement in gen_server:loop/6 with a valid message in its queue. it would appear so... could it be live locked? i guess not since it didn't use reductions... > This line of investigation is all we have as the server has now been > restarted. What other information should we collect if this problem (or > a similar problem) happens again? I think you should re-send this mail to erlang-bugs. Perhaps they can think of some extra info to be collected. I wonder what would happen if you sent a new message to disk_log_server? mats From holger@REDACTED Thu Jan 8 14:27:54 2009 From: holger@REDACTED (Holger Hoffstaette) Date: Thu, 08 Jan 2009 14:27:54 +0100 Subject: [erlang-questions] Gentoo overlay for erlang related stuff (with leex) References: <4965F06D.3080102@erlang-consulting.com> Message-ID: On Thu, 08 Jan 2009 12:24:13 +0000, Oscar Hellstr?m wrote: > Have you tried to file bugs for this with the Gentoo project. My > experience is that it's not that hard to get new ebuilds accepted. I regularly contribute ebuilds & patches to b.g.o, for example the initial RabbitMQ ebuild. The problem is the lack of a dedicated maintainer who must also be a registered Gentoo dev. Currently even erlang itself is under proxy-maintenance. I help whereever I can, but the strong coupling of these roles is a huge problem. Overlays are one solution, but it's necessary to prevent community fragmentation - hence my post. :) thanks Holger From erlang@REDACTED Thu Jan 8 15:10:46 2009 From: erlang@REDACTED (Joe Armstrong) Date: Thu, 8 Jan 2009 15:10:46 +0100 Subject: [erlang-questions] Starting Erlang as a Unix daemon In-Reply-To: <20090107175301.3d64ee6d@samb-cm> References: <20090107175301.3d64ee6d@samb-cm> Message-ID: <9b08084c0901080610p4782ace9t17523bdac458d2aa@mail.gmail.com> Read http://www.sics.se/~joe/tutorials/web_server/web_server.html#m2 This is specific to red-hat - but it is pretty easy to adapt to other *nix systems /Joe Armstrong On Wed, Jan 7, 2009 at 7:53 AM, Sam Bobroff wrote: > Hello everyone, > > I'm working on a project in Erlang that needs to run as a daemon on a > Unix machine. I would like to provide feedback from the init script > that starts the daemon but I'm having trouble finding a good way of > doing it. For example, I would like this to happen from the shell: > > # /etc/init.d/foo start > Starting foo... OK > > or > > # /etc/init.d/foo start > Starting foo... FAILED > > (If there was a fatal error during startup.) > > I've tried using both "run_erl" and "erl -detached" but both of them > seem to fork and exit before any user code is run. > > Does anyone know a good way to handle this? > > Thanks in advance, > Sam. > -- > Sam Bobroff | sam@REDACTED | M5 Networks > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From thomasl_erlang@REDACTED Thu Jan 8 14:28:59 2009 From: thomasl_erlang@REDACTED (Thomas Lindgren) Date: Thu, 8 Jan 2009 05:28:59 -0800 (PST) Subject: [erlang-questions] Are packaged modules the way to go ? In-Reply-To: <496541E7.10505@laposte.net> Message-ID: <288280.19279.qm@web111413.mail.gq1.yahoo.com> --- On Thu, 1/8/09, cyril Romain wrote: > A project without packaged modules: > - has a flat module structure (i.e. there are no modules > within modules). > - generally has, if not always, its sources files (*.erl) > in one > directory with no subdirectory. Same things for binary > files (*.beam). Not really. A project (aka 'release' in OTP) would normally consist of many 'applications', each of which has its own directory tree with src/ and ebin/ subdirectories (among others). > - tends to use the following name convention to avoid > file/module name > clashes: myapplication_mycomponent_mymodule.erl (sometimes > there is no > mycomponent, and more rarely no myapplication in the name). > > Abbreviations such as myapp instead of myapplication are > often use to > avoid very long name. Naming in practice tends to use app_mod, not app_comp_mod. In some cases, particularly core libraries, the name is just mod. > Packages modules suggest to the developers to split their > software into > sub-component, which is good IMHO. Project containing ton > of source > files are indeed easier to work with when split into > orthogonal > components, with one directory per component and where code > dependencies > are more clear. Such packaging is usually done at the application level, and if you so wish, an OTP application can be seen as a component. For instance, the application need not start a server; just provide a collection of modules. I seem to recall this is called a 'code application'. Applications can then require each other, etc etc. (An aside for those who want packages: should applications also have a hierarchical name space? While applications are not a part of the language, I suppose we will run into the same problems?) Personally, I think the idea of a non-flat module name space is attractive, but packages as proposed are not quite what is needed. (Even if I ignore at least one killer bug.) Best, Thomas From nick@REDACTED Thu Jan 8 15:37:31 2009 From: nick@REDACTED (Nick Gerakines) Date: Thu, 8 Jan 2009 06:37:31 -0800 Subject: [erlang-questions] Gentoo overlay for erlang related stuff (with leex) In-Reply-To: References: Message-ID: I started http://github.com/ngerakines/erlang_portage back in late November and have been updating it fairly regularly. We should consider condensing the two. It's got several of my modules as well as a few others like MochiWeb and the rfc4627 lib. # Nick Gerakines 2009/1/8 Maxim Treskin : > Hello > > Today I had made repository for Gentoo overlay with erlang related stuff. > > http://github.com/Zert/gentoo-erlang-layout/tree/master > > At this time it contains only ebuild for leex (by Robert Virding). > If you are gentoo user and erlang programmer you can help me with your > ebuild for packages absents in official gentoo portage tree. > > Thank you > > -- > Maxim Treskin > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From jed@REDACTED Thu Jan 8 16:33:28 2009 From: jed@REDACTED (Jed McCaleb) Date: Thu, 8 Jan 2009 10:33:28 -0500 Subject: [erlang-questions] odbc unsigned values In-Reply-To: <4965B678.2010404@erix.ericsson.se> References: <4965B678.2010404@erix.ericsson.se> Message-ID: it is saying it is of type: sql_integer Thanks, Jed. On Thu, Jan 8, 2009 at 3:16 AM, Ingela Anderton Andin < ingela@REDACTED> wrote: > Hi! > > What erlang odbc will return depends on which SQL-DATATYPE that the > driver you use claims it to be. > You can use odbc:describe_table/[2,3] to find out what type will be > returned. When we know that maybe > we can derive if the erlang-odbc port program needs an update or not. > > Regards Ingela Erlang/OTP - Ericsson > > > Hi,I'm trying to port my erlang app to linux. It works fine on windows > but I'm > > having trouble with odbc on linux. Basically anytime I do something like > > this: > > > > SQL="Select BigInt from Table", > > odbc:sql_query(DBRef, SQL). > > > > If BigInt is over 2147483647 it will just return 2147483647. > > > > in mysql BigInt is of type: int(10) unsigned > > it works fine from isql > > I'm using odbc-2.10.2 > > > > Is this a known problem? Any ideas how to fix? > > Thanks for any help, > > Jed. > > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From james.hague@REDACTED Thu Jan 8 21:34:36 2009 From: james.hague@REDACTED (James Hague) Date: Thu, 8 Jan 2009 14:34:36 -0600 Subject: [erlang-questions] Calling into Lua from Erlang In-Reply-To: <6a3ae47e0901070810n5184c90brc8f230452c88e0ba@mail.gmail.com> References: <6a3ae47e0901070810n5184c90brc8f230452c88e0ba@mail.gmail.com> Message-ID: I recommend using a TCP socket for communication. I have done this successfully for communication between Erlang and BlitzMax (a BASIC with cross-platform graphics and sound capabilities). Building and decoding binaries is trivial in Erlang, and most scripting languages have libraries for doing the same thing (such as "pack" and "unpack" in Perl, and the "struct" module in Python). From sten@REDACTED Thu Jan 8 22:01:06 2009 From: sten@REDACTED (Sten Kvamme) Date: Thu, 08 Jan 2009 22:01:06 +0100 Subject: [erlang-questions] case or clause Message-ID: <1231448466.13913.9.camel@bautasten> I got the question the other day about erlang best practize, to use case or clause? (don't know if clasuse is the correct erlang name, but you know -- in a Prolog-way). Is erlang better/faster/leaner if I implement several "prolog" clauses as a case in a clause, or is it better/faster/leaner to reduce the use of case to situations when local variables in a clause is used in the case statement? Or is it just a matter of 'taste'? Thanks Sten Kvamme -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: Detta ?r en digitalt signerad meddelandedel URL: From richardc@REDACTED Thu Jan 8 23:04:39 2009 From: richardc@REDACTED (Richard Carlsson) Date: Thu, 08 Jan 2009 23:04:39 +0100 Subject: [erlang-questions] case or clause In-Reply-To: <1231448466.13913.9.camel@bautasten> References: <1231448466.13913.9.camel@bautasten> Message-ID: <49667877.7010606@it.uu.se> Sten Kvamme wrote: > I got the question the other day about erlang best practize, to use case > or clause? (don't know if clasuse is the correct erlang name, but you > know -- in a Prolog-way). > > Is erlang better/faster/leaner if I implement several "prolog" clauses > as a case in a clause, or is it better/faster/leaner to reduce the use > of case to situations when local variables in a clause is used in the > case statement? > > Or is it just a matter of 'taste'? You presumably mean the difference between f(Pattern1, ..., PatternN) -> ...; ... f(Pattern1, ..., PatternN) -> .... and f(X) -> case X of Pattern1 -> ...; ... PatternN -> ... end. In efficiency terms, there is no real difference. (If there is one, it should be considered a compiler problem that might be corrected at any time - do not waste your time on such microoptimizations.) Oh, and 'if' switches are no different - they're really a 'case'. So it's mostly a matter of taste. If your switch makes sense on its own, i.e., you can give it a reasonably straightforward name, then by all means break it out as a function - it will make the code easier to read and make it easier for you to see when there is common functionality that could be reused rather than copy-pasted. /Richard From sten@REDACTED Thu Jan 8 23:30:13 2009 From: sten@REDACTED (Sten Kvamme) Date: Thu, 08 Jan 2009 23:30:13 +0100 Subject: [erlang-questions] case or clause In-Reply-To: <49667877.7010606@it.uu.se> References: <1231448466.13913.9.camel@bautasten> <49667877.7010606@it.uu.se> Message-ID: <1231453813.13913.21.camel@bautasten> tor 2009-01-08 klockan 23:04 +0100 skrev Richard Carlsson: > Sten Kvamme wrote: > > I got the question the other day about erlang best practize, to use case > > or clause? (don't know if clasuse is the correct erlang name, but you > > know -- in a Prolog-way). > > > > Is erlang better/faster/leaner if I implement several "prolog" clauses > > as a case in a clause, or is it better/faster/leaner to reduce the use > > of case to situations when local variables in a clause is used in the > > case statement? > > > > Or is it just a matter of 'taste'? > > You presumably mean the difference between > > f(Pattern1, ..., PatternN) -> ...; > ... > f(Pattern1, ..., PatternN) -> .... > > and > > f(X) -> > case X of > Pattern1 -> ...; > ... > PatternN -> ... > end. > > In efficiency terms, there is no real difference. (If there is one, > it should be considered a compiler problem that might be corrected > at any time - do not waste your time on such microoptimizations.) > Oh, and 'if' switches are no different - they're really a 'case'. > > So it's mostly a matter of taste. If your switch makes sense on its > own, i.e., you can give it a reasonably straightforward name, then > by all means break it out as a function - it will make the code > easier to read and make it easier for you to see when there is > common functionality that could be reused rather than copy-pasted. > > /Richard > Ok, and if I'm using several clauses, is it like it is in Prolog a good idea to put the clauses that match most often at the top? /SK -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: Detta ?r en digitalt signerad meddelandedel URL: From rvirding@REDACTED Thu Jan 8 23:32:54 2009 From: rvirding@REDACTED (Robert Virding) Date: Thu, 8 Jan 2009 23:32:54 +0100 Subject: [erlang-questions] case or clause In-Reply-To: <49667877.7010606@it.uu.se> References: <1231448466.13913.9.camel@bautasten> <49667877.7010606@it.uu.se> Message-ID: <3dbc6d1c0901081432x2ac062bem5677221b323b9bc7@mail.gmail.com> This thread is also a comment to an earlier question by Edward Stow < ed.stow@REDACTED>. 2009/1/8 Richard Carlsson > > In efficiency terms, there is no real difference. (If there is one, > it should be considered a compiler problem that might be corrected > at any time - do not waste your time on such microoptimizations.) > Oh, and 'if' switches are no different - they're really a 'case'. Just to qualify Richard's comment. There is no difference at all, in the compiler function clauses are first transformed into a case. > So it's mostly a matter of taste. If your switch makes sense on its > own, i.e., you can give it a reasonably straightforward name, then > by all means break it out as a function - it will make the code > easier to read and make it easier for you to see when there is > common functionality that could be reused rather than copy-pasted. Sometimes I also do the opposite and use function clauses / case as a means of grouping to emphasize a code structure. So while you can write: foo(a, m, Z) -> ...; foo(a, n, Z) -> ...; foo(a, o, Z) -> ... ... it might sometimes better clarify your intent to group function clauses and write: foo(a, Y, Z) -> case Y of a -> ...; b -> ...; ... end; ... As already noted there is no difference in efficiency. This is probably not a PC thought for a functional language I sometimes feel that you can get too of a good thing and have too many small functions and it can make reading the whole more difficult. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From rvirding@REDACTED Fri Jan 9 00:23:53 2009 From: rvirding@REDACTED (Robert Virding) Date: Fri, 9 Jan 2009 00:23:53 +0100 Subject: [erlang-questions] case or clause In-Reply-To: <1231453813.13913.21.camel@bautasten> References: <1231448466.13913.9.camel@bautasten> <49667877.7010606@it.uu.se> <1231453813.13913.21.camel@bautasten> Message-ID: <3dbc6d1c0901081523g56bef455q74cb53230d840201@mail.gmail.com> 2009/1/8 Sten Kvamme > > Ok, and if I'm using several clauses, is it like it is in Prolog a good > idea to put the clauses that match most often at the top? It will never hurt but in many cases it will not help. The compiler is pretty good at optimising matching and will reorder clauses if it feels the result is better and the sequential matching semantics is preserved. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From vychodil.hynek@REDACTED Fri Jan 9 00:25:51 2009 From: vychodil.hynek@REDACTED (Hynek Vychodil) Date: Fri, 9 Jan 2009 00:25:51 +0100 Subject: [erlang-questions] case or clause In-Reply-To: <3dbc6d1c0901081432x2ac062bem5677221b323b9bc7@mail.gmail.com> References: <1231448466.13913.9.camel@bautasten> <49667877.7010606@it.uu.se> <3dbc6d1c0901081432x2ac062bem5677221b323b9bc7@mail.gmail.com> Message-ID: <20090108232552.CA94324013@relay.gooddata.com> I can see one subtle difference between mane short functions and less longer. If error occurred, back-trace is more useful for shorter functions. 2009/1/8 Robert Virding > This thread is also a comment to an earlier question by Edward Stow < > ed.stow@REDACTED>. > > 2009/1/8 Richard Carlsson > >> >> In efficiency terms, there is no real difference. (If there is one, >> it should be considered a compiler problem that might be corrected >> at any time - do not waste your time on such microoptimizations.) >> Oh, and 'if' switches are no different - they're really a 'case'. > > > Just to qualify Richard's comment. There is no difference at all, in the > compiler function clauses are first transformed into a case. > > >> So it's mostly a matter of taste. If your switch makes sense on its >> own, i.e., you can give it a reasonably straightforward name, then >> by all means break it out as a function - it will make the code >> easier to read and make it easier for you to see when there is >> common functionality that could be reused rather than copy-pasted. > > > Sometimes I also do the opposite and use function clauses / case as a means > of grouping to emphasize a code structure. So while you can write: > > foo(a, m, Z) -> ...; > foo(a, n, Z) -> ...; > foo(a, o, Z) -> ... > ... > > it might sometimes better clarify your intent to group function clauses and > write: > > foo(a, Y, Z) -> > case Y of > a -> ...; > b -> ...; > ... > end; > ... > > As already noted there is no difference in efficiency. This is probably not > a PC thought for a functional language I sometimes feel that you can get too > of a good thing and have too many small functions and it can make reading > the whole more difficult. > > Robert > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero! Try Good Data now for free: www.gooddata.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From samb@REDACTED Fri Jan 9 01:26:58 2009 From: samb@REDACTED (Sam Bobroff) Date: Fri, 9 Jan 2009 11:26:58 +1100 Subject: [erlang-questions] Starting Erlang as a Unix daemon In-Reply-To: <9b08084c0901080610p4782ace9t17523bdac458d2aa@mail.gmail.com> References: <20090107175301.3d64ee6d@samb-cm> <9b08084c0901080610p4782ace9t17523bdac458d2aa@mail.gmail.com> Message-ID: <20090109112658.6840cc19@samb-cm> Hi Joe, On Thu, 8 Jan 2009 15:10:46 +0100 Joe Armstrong wrote: > Read > > http://www.sics.se/~joe/tutorials/web_server/web_server.html#m2 > > This is specific to red-hat - but it is pretty easy to adapt to other > *nix systems > > /Joe Armstrong I already use a system very like the one described on your web page but I'm having several problems with it. They are: * The init script should return success (a zero exit code and an "OK" message) if and only if the server has started successfully. Running "erl -detached" (as your script does) unfortunately always returns success. It's just not acceptable to have a service report that it's started successfully when it hasn't. * Running the stop init script should only return success if it has actually managed to stop the server. (*) Without these properties a system can't be (safely) used from package managers like RPM and it also looks bad to system administrators (who have to use "ps" and look at some log file just to see if it's started up). I think I'll have to write a C wrapper program to handle this. It could register itself as a C node and run Erlang as a (non-detached) child process. It could then display any output from Erlang during the start up phase on the terminal, and once it receives a specific message from the Erlang application (via a simple message to the C node) it could detach itself from the terminal and return a result code (leaving Erlang running in the background). If that sounds useful to anyone else, let me know and I'll try to open source it :-) (Even better would be to include this functionality in erl itself, and provide a BIF that you could call from within your Erlang application to complete the detachment and return a result code from erl to the shell.) Cheers, Sam. (*) I've got this part working fairly well by using a system similar to yours but by also passing the result of the stop function out to the init script using halt(1) or halt(0). -- Sam Bobroff | sam@REDACTED | M5 Networks From dbudworth@REDACTED Fri Jan 9 03:14:27 2009 From: dbudworth@REDACTED (David Budworth) Date: Thu, 8 Jan 2009 20:14:27 -0600 Subject: [erlang-questions] case or clause In-Reply-To: <20090108232552.CA94324013@relay.gooddata.com> References: <1231448466.13913.9.camel@bautasten> <49667877.7010606@it.uu.se> <3dbc6d1c0901081432x2ac062bem5677221b323b9bc7@mail.gmail.com> <20090108232552.CA94324013@relay.gooddata.com> Message-ID: <2e23d1d20901081814l3cbb750fy3361864ca1f0f602@mail.gmail.com> is it more useful? if I have: f(a,Var) -> ok; f(b,Var) -> 10/0; f(c,Var) -> ok. and call: f(b,foo) The error message would say it failed in "f/2" It doesn't tell me at all which one it actually failed in. Buf for a gen_* you would know since they show the last message in, which usually lines up with a function. But in generic library code, it always seems hard-to-impossible to tell from the stack. I end up adding print statements all over and re-producing to find offending function. That being said, I actually prefer many little functions anyway as it tends to be easier to read at a glance. 2009/1/8 Hynek Vychodil > I can see one subtle difference between mane short functions and less > longer. If error occurred, back-trace is more useful for shorter functions. > > 2009/1/8 Robert Virding > >> This thread is also a comment to an earlier question by Edward Stow < >> ed.stow@REDACTED>. >> >> 2009/1/8 Richard Carlsson >> >>> >>> In efficiency terms, there is no real difference. (If there is one, >>> it should be considered a compiler problem that might be corrected >>> at any time - do not waste your time on such microoptimizations.) >>> Oh, and 'if' switches are no different - they're really a 'case'. >> >> >> Just to qualify Richard's comment. There is no difference at all, in the >> compiler function clauses are first transformed into a case. >> >> >>> So it's mostly a matter of taste. If your switch makes sense on its >>> own, i.e., you can give it a reasonably straightforward name, then >>> by all means break it out as a function - it will make the code >>> easier to read and make it easier for you to see when there is >>> common functionality that could be reused rather than copy-pasted. >> >> >> Sometimes I also do the opposite and use function clauses / case as a >> means of grouping to emphasize a code structure. So while you can write: >> >> foo(a, m, Z) -> ...; >> foo(a, n, Z) -> ...; >> foo(a, o, Z) -> ... >> ... >> >> it might sometimes better clarify your intent to group function clauses >> and write: >> >> foo(a, Y, Z) -> >> case Y of >> a -> ...; >> b -> ...; >> ... >> end; >> ... >> >> As already noted there is no difference in efficiency. This is probably >> not a PC thought for a functional language I sometimes feel that you can get >> too of a good thing and have too many small functions and it can make >> reading the whole more difficult. >> >> Robert >> >> >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions@REDACTED >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > > > > -- > --Hynek (Pichi) Vychodil > > Analyze your data in minutes. Share your insights instantly. Thrill your > boss. Be a data hero! > Try Good Data now for free: www.gooddata.com > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From koushik.list@REDACTED Fri Jan 9 03:44:51 2009 From: koushik.list@REDACTED (Koushik Narayanan) Date: Fri, 9 Jan 2009 08:14:51 +0530 Subject: [erlang-questions] Starting Erlang as a Unix daemon In-Reply-To: <20090109112658.6840cc19@samb-cm> References: <20090107175301.3d64ee6d@samb-cm> <9b08084c0901080610p4782ace9t17523bdac458d2aa@mail.gmail.com> <20090109112658.6840cc19@samb-cm> Message-ID: <20090109024451.GA10847@bsd.top> Hi, On Fri, Jan 09, 2009 at 11:26:58AM +1100, Sam Bobroff wrote: > > Without these properties a system can't be (safely) used from package > managers like RPM and it also looks bad to system administrators (who > have to use "ps" and look at some log file just to see if it's started > up). Any thoughts on using erlrc for this purpose? http://code.google.com/p/erlrc It claims to solve this problem, though I am not very sure how it works. Regards, Koushik Narayanan From raimo+erlang-questions@REDACTED Fri Jan 9 09:42:25 2009 From: raimo+erlang-questions@REDACTED (Raimo Niskanen) Date: Fri, 9 Jan 2009 09:42:25 +0100 Subject: [erlang-questions] : : : : : driver_entry stop() and driver_async() interaction In-Reply-To: <781dd98c0812190708y66eb7fb0pd48c7fbc0f9870d8@mail.gmail.com> References: <48F75F09.7020108@alertlogic.net> <491335F5.3060602@alertlogic.net> <20081107104759.GA1287@erix.ericsson.se> <494A44FB.5030309@alertlogic.net> <20081218155426.GC23981@erix.ericsson.se> <20081219135220.GB10968@erix.ericsson.se> <20081219143620.GA13337@erix.ericsson.se> <781dd98c0812190708y66eb7fb0pd48c7fbc0f9870d8@mail.gmail.com> Message-ID: <20090109084225.GA308@erix.ericsson.se> On Fri, Dec 19, 2008 at 07:08:11AM -0800, Chris Newcombe wrote: > > We plan while fixing the bug with async_free() mentioned below > > to introduce a reference counter of async jobs so it will be > > guaranteed that stop() is not called until all async jobs are done. > > Excellent. But please could you provide APIs to increment and > decrement that reference count, so that drivers that implement their > own private thread-pools can achieve the same behaviour? Sounds a bit hackish, but why not; drivers tend to be hackish. An even hackier hack would be to use the I/O queue for this, and that even works today. > > Also, I hate to cause feature creep, but if you do implement the above > reference count/delayed 'stop', please could you also add an optional > "prepare to stop" callback, which the VM calls when the Erlang code > closes the port (e.g. the port owner process dies, or something > explicitly closes the port)? Some drivers often have fairly > long-running operations (seconds/minutes) running in their own > threads, and would like timely notification that they should force > such jobs to terminate, to allow "stop" to be called as soon as > possible (the berkeley_db driver has to do this). i.e. It's not > always the case that running async jobs should be left to complete in > their own sweet time. (Note that this is different from 'cancelling' > pending-but-not-yet-started jobs.) Was not this (later in the same mail from me) enough? : > Raimo wrote: > > While we are at it we plan to introduce a driver flag > > indicating that the driver wants to be called on > > flush() if there are pending async jobs (as well as > > today if the IO queue is not empty). : Today the flush() callback is called when the port gets killed e.g gets an exit signal from its linked owner when it dies, if there is data in the I/O queue. Then the stop() callback is called when the I/O queue is emptied. > > Rationale: It does actually matter a lot to some drivers that "stop" : -- / Raimo Niskanen, Erlang/OTP, Ericsson AB From klacke@REDACTED Fri Jan 9 10:03:54 2009 From: klacke@REDACTED (Claes Wikstrom) Date: Fri, 09 Jan 2009 10:03:54 +0100 Subject: [erlang-questions] Yaws 1.78 Message-ID: <496712FA.4020305@hyber.org> A new release of Yaws is available at http://yaws.hyber.org It contains quite a lot of minor fixes and enhancements and also a brand new great feature. Steve Vinoski has implemented support for sendfile. It works on Linux, FreeBSD and OSX. Steve has published some measurements at http://steve.vinoski.net/blog/ indicating excellent performance improvements. As usual code, release notes and docs at http://yaws.hyber.org Enjoy /klacke From rtrlists@REDACTED Fri Jan 9 10:04:16 2009 From: rtrlists@REDACTED (Robert Raschke) Date: Fri, 9 Jan 2009 09:04:16 +0000 Subject: [erlang-questions] case or clause In-Reply-To: <1231448466.13913.9.camel@bautasten> References: <1231448466.13913.9.camel@bautasten> Message-ID: <6a3ae47e0901090104n2a64a908pcdc4db2082737aac@mail.gmail.com> 2009/1/8 Sten Kvamme : > I got the question the other day about erlang best practize, to use case > or clause? (don't know if clasuse is the correct erlang name, but you > know -- in a Prolog-way). > > Is erlang better/faster/leaner if I implement several "prolog" clauses > as a case in a clause, or is it better/faster/leaner to reduce the use > of case to situations when local variables in a clause is used in the > case statement? > > Or is it just a matter of 'taste'? One thing to bear in mind is that error messages arising from nested cases can be hard to decipher sometimes. I try to keep my functions simple enoug, not to run into this. So, a function that would normally have a case within a case, I tend to rewrite as a function with multiple heads and only one case inside, where needed. Robby From richardc@REDACTED Fri Jan 9 10:18:35 2009 From: richardc@REDACTED (Richard Carlsson) Date: Fri, 09 Jan 2009 10:18:35 +0100 Subject: [erlang-questions] case or clause In-Reply-To: <1231453813.13913.21.camel@bautasten> References: <1231448466.13913.9.camel@bautasten> <49667877.7010606@it.uu.se> <1231453813.13913.21.camel@bautasten> Message-ID: <4967166B.9060808@it.uu.se> Sten Kvamme wrote: > Ok, and if I'm using several clauses, is it like it is in Prolog a good > idea to put the clauses that match most often at the top? Like Robert said, the compiler may reorder tests "under the hood" for better efficiency, as long as it does not change the observable behaviour in any way, which should always be as if the clauses were tried in strictly top-down order. However, the compiler knows nothing about the statistical probability of the different clauses, so if you know more, you can reduce the amount of unnecessary tests by putting more probable clauses first. This is also a kind of microoptimization, that I don't recommend spending any effort on unless you are writing something like a heavily used abstract data type such as the gb_trees and array modules. In most other cases, clarity of expression should be your guiding principle: optimize for maintainability first, and for efficiency when you know your bottlenecks. /Richard From hans.bolinder@REDACTED Fri Jan 9 10:25:08 2009 From: hans.bolinder@REDACTED (Hans Bolinder) Date: Fri, 9 Jan 2009 10:25:08 +0100 Subject: [erlang-questions] QLC vs mnesia:select/read In-Reply-To: References: Message-ID: <18791.6132.499915.496534@ornendil.du.uab.ericsson.se> [Ryan Lepidi:] > I am just learning Erlang and was recently reading up on the Mnesia section. > It seems that QLC commands and the mnesia:select and mnesia:read functions > do the same thing. Are there any drawbacks, functionality wise or speed > wise, to using one over the other? Because to me it seems that QLC is > simpler and more readable. Is it just a matter of preference? mnesia:select() is more general than mnesia:read() as it takes match specifications as arguments. Matchspecs are described in the ERTS user's guide. There is a pseudo function ets:fun2ms() that makes is easier to write matchspecs. See also ms_transform(3). qlc translates queries to mnesia:{index_}read() or mnesia:select() when possible, but there is an overhead at the beginning of the evaluation of a query which makes qlc somewhat slower. qlc is more general than matchspecs as filters can be any Erlang expressions and data from several tables can be tested and combined easily. Best regards, Hans Bolinder, Erlang/OTP team, Ericsson From bqt@REDACTED Thu Jan 8 23:51:38 2009 From: bqt@REDACTED (Johnny Billquist) Date: Thu, 08 Jan 2009 23:51:38 +0100 Subject: [erlang-questions] case or clause In-Reply-To: <1231453813.13913.21.camel@bautasten> References: <1231448466.13913.9.camel@bautasten> <49667877.7010606@it.uu.se> <1231453813.13913.21.camel@bautasten> Message-ID: <4966837A.7050007@softjar.se> Sten Kvamme wrote: > tor 2009-01-08 klockan 23:04 +0100 skrev Richard Carlsson: >> Sten Kvamme wrote: >>> I got the question the other day about erlang best practize, to use case >>> or clause? (don't know if clasuse is the correct erlang name, but you >>> know -- in a Prolog-way). >>> >>> Is erlang better/faster/leaner if I implement several "prolog" clauses >>> as a case in a clause, or is it better/faster/leaner to reduce the use >>> of case to situations when local variables in a clause is used in the >>> case statement? >>> >>> Or is it just a matter of 'taste'? >> You presumably mean the difference between >> >> f(Pattern1, ..., PatternN) -> ...; >> ... >> f(Pattern1, ..., PatternN) -> .... >> >> and >> >> f(X) -> >> case X of >> Pattern1 -> ...; >> ... >> PatternN -> ... >> end. >> >> In efficiency terms, there is no real difference. (If there is one, >> it should be considered a compiler problem that might be corrected >> at any time - do not waste your time on such microoptimizations.) >> Oh, and 'if' switches are no different - they're really a 'case'. >> >> So it's mostly a matter of taste. If your switch makes sense on its >> own, i.e., you can give it a reasonably straightforward name, then >> by all means break it out as a function - it will make the code >> easier to read and make it easier for you to see when there is >> common functionality that could be reused rather than copy-pasted. >> >> /Richard >> > > Ok, and if I'm using several clauses, is it like it is in Prolog a good > idea to put the clauses that match most often at the top? Don't make the mistake of thinking like Prolog when you write Erlang, or you'll be severly bitten. Erlang will *not* match several clauses. It will stop matching at the first "hit". No backtrace like in Prolog. And it does the matches in the same order as the clauses are written in the source. Top down... Johnny From bqt@REDACTED Mon Jan 5 01:44:32 2009 From: bqt@REDACTED (Johnny Billquist) Date: Mon, 05 Jan 2009 01:44:32 +0100 Subject: [erlang-questions] Flash client communication with Erlang Server problem In-Reply-To: References: Message-ID: <496157F0.6030903@softjar.se> Have you tried running tcpdump or something similar to verity that you actually send what you think? Johnny Ryan Lepidi wrote: > This is an erlang problem, it seems. I have this code to test the client > sending data, written in Actionscript 3: > > Code: > var socket:Socket=new Socket("localhost", 2345); > socket.addEventListener(Event.CONNECT, connected); > > private function connected(event:Event):void { > socket.writeInt(12); //packet length, should be correct? 4 bytes each? > socket.writeInt(3); > socket.writeInt(6); > socket.writeInt(9); > socket.flush(); > } > > > Then I have this small server, written in Erlang: > > Code: > start_nano_server() -> > {ok, Listen} = gen_tcp:listen(2345, [binary, {packet, 0}, > {reuseaddr, true}, > {active, true}, > {packet_size, 128}]), > {ok, Socket} = gen_tcp:accept(Listen), > gen_tcp:close(Listen), > receive_data(Socket, []). > > receive_data(Socket, SoFar) -> > receive > {tcp,Socket,Bin} -> > receive_data(Socket, [Bin|SoFar]); > {tcp_closed,Socket} -> > Bytes=list_to_binary(reverse(SoFar)), > io:format("~p~n",[Bytes]) > end. > > > Now, no matter what I send from the client, I ALWAYS get > [<<0,0,0,4,0,0,0,32>>] as the response. I can try writing bytes to the > socket directly instead of ints, and I get the same thing. I can write > more or less data, same result. UTF strings same result. Even when > specifying "4" as the packet header length, I just get the same > consistant result of [<<0,0,0,32>>] instead. I don't understand what I'm > doing wrong here. > > > ------------------------------------------------------------------------ > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From torben.lehoff@REDACTED Fri Jan 9 14:14:58 2009 From: torben.lehoff@REDACTED (Torben Hoffmann) Date: Fri, 9 Jan 2009 14:14:58 +0100 Subject: [erlang-questions] Installation of exprecs.erl Message-ID: Hi, I have put exprecs.erl into util/src/ and added it to my util/ebin/util.app file but when I do my make it keeps complaining about src/record_logger.erl:none: error in parse transform 'exprecs': {undef, [{exprecs,parse_transform, [[{attribute,1,file, {"src/record_logger.erl",1}}, {attribute,17,module,record_logger}, {attribute,1,file, {"/home/pap/subv/util-0.1/../pap_app-0.1/include/my_types.hrl", 1}}, I have my records definded in a .hrl which is included in the module where I want to utilise the exprecs functionality like this: -compiler({parse_transform,exprecs}). -include("my_types.hrl"). -export([fields/1]). -export_records([ % huge list with all the records from my_types.hrl that I want to get the field names for ]). fields(Rec) -> '#info-'(fields,Rec). Have I installed exprecs incorrectly? Thanks, Torben -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomasl_erlang@REDACTED Fri Jan 9 13:37:25 2009 From: thomasl_erlang@REDACTED (Thomas Lindgren) Date: Fri, 9 Jan 2009 04:37:25 -0800 (PST) Subject: [erlang-questions] case or clause In-Reply-To: <2e23d1d20901081814l3cbb750fy3361864ca1f0f602@mail.gmail.com> Message-ID: <690065.73594.qm@web111404.mail.gq1.yahoo.com> --- On Fri, 1/9/09, David Budworth wrote: > is it more useful? > if I have: > > f(a,Var) -> ok; > f(b,Var) -> 10/0; > f(c,Var) -> ok. > > and call: f(b,foo) > > The error message would say it failed in "f/2" > It doesn't tell me at all which one it actually failed > in. You could try smart_exceptions in jungerl (or github if you're feeling brave, where I'm working on a rewrite). It tries to mark all exceptions with module, line, etc. I have found it quite helpful, but it's not a bulletproof drop-in replacement. Ideally, the compiler should of course do this instead. Best, Thomas From andrew@REDACTED Fri Jan 9 20:10:08 2009 From: andrew@REDACTED (Andrew Thompson) Date: Fri, 9 Jan 2009 14:10:08 -0500 Subject: [erlang-questions] [ANN] mod_erlang_event for FreeSWITCH Message-ID: <20090109191007.GD5210@hijacked.us> Hi, Today, I'd like to offically announce mod_erlang_event for FreeSWITCH, a way to allow FreeSWITCH to participate in an Erlang node cluster. You can send it requests, it responds, you can configure it to make requests to other nodes, etc. This lets you control mosts aspects of FreeSWITCH, an open source class-5 softswitch, from Erlang in native Erlang terms. Unlike mod_event_socket, the module that mod_erlang_event is modeled on, mod_erlang_event intelligently routes events/replies/requests to the correct erlang process on the correct node, so you don't have to spend time determining what process a particular reply or request should go to. Also, everything is returned in erlang's term format too, so parsing is trivial. Additionally, I also added the ability to 'bind' config lookups to allow you to indicate a particular process should be asked for certain classes of FreeSWITCH configuration (eg. dialplan, SIP configurations, etc). This allows you to route calls by querying an erlang process for routing information, allow/deny sip registrations from an erlang process, etc. Here's the page on the FreeSWITCH wiki for more information: http://wiki.freeswitch.org/wiki/Mod_erlang_event As of FreeSWITCH 1.0.2, mod_erlang_event is part of the official releases. If anyone has any problems or questions, I'm happy to help. I'll be making an announcement about the project I wrote this module for later today, which is also going to be open source. Andrew From ad.sergey@REDACTED Fri Jan 9 20:14:54 2009 From: ad.sergey@REDACTED (Sergey S) Date: Fri, 9 Jan 2009 11:14:54 -0800 Subject: [erlang-questions] install_release/1 always returns enoent error Message-ID: Hello. While reading OTP Design Principles (Release Handling part) I've found that function release_handler:install_release/1 doesn't work as expected. It returns a strange error, complaining about relup file: Eshell V5.6.5 (abort with ^G) 1> release_handler:install_release("B"). {error,{enoent,"/usr/lib/erlang/releases/R12B/relup"}} And it's true - there is no such a file. Instead of $ROOT/releases/R12B my relup file resides in $ROOT/releases/B. I have no idea why release_handler searches for relup in R12B dir :/ It looks like a bug... I tried to copy my relup to R12B dir by hand, but It didn't help: 2> release_handler:install_release("B"). {error,{bad_relup_file,"/usr/lib/erlang/releases/R12B/relup"}} Then, I've tried to find out the solution through Google. But what I've found (please, look at the comments for this article) was: http://spawnlink.com/articles/performing-real-time-upgrades-to-an-otp-system/ There are people who run into the same problem. Unfortunatelly nobody gave solution to this problem. Here is the sources of my test app (1.4Kb): http://rapidshare.com/files/181485268/foo_app.tar.gz.html Thanks! -- Sergey -------------- next part -------------- An HTML attachment was scrubbed... URL: From kaiduanx@REDACTED Fri Jan 9 22:39:52 2009 From: kaiduanx@REDACTED (Kaiduan Xie) Date: Fri, 9 Jan 2009 16:39:52 -0500 Subject: [erlang-questions] install_release/1 always returns enoent error In-Reply-To: References: Message-ID: I think you have to do install_release() from the erlang shell which starts release A. Please also read System Principles documentation http://www.erlang.org/doc/pdf/system_principles.pdf on how to start the first target system. kaiduan 2009/1/9 Sergey S > Hello. > > While reading OTP Design Principles (Release Handling part) I've found that > function release_handler:install_release/1 doesn't work as expected. It > returns a strange error, complaining about relup file: > > Eshell V5.6.5 (abort with ^G) > 1> release_handler:install_release("B"). > {error,{enoent,"/usr/lib/erlang/releases/R12B/relup"}} > > And it's true - there is no such a file. Instead of $ROOT/releases/R12B my > relup file resides in $ROOT/releases/B. I have no idea why release_handler > searches for relup in R12B dir :/ It looks like a bug... > > I tried to copy my relup to R12B dir by hand, but It didn't help: > > 2> release_handler:install_release("B"). > {error,{bad_relup_file,"/usr/lib/erlang/releases/R12B/relup"}} > > Then, I've tried to find out the solution through Google. But what I've > found (please, look at the comments for this article) was: > http://spawnlink.com/articles/performing-real-time-upgrades-to-an-otp-system/ > > There are people who run into the same problem. Unfortunatelly nobody gave > solution to this problem. > > Here is the sources of my test app (1.4Kb): > http://rapidshare.com/files/181485268/foo_app.tar.gz.html > > Thanks! > > -- > Sergey > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter@REDACTED Fri Jan 9 22:45:03 2009 From: peter@REDACTED (Peter Sabaini) Date: Fri, 9 Jan 2009 22:45:03 +0100 Subject: [erlang-questions] mnesia: composite keys? Message-ID: <200901092245.09386.peter@sabaini.at> Hello list, I've read[1] that mnesia doesn't support composite keys. It seems I can use keys made up of tuples though: (emacs@REDACTED)11> mnesia:create_table(test, [{attributes, [id, data]}]). {atomic,ok} (emacs@REDACTED)19> Ins = fun() -> mnesia:write({test, {a_key, 0}, "asdfasdf"}) end. #Fun (emacs@REDACTED)20> mnesia:transaction(Ins). {atomic,ok} (emacs@REDACTED)21> R = fun() -> mnesia:read(test, {a_key, 0}) end. #Fun (emacs@REDACTED)22> mnesia:transaction(R). {atomic,[{test,{a_key,0},"asdfasdf"}]} Is tuples as keys common practice or A Really Bad Idea(tm)? thx, peter. [1] http://www.erlang.org/pipermail/erlang-questions/2008-February/032903.html -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part. URL: From ad.sergey@REDACTED Fri Jan 9 23:44:28 2009 From: ad.sergey@REDACTED (Sergey S) Date: Fri, 9 Jan 2009 14:44:28 -0800 Subject: [erlang-questions] install_release/1 always returns enoent error In-Reply-To: References: Message-ID: Hello. On Fri, Jan 9, 2009 at 1:39 PM, Kaiduan Xie wrote: > I think you have to do install_release() from the erlang shell which starts > release A. I've already tried that. It leads to the same error. Please also read System Principles documentation > http://www.erlang.org/doc/pdf/system_principles.pdf on how to start the > first target system. I've read that. I'm using initial Erlang system created by my packet manager as a target system. I start erlang by the following command: sudo erl -boot /usr/lib/erlang/releases/A/start I also tried adding "-mode embedded". (I'm using sudo so that Erlang can correctly do unpack_release/1) -- Sergey -------------- next part -------------- An HTML attachment was scrubbed... URL: From japerk@REDACTED Fri Jan 9 23:48:13 2009 From: japerk@REDACTED (Jacob Perkins) Date: Fri, 9 Jan 2009 14:48:13 -0800 Subject: [erlang-questions] mnesia: composite keys? Message-ID: > I've read[1] that mnesia doesn't support composite keys. It seems I can use > keys made up of tuples though: > > (emacs@REDACTED)11> mnesia:create_table(test, [{attributes, [id, data]}]). > {atomic,ok} > (emacs@REDACTED)19> Ins = fun() -> mnesia:write({test, {a_key, 0}, > "asdfasdf"}) > end. > #Fun > (emacs@REDACTED)20> mnesia:transaction(Ins). > {atomic,ok} > (emacs@REDACTED)21> R = fun() -> mnesia:read(test, {a_key, 0}) end. > #Fun > (emacs@REDACTED)22> mnesia:transaction(R). > {atomic,[{test,{a_key,0},"asdfasdf"}]} > > > Is tuples as keys common practice or A Really Bad Idea(tm)? > Tuple keys can actually be a Really Good Idea, especially with ordered_set tables. Jacob -------------- next part -------------- An HTML attachment was scrubbed... URL: From dking@REDACTED Sat Jan 10 00:02:39 2009 From: dking@REDACTED (David King) Date: Fri, 9 Jan 2009 15:02:39 -0800 Subject: [erlang-questions] mnesia: composite keys? In-Reply-To: <200901092245.09386.peter@sabaini.at> References: <200901092245.09386.peter@sabaini.at> Message-ID: > Is tuples as keys common practice or A Really Bad Idea(tm)? The table line_item :: {order_no,item_no} -> {cost, quantity, comment} should work just fine, the major downside would be that while there's an automatic index on the tuple {order_no,item_no}, and you can make an index on 'cost' or 'quantity', you can't make an index on 'order_no' or 'item_no' (because they aren't really fields), so it makes asking for all of the items from a given 'order_no' a little harder You could cheat by copying the 'order_no' or 'item_no' into the record and making an index on that, but you'd have to maintain that in the application From andrew@REDACTED Sat Jan 10 00:06:50 2009 From: andrew@REDACTED (Andrew Thompson) Date: Fri, 9 Jan 2009 18:06:50 -0500 Subject: [erlang-questions] [ANN] Spice Telephony - an open source FreeSWITCH/Erlang callcenter platform Message-ID: <20090109230650.GF5210@hijacked.us> Hi, Today I'd like to announce the open-sourcing of a distributed callcenter platform I've been designing/building using FreeSWITCH/Erlang. The goal is to allow multiple callcenter branch offices to operate seamlessly as a whole, or even just scale one large one beyond hardware/software limits by partitioning the inbound lines/agents across multiple servers. You can read more about the design here: http://opencsm.org/wiki/index.php/Spice_Telephony And a quick overview of planned features: * Inbound/Outbound support * Media type agnostic (voice, email, chat, video(?)) * Skill based routing * Agent phone agnostic (SIP or POTS line) * Dynamic wrapup time * Web or fat client interface And you can download a very early work in progress snapshot of the code from http://opencsm.org . We're also open sourcing our customer service management application too, which is also available for download there. If anyone is interested in callcenter development using FreeSWITCH and/or Erlang, we welcome participation at any level. We don't have public source control or a bug tracker yet, but please bear with us; they're on the way. Thanks, Andrew Thompson - opencsm.org From victor.sovetov@REDACTED Sat Jan 10 00:04:50 2009 From: victor.sovetov@REDACTED (Viktor Sovietov) Date: Fri, 9 Jan 2009 15:04:50 -0800 (PST) Subject: [erlang-questions] mnesia: composite keys? In-Reply-To: <200901092245.09386.peter@sabaini.at> References: <200901092245.09386.peter@sabaini.at> Message-ID: <71f43ded-7365-4e63-891c-17c1baccf775@y1g2000pra.googlegroups.com> If you use ordered_set tables that tuple keys are useful, because you can organize hierarchies inside one table. In other hand, you can't save such tables on disk, so... Anyway, Erlang isn't MUMPS, so you simply have not any mechanism to operate with complex keys. Sincerely, --Victor On Jan 9, 11:45?pm, Peter Sabaini wrote: > Hello list, > > I've read[1] that mnesia doesn't support composite keys. It seems I can use > keys made up of tuples though: > > (emacs@REDACTED)11> mnesia:create_table(test, [{attributes, [id, data]}]). > {atomic,ok} > (emacs@REDACTED)19> Ins = fun() -> mnesia:write({test, {a_key, 0}, "asdfasdf"}) > end. > #Fun > (emacs@REDACTED)20> mnesia:transaction(Ins). > {atomic,ok} > (emacs@REDACTED)21> R = fun() -> mnesia:read(test, {a_key, 0}) end. > #Fun > (emacs@REDACTED)22> mnesia:transaction(R). > {atomic,[{test,{a_key,0},"asdfasdf"}]} > > Is tuples as keys common practice or A Really Bad Idea(tm)? > > thx, > peter. > > [1]http://www.erlang.org/pipermail/erlang-questions/2008-February/032903... > > ?signature.asc > < 1KViewDownload > > _______________________________________________ > erlang-questions mailing list > erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions From kaiduanx@REDACTED Sat Jan 10 01:36:13 2009 From: kaiduanx@REDACTED (Kaiduan Xie) Date: Fri, 9 Jan 2009 19:36:13 -0500 Subject: [erlang-questions] install_release/1 always returns enoent error In-Reply-To: References: Message-ID: Please follow the System Principles closely and use the source code target_system.erl it provides. I had used the way to do hot update and it worked well. On Fri, Jan 9, 2009 at 5:44 PM, Sergey S wrote: > Hello. > > On Fri, Jan 9, 2009 at 1:39 PM, Kaiduan Xie wrote: > >> I think you have to do install_release() from the erlang shell which >> starts release A. > > > I've already tried that. It leads to the same error. > > Please also read System Principles documentation >> http://www.erlang.org/doc/pdf/system_principles.pdf on how to start the >> first target system. > > > I've read that. I'm using initial Erlang system created by my packet > manager as a target system. I start erlang by the following command: > > sudo erl -boot /usr/lib/erlang/releases/A/start > > I also tried adding "-mode embedded". (I'm using sudo so that Erlang can > correctly do unpack_release/1) > > -- > Sergey > -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter@REDACTED Sat Jan 10 00:39:57 2009 From: peter@REDACTED (Peter Sabaini) Date: Sat, 10 Jan 2009 00:39:57 +0100 Subject: [erlang-questions] mnesia: composite keys? In-Reply-To: References: <200901092245.09386.peter@sabaini.at> Message-ID: <200901100040.07323.peter@sabaini.at> On Saturday 10 January 2009 00:02:39 David King wrote: > > Is tuples as keys common practice or A Really Bad Idea(tm)? > > The table > > line_item :: {order_no,item_no} -> {cost, quantity, comment} > > should work just fine, the major downside would be that while there's > an automatic index on the tuple {order_no,item_no}, and you can make > an index on 'cost' or 'quantity', you can't make an index on > 'order_no' or 'item_no' (because they aren't really fields), so it > makes asking for all of the items from a given 'order_no' a little > harder Yep, I thought so -- but this won't be an issue for my app. Thanks, all. peter. > You could cheat by copying the 'order_no' or 'item_no' into the record > and making an index on that, but you'd have to maintain that in the > application -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part. URL: From ed.stow@REDACTED Sat Jan 10 02:42:53 2009 From: ed.stow@REDACTED (Edward Stow) Date: Sat, 10 Jan 2009 12:42:53 +1100 Subject: [erlang-questions] inets and ssl start/1 stop/1 Message-ID: Hi Within a yaws application I am start/1 ing inets and ssl to send a post request to an external server. Should I be stopping these services when my request returns. I assume that for each yaws request a new process is started and that the inets ssl services are stopped when the process exits. -- Edward Stow From saleyn@REDACTED Sat Jan 10 04:23:41 2009 From: saleyn@REDACTED (Serge Aleynikov) Date: Fri, 09 Jan 2009 22:23:41 -0500 Subject: [erlang-questions] Starting Erlang as a Unix daemon In-Reply-To: <20090109112658.6840cc19@samb-cm> References: <20090107175301.3d64ee6d@samb-cm> <9b08084c0901080610p4782ace9t17523bdac458d2aa@mail.gmail.com> <20090109112658.6840cc19@samb-cm> Message-ID: <496814BD.2010002@gmail.com> Sam, Actually there are already tools that can help you with this task. Use run_erl (http://www.erlang.org/doc/apps/erts/index.html) in order to start your node (without providing the -daemon option). In your shell script run run_erl as a background task, and use erl_call (from erl_interface) to attempt connecting to the node or alternatively just grep the erlang.log.1 (produced by run_erl) for expected successful startup message. Lately I've been using this approach to install and run nodes with help of chkconfig on Linux quite successfully. The outer shell script is run as root, and all it does is starting run_erl in the background as a non-privileged user, detecting its death and restarting the process using some throttling rate to avoid too frequent restarts in case of bad configuration or something like that. We've had some bad experience with the -heart option to erl in combination with run_erl. As I recall two issues came up: 1. The later has some race conditions related to signal handling and calling select(). We are actually running a patched version of run_erl that fixes the issue. http://www.erlang.org/pipermail/erlang-patches/2006-January/000147.html 2. On a few occasions we've seen on a busy node heart missing some heartbeat replies and killing the monitored node. Some details on this can be found here: http://erlang.org/pipermail/erlang-questions/2006-December/024365.html On the contrary the shell-based startup alternative described above works pretty stably. Serge Sam Bobroff wrote: > I already use a system very like the one described on your web page but > I'm having several problems with it. They are: > > * The init script should return success (a zero exit code and an "OK" > message) if and only if the server has started successfully. Running > "erl -detached" (as your script does) unfortunately always returns > success. It's just not acceptable to have a service report that it's > started successfully when it hasn't. > * Running the stop init script should only return success if it has > actually managed to stop the server. (*) > > Without these properties a system can't be (safely) used from package > managers like RPM and it also looks bad to system administrators (who > have to use "ps" and look at some log file just to see if it's started > up). > > I think I'll have to write a C wrapper program to handle this. It could > register itself as a C node and run Erlang as a (non-detached) child > process. It could then display any output from Erlang during the start > up phase on the terminal, and once it receives a specific message from > the Erlang application (via a simple message to the C node) it could > detach itself from the terminal and return a result code (leaving Erlang > running in the background). If that sounds useful to anyone else, let > me know and I'll try to open source it :-) > > (Even better would be to include this functionality in erl itself, and > provide a BIF that you could call from within your Erlang application to > complete the detachment and return a result code from erl to the shell.) > > Cheers, > > Sam. > > (*) I've got this part working fairly well by using a system similar to > yours but by also passing the result of the stop function out to the > init script using halt(1) or halt(0). From juanjo@REDACTED Sat Jan 10 06:39:36 2009 From: juanjo@REDACTED (Juan Jose Comellas) Date: Sat, 10 Jan 2009 03:39:36 -0200 Subject: [erlang-questions] [ANN] mod_erlang_event for FreeSWITCH In-Reply-To: <20090109191007.GD5210@hijacked.us> References: <20090109191007.GD5210@hijacked.us> Message-ID: <1c3be50f0901092139y7699ce90n1fa8706e32ae2c05@mail.gmail.com> Nice work! Have you thought about using binaries for the data that is sent and received from FreeSWITCH instead of using Erlang strings? Also, being able to return config/dialplan/directory data as tuple lists instead of an XML string would probably be much more comfortable. This does not necessarily have to happen in mod_erlang_event; there could be a wrapper in Erlang that takes care of these conversions. On Fri, Jan 9, 2009 at 5:10 PM, Andrew Thompson wrote: > Hi, > > Today, I'd like to offically announce mod_erlang_event for FreeSWITCH, a > way to allow FreeSWITCH to participate in an Erlang node cluster. You > can send it requests, it responds, you can configure it to make requests > to other nodes, etc. This lets you control mosts aspects of FreeSWITCH, > an open source class-5 softswitch, from Erlang in native Erlang terms. > > Unlike mod_event_socket, the module that mod_erlang_event is modeled on, > mod_erlang_event intelligently routes events/replies/requests to the > correct erlang process on the correct node, so you don't have to spend > time determining what process a particular reply or request should go > to. Also, everything is returned in erlang's term format too, so parsing > is trivial. > > Additionally, I also added the ability to 'bind' config lookups to allow > you to indicate a particular process should be asked for certain classes > of FreeSWITCH configuration (eg. dialplan, SIP configurations, etc). > This allows you to route calls by querying an erlang process for routing > information, allow/deny sip registrations from an erlang process, etc. > > Here's the page on the FreeSWITCH wiki for more information: > > http://wiki.freeswitch.org/wiki/Mod_erlang_event > > As of FreeSWITCH 1.0.2, mod_erlang_event is part of the official > releases. If anyone has any problems or questions, I'm happy to help. > I'll be making an announcement about the project I wrote this module for > later today, which is also going to be open source. > > Andrew > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From klacke@REDACTED Fri Jan 9 23:58:44 2009 From: klacke@REDACTED (=?ISO-8859-1?Q?Claes_Wikstr=F6m?=) Date: Fri, 09 Jan 2009 23:58:44 +0100 Subject: [erlang-questions] Starting Erlang as a Unix daemon In-Reply-To: <20090107175301.3d64ee6d@samb-cm> References: <20090107175301.3d64ee6d@samb-cm> Message-ID: <4967D6A4.4090106@hyber.org> Sam Bobroff wrote: > > I've tried using both "run_erl" and "erl -detached" but both of them > seem to fork and exit before any user code is run. > > Does anyone know a good way to handle this? > There is unfortunately no good way to do this. The only option is to have some auxiliary code that runs after the detached erl process and checks for liveness. /klacke From ad.sergey@REDACTED Sat Jan 10 13:25:28 2009 From: ad.sergey@REDACTED (Sergey S) Date: Sat, 10 Jan 2009 04:25:28 -0800 Subject: [erlang-questions] install_release/1 always returns enoent error In-Reply-To: References: Message-ID: Hello. But if there is a way to use hot updates without creating custom target system (we already have Erlang installed by packet manager, what is the need to have another one?), please tell me. Thanks. -- Sergey -------------- next part -------------- An HTML attachment was scrubbed... URL: From ad.sergey@REDACTED Sat Jan 10 13:27:39 2009 From: ad.sergey@REDACTED (Sergey S) Date: Sat, 10 Jan 2009 04:27:39 -0800 Subject: [erlang-questions] install_release/1 always returns enoent error In-Reply-To: References: Message-ID: Hello, Kaiduan! Please follow the System Principles closely and use the source code > target_system.erl it provides. I had used the way to do hot update and it > worked well. You were right that using custom target system (not initial) is the solution. Now hot updates work to me. Thanks for your help! I just thought that using default (initital) Erlang system will be more convenient than creating target system by hand. -- Sergey -------------- next part -------------- An HTML attachment was scrubbed... URL: From masse@REDACTED Sat Jan 10 18:49:10 2009 From: masse@REDACTED (mats cronqvist) Date: Sat, 10 Jan 2009 18:49:10 +0100 Subject: [erlang-questions] Starting Erlang as a Unix daemon In-Reply-To: <496814BD.2010002@gmail.com> (Serge Aleynikov's message of "Fri\, 09 Jan 2009 22\:23\:41 -0500") References: <20090107175301.3d64ee6d@samb-cm> <9b08084c0901080610p4782ace9t17523bdac458d2aa@mail.gmail.com> <20090109112658.6840cc19@samb-cm> <496814BD.2010002@gmail.com> Message-ID: <87k593hx0p.fsf@dixie.cronqvi.st> Serge Aleynikov writes: > Sam, > > Actually there are already tools that can help you with this task. > > Use run_erl (http://www.erlang.org/doc/apps/erts/index.html) in order to > start your node (without providing the -daemon option). In your shell > script run run_erl as a background task, and use erl_call (from > erl_interface) to attempt connecting to the node or alternatively just > grep the erlang.log.1 (produced by run_erl) for expected successful > startup message. i belive there is an option to start yaws in this fashion, that might be used as an example. mats From hs@REDACTED Sat Jan 10 18:36:54 2009 From: hs@REDACTED (Hynek Schlawack) Date: Sat, 10 Jan 2009 18:36:54 +0100 Subject: [erlang-questions] I/O performance when reading from stdin Message-ID: <4968DCB6.9030400@ox.cx> Hi, I'm starting to learn and love Erlang and wanted as a small exercise implement a word occurrence counter for http://ptrace.fefe.de/wp/ . To say it kindly, Erlang isn't built for string operations. :) My (mostly approved by #erlang) version[1] is twice as slow as the slowest already submitted[2]. Anyway, I encountered a rather strange effect I'd like to ask about: When I read from stdin, the program takes twice the time and memory compared to the case when I open the file myself. Any hints? Is it a bug? Isn't it just the "intended use" of Erlang and nobody cares? The effect occurs under Linux, haven't tested it elsewhere. Thanks! Hynek -- [1] http://github.com/hynek/wp-erlang/tree/master/wp.erl [2] http://ptrace.fefe.de/wp/timings.txt From paul-trapexit@REDACTED Sat Jan 10 20:10:52 2009 From: paul-trapexit@REDACTED (Paul Mineiro) Date: Sat, 10 Jan 2009 11:10:52 -0800 (PST) Subject: [erlang-questions] mnesia: composite keys? In-Reply-To: <71f43ded-7365-4e63-891c-17c1baccf775@y1g2000pra.googlegroups.com> References: <200901092245.09386.peter@sabaini.at> <71f43ded-7365-4e63-891c-17c1baccf775@y1g2000pra.googlegroups.com> Message-ID: On Fri, 9 Jan 2009, Viktor Sovietov wrote: > If you use ordered_set tables that tuple keys are useful, because you > can organize hierarchies inside one table. In other hand, you can't > save such tables on disk, so... Anyway, Erlang isn't MUMPS, so you > simply have not any mechanism to operate with complex keys. I have a nonstandard extension to mnesia that allows one to define new table types, plus a disk-based ordered set table so defined. http://code.google.com/p/mnesiaex/ Also we use tuples as keys extensively in our application. -- p > > Sincerely, > > --Victor > > On Jan 9, 11:45?pm, Peter Sabaini wrote: > > Hello list, > > > > I've read[1] that mnesia doesn't support composite keys. It seems I can use > > keys made up of tuples though: > > > > (emacs@REDACTED)11> mnesia:create_table(test, [{attributes, [id, data]}]). > > {atomic,ok} > > (emacs@REDACTED)19> Ins = fun() -> mnesia:write({test, {a_key, 0}, "asdfasdf"}) > > end. > > #Fun > > (emacs@REDACTED)20> mnesia:transaction(Ins). > > {atomic,ok} > > (emacs@REDACTED)21> R = fun() -> mnesia:read(test, {a_key, 0}) end. > > #Fun > > (emacs@REDACTED)22> mnesia:transaction(R). > > {atomic,[{test,{a_key,0},"asdfasdf"}]} > > > > Is tuples as keys common practice or A Really Bad Idea(tm)? > > > > thx, > > peter. > > > > [1]http://www.erlang.org/pipermail/erlang-questions/2008-February/032903... > > > > ?signature.asc > > < 1KViewDownload > > > > _______________________________________________ > > erlang-questions mailing list > > erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > In an artificial world, only extremists live naturally. -- Paul Graham From chris.newcombe@REDACTED Sat Jan 10 20:18:07 2009 From: chris.newcombe@REDACTED (Chris Newcombe) Date: Sat, 10 Jan 2009 11:18:07 -0800 Subject: [erlang-questions] : : : : : driver_entry stop() and driver_async() interaction In-Reply-To: <20090109084225.GA308@erix.ericsson.se> References: <48F75F09.7020108@alertlogic.net> <491335F5.3060602@alertlogic.net> <20081107104759.GA1287@erix.ericsson.se> <494A44FB.5030309@alertlogic.net> <20081218155426.GC23981@erix.ericsson.se> <20081219135220.GB10968@erix.ericsson.se> <20081219143620.GA13337@erix.ericsson.se> <781dd98c0812190708y66eb7fb0pd48c7fbc0f9870d8@mail.gmail.com> <20090109084225.GA308@erix.ericsson.se> Message-ID: <781dd98c0901101118s11dfa3f8s4cf2431bc27c4322@mail.gmail.com> > Sounds a bit hackish, but why not; drivers tend to be hackish. Thanks! > An even hackier hack would be to use the I/O queue for this, > and that even works today. I've never used the I/O queue so I don't know much about it. IIRC (from looking at the docs a couple of years ago), I got the impression that it is an 'earlier' driver API. But maybe I just haven't encountered the right use-case. EDTK uses binaries via outputv and driver_send_term, to minimize copying. As the BerkeleyDB driver is often used to transfer a _lot_ of data, this is important. > Was not this (later in the same mail from me) enough? > : >> Raimo wrote: >> > While we are at it we plan to introduce a driver flag >> > indicating that the driver wants to be called on >> > flush() if there are pending async jobs (as well as >> > today if the IO queue is not empty). Ah, very sorry -- yes I somehow missed this part of your e-mail. So all I need (for EDTK) would be the API increment and decrement the 'async operation count'. (I'd really prefer to avoid (mis)using the I/O queue for that) many thanks, Chris On Fri, Jan 9, 2009 at 12:42 AM, Raimo Niskanen wrote: > On Fri, Dec 19, 2008 at 07:08:11AM -0800, Chris Newcombe wrote: >> > We plan while fixing the bug with async_free() mentioned below >> > to introduce a reference counter of async jobs so it will be >> > guaranteed that stop() is not called until all async jobs are done. >> >> Excellent. But please could you provide APIs to increment and >> decrement that reference count, so that drivers that implement their >> own private thread-pools can achieve the same behaviour? > > Sounds a bit hackish, but why not; drivers tend to be hackish. > An even hackier hack would be to use the I/O queue for this, > and that even works today. > >> >> Also, I hate to cause feature creep, but if you do implement the above >> reference count/delayed 'stop', please could you also add an optional >> "prepare to stop" callback, which the VM calls when the Erlang code >> closes the port (e.g. the port owner process dies, or something >> explicitly closes the port)? Some drivers often have fairly >> long-running operations (seconds/minutes) running in their own >> threads, and would like timely notification that they should force >> such jobs to terminate, to allow "stop" to be called as soon as >> possible (the berkeley_db driver has to do this). i.e. It's not >> always the case that running async jobs should be left to complete in >> their own sweet time. (Note that this is different from 'cancelling' >> pending-but-not-yet-started jobs.) > > Was not this (later in the same mail from me) enough? > : >> Raimo wrote: >> > While we are at it we plan to introduce a driver flag >> > indicating that the driver wants to be called on >> > flush() if there are pending async jobs (as well as >> > today if the IO queue is not empty). > : > Today the flush() callback is called when the port gets killed e.g > gets an exit signal from its linked owner when it dies, if there > is data in the I/O queue. Then the stop() callback is called when the > I/O queue is emptied. > >> >> Rationale: It does actually matter a lot to some drivers that "stop" > : > > -- > > / Raimo Niskanen, Erlang/OTP, Ericsson AB > From ed.stow@REDACTED Sat Jan 10 23:36:15 2009 From: ed.stow@REDACTED (Edward Stow) Date: Sun, 11 Jan 2009 09:36:15 +1100 Subject: [erlang-questions] I/O performance when reading from stdin In-Reply-To: <4968DCB6.9030400@ox.cx> References: <4968DCB6.9030400@ox.cx> Message-ID: 2009/1/11 Hynek Schlawack : > Hi, > > I'm starting to learn and love Erlang and wanted as a small exercise > implement a word occurrence counter for http://ptrace.fefe.de/wp/ . > > To say it kindly, Erlang isn't built for string operations. :) My > (mostly approved by #erlang) version[1] is twice as slow as the slowest > already submitted[2]. > I am only an Erlang / FP noob but I would not be surprised that the Erlang code is slower as it is not really equivalent to the other implementations : for example the python implemenation http://ptrace.fefe.de/wp/wp.py is streaming over stdin and only accumulating the word counts in a dictionary. Whereas the erlang implementation reads the entire file into memory, with the overheads that are needed for storage and processing by ets. -- Edward Stow From richardc@REDACTED Sat Jan 10 23:43:35 2009 From: richardc@REDACTED (Richard Carlsson) Date: Sat, 10 Jan 2009 23:43:35 +0100 Subject: [erlang-questions] new version of file_monitor.erl - beta testers wanted Message-ID: <49692497.7030602@it.uu.se> I've been rewriting my file monitor module: it's still polling only, but now it's a gen_server, supports recursive monitoring, and is documented: http://svn.process-one.net/contribs/trunk/eunit/doc/file_monitor.html. The source code is here (it lives in the eunit project at present): http://svn.process-one.net/contribs/trunk/eunit/src/file_monitor.erl There is also an accompanying eunit test suite module: http://svn.process-one.net/contribs/trunk/eunit/src/file_monitor_tests.erl Any feedback (bugs, usability, performance, documentation) is welcome. I'll try to get it into OTP if it seems to be useful enough. The performance is fairly good; I've tried recursive monitoring on my entire OTP development tree containing something like 18 thousand files. /Richard -- "Having users is like optimization: the wise course is to delay it." -- Paul Graham From ad.sergey@REDACTED Sat Jan 10 23:52:47 2009 From: ad.sergey@REDACTED (Sergey S) Date: Sat, 10 Jan 2009 14:52:47 -0800 Subject: [erlang-questions] Yet Another Web Server Message-ID: Hello. > I want include a web server to my Erlang application, can I do this with YAWS? Maybe it will be better to use mochiweb instead of Yaws? It's developed to be very convenient in cases when web-server is considered as a part of your application. Look at this article, showing how to use mochiweb in a nutshell: http://bob.pythonmac.org/archives/2007/11/07/mochiweb-another-faster-web-server/ The sources can be found here: http://code.google.com/p/mochiweb/ And google about iserver and httpd. It will help you to decide which web-server you need. -- Sergey From ulf@REDACTED Sat Jan 10 23:59:07 2009 From: ulf@REDACTED (Ulf Wiger) Date: Sat, 10 Jan 2009 23:59:07 +0100 Subject: [erlang-questions] Installation of exprecs.erl In-Reply-To: References: Message-ID: <8209f740901101459s738d6a6fw242a88cb913e2a7a@mail.gmail.com> The 'undef' means that erlc can't find the file exprecs.beam. Try adding e.g. -pa ../ebin to the erlc command line in your Makefile (or similar, depending on how you prefer to identify the location of exprecs.beam in the Makefile) BR, Ulf W 2009/1/9 Torben Hoffmann : > Hi, > > I have put exprecs.erl into util/src/ and added it to my util/ebin/util.app > file but when I do my make it keeps complaining about > > src/record_logger.erl:none: error in parse transform 'exprecs': {undef, > [{exprecs,parse_transform, > [[{attribute,1,file, > {"src/record_logger.erl",1}}, > > {attribute,17,module,record_logger}, > {attribute,1,file, > > {"/home/pap/subv/util-0.1/../pap_app-0.1/include/my_types.hrl", > 1}}, > > > I have my records definded in a .hrl which is included in the module where I > want to utilise the exprecs functionality like this: > > -compiler({parse_transform,exprecs}). > -include("my_types.hrl"). > > -export([fields/1]). > -export_records([ % huge list with all the records from my_types.hrl that I > want to get the field names for > ]). > > fields(Rec) -> > '#info-'(fields,Rec). > > Have I installed exprecs incorrectly? > > Thanks, > Torben > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From ulf@REDACTED Sat Jan 10 23:59:59 2009 From: ulf@REDACTED (Ulf Wiger) Date: Sat, 10 Jan 2009 23:59:59 +0100 Subject: [erlang-questions] Installation of exprecs.erl In-Reply-To: <8209f740901101459s738d6a6fw242a88cb913e2a7a@mail.gmail.com> References: <8209f740901101459s738d6a6fw242a88cb913e2a7a@mail.gmail.com> Message-ID: <8209f740901101459n76a969f8n5276665400147214@mail.gmail.com> Eh, apologies. Unless you have a good reason to use -pa, -pz is of course better. (: BR, Ulf W 2009/1/10 Ulf Wiger : > The 'undef' means that erlc can't find the file exprecs.beam. > > Try adding e.g. -pa ../ebin to the erlc command line in your > Makefile (or similar, depending on how you prefer to identify > the location of exprecs.beam in the Makefile) > > BR, > Ulf W > > 2009/1/9 Torben Hoffmann : >> Hi, >> >> I have put exprecs.erl into util/src/ and added it to my util/ebin/util.app >> file but when I do my make it keeps complaining about >> >> src/record_logger.erl:none: error in parse transform 'exprecs': {undef, >> [{exprecs,parse_transform, >> [[{attribute,1,file, >> {"src/record_logger.erl",1}}, >> >> {attribute,17,module,record_logger}, >> {attribute,1,file, >> >> {"/home/pap/subv/util-0.1/../pap_app-0.1/include/my_types.hrl", >> 1}}, >> >> >> I have my records definded in a .hrl which is included in the module where I >> want to utilise the exprecs functionality like this: >> >> -compiler({parse_transform,exprecs}). >> -include("my_types.hrl"). >> >> -export([fields/1]). >> -export_records([ % huge list with all the records from my_types.hrl that I >> want to get the field names for >> ]). >> >> fields(Rec) -> >> '#info-'(fields,Rec). >> >> Have I installed exprecs incorrectly? >> >> Thanks, >> Torben >> >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions@REDACTED >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > From fredrik.svahn@REDACTED Sun Jan 11 01:03:20 2009 From: fredrik.svahn@REDACTED (Fredrik Svahn) Date: Sun, 11 Jan 2009 01:03:20 +0100 Subject: [erlang-questions] I/O performance when reading from stdin In-Reply-To: <4968DCB6.9030400@ox.cx> References: <4968DCB6.9030400@ox.cx> Message-ID: It is a known problem that reading from stdin is slow. I believe it has been discussed several times on the mailing list. Most erlang applications do not read from stdin, at least not huge amounts of data. Erlang was originally built and optimized for applications that are supposed to run for years with thousands of concurrent processes, not for shortlived scripts running just a single process. However, there has been some small improvements in later releases. You do not mention what release you are running, but my guess would be R12B-4 or earlier? I get pretty much the same results as you get when running R12B-3. With R12B-5, however, the stdio variant is just as fast as file io with get_line (but still many times slower than a corresponding c/c++ program). There is no improvement in memory consumption in R12B-5, though. By the way, if the file is small enough to fit in memory then file:read_file/1 is a lot faster! BR /Fredrik PS, How would you like to improve the string handling? On Sat, Jan 10, 2009 at 6:36 PM, Hynek Schlawack wrote: > Hi, > > I'm starting to learn and love Erlang and wanted as a small exercise > implement a word occurrence counter for http://ptrace.fefe.de/wp/ . > > To say it kindly, Erlang isn't built for string operations. :) My > (mostly approved by #erlang) version[1] is twice as slow as the slowest > already submitted[2]. > > Anyway, I encountered a rather strange effect I'd like to ask about: > When I read from stdin, the program takes twice the time and memory > compared to the case when I open the file myself. Any hints? Is it a > bug? Isn't it just the "intended use" of Erlang and nobody cares? The > effect occurs under Linux, haven't tested it elsewhere. > > Thanks! > Hynek > -- > [1] http://github.com/hynek/wp-erlang/tree/master/wp.erl > [2] http://ptrace.fefe.de/wp/timings.txt > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From hs@REDACTED Sun Jan 11 11:50:10 2009 From: hs@REDACTED (Hynek Schlawack) Date: Sun, 11 Jan 2009 11:50:10 +0100 Subject: [erlang-questions] I/O performance when reading from stdin In-Reply-To: References: <4968DCB6.9030400@ox.cx> Message-ID: <4969CEE2.4090806@ox.cx> Edward Stow schrieb: > I am only an Erlang / FP noob but I would not be surprised that the > Erlang code is slower as it is not really equivalent to the other > implementations : for example the python implemenation > http://ptrace.fefe.de/wp/wp.py is streaming over stdin and only > accumulating the word counts in a dictionary. > > Whereas the erlang implementation reads the entire file into memory, > with the overheads that are needed for storage and processing by ets. Pardon my ignorance, but I though, I've been also streaming? Or is it how reading from stdin in Erlang works: It's first completely read into memory? That would explain bad performance as well as memory usage compared to reading directly from a file. Cheers, Hynek From mazen.harake@REDACTED Sun Jan 11 14:33:28 2009 From: mazen.harake@REDACTED (Mazen Harake) Date: Sun, 11 Jan 2009 15:33:28 +0200 Subject: [erlang-questions] How to solve the issue with Configuration files? Message-ID: <4969F528.9030303@erlang-consulting.com> Dear List, During the countless times I've done releasehandling I always end up thinking about the problem with how to "ship" configuration. Option1: All configuration files are specific for each application and reside in e.g. priv directory. Benefit is that it then gets included when packing a release however it won't survive a release upgrade unless the files are explicitly copied to the new location. Option2: An env variable which tells where a configuration folder is and that is used in your application (or if you don't care about dependencies, heh, then a lib which provides that directory or similar). Then each application use their own files in that dir. Benefit here is that configuration survives release change but doesn't get packed with the release. Also this is a b**h to handle, anyone that version control their configuration will have a nightmare if you want to manually handle the configuration. So the question is; what is the best way to handle configurations? Say you have 20 xml files which various applications in your release use... where to put them and how to maintain them? If you can, please share how you handle them... /Mazen From hayeah@REDACTED Sun Jan 11 20:11:08 2009 From: hayeah@REDACTED (Howard Yeh) Date: Sun, 11 Jan 2009 11:11:08 -0800 Subject: [erlang-questions] terminating external port program Message-ID: Hi All, When the port's owner exits, the pipe is closed, but the program isn't killed. Is this right? The reference manual says that, "The external program should terminate when the port is closed." That means the external program needs to detect that pipe is closed and exits? I am writing a script spawner/monitor with Erlang. The problem is if the external script gets into a loop, it needs to be killed explicitly. There has been a posting on this before, http://erlang.org/pipermail/erlang-questions/2001-July/003445.html But writing a wrapper isn't a viable approach... that leaves me with patching port_info? What's the reason of keeping the process id hidden? Howard From hayeah@REDACTED Sun Jan 11 21:54:40 2009 From: hayeah@REDACTED (Howard Yeh) Date: Sun, 11 Jan 2009 12:54:40 -0800 Subject: [erlang-questions] terminating external port program In-Reply-To: References: Message-ID: On Sun, Jan 11, 2009 at 11:11 AM, Howard Yeh wrote: > But writing a wrapper isn't a viable approach... that leaves me with > patching port_info? What's the reason of keeping the process id > hidden? > Answering my own question, the reason to keep process id hidden is that a port isn't always a process, or even local. Right? But why not make it s.t. erlang:port_close/1 sends a kill signal when the port wraps a process? I can't figure out a reliable way to kill spawned port process if it doesn't "terminate properly". From rvirding@REDACTED Sun Jan 11 22:26:24 2009 From: rvirding@REDACTED (Robert Virding) Date: Sun, 11 Jan 2009 22:26:24 +0100 Subject: [erlang-questions] terminating external port program In-Reply-To: References: Message-ID: <3dbc6d1c0901111326t650bafe8y1fc84d7b43571ee5@mail.gmail.com> 2009/1/11 Howard Yeh > On Sun, Jan 11, 2009 at 11:11 AM, Howard Yeh wrote: > > > > But writing a wrapper isn't a viable approach... that leaves me with > > patching port_info? What's the reason of keeping the process id > > hidden? > > > > Answering my own question, the reason to keep process id hidden > is that a port isn't always a process, or even local. Right? > > But why not make it s.t. erlang:port_close/1 sends a kill signal > when the port wraps a process? I can't figure out a reliable way > to kill spawned port process if it doesn't "terminate properly". I think one reason not to kill the process -------------- next part -------------- An HTML attachment was scrubbed... URL: From rvirding@REDACTED Sun Jan 11 22:35:30 2009 From: rvirding@REDACTED (Robert Virding) Date: Sun, 11 Jan 2009 22:35:30 +0100 Subject: [erlang-questions] terminating external port program In-Reply-To: References: Message-ID: <3dbc6d1c0901111335w11ea1e41wd8f6a4c0d98aaca5@mail.gmail.com> Sorry for incomplete reply, my machine seems to keep helping me by automatically clicking the mouse. :-) 2009/1/11 Howard Yeh > On Sun, Jan 11, 2009 at 11:11 AM, Howard Yeh wrote: > > > > But writing a wrapper isn't a viable approach... that leaves me with > > patching port_info? What's the reason of keeping the process id > > hidden? > > > > Answering my own question, the reason to keep process id hidden > is that a port isn't always a process, or even local. Right? > > But why not make it s.t. erlang:port_close/1 sends a kill signal > when the port wraps a process? I can't figure out a reliable way > to kill spawned port process if it doesn't "terminate properly". I think one reason not to SIGKILL the process is that it does not give the process a chance to clean up before dying. Of course, this doesn't help when the process refuses to die as it should. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From hayeah@REDACTED Sun Jan 11 22:47:31 2009 From: hayeah@REDACTED (Howard Yeh) Date: Sun, 11 Jan 2009 13:47:31 -0800 Subject: [erlang-questions] terminating external port program In-Reply-To: <3dbc6d1c0901111335w11ea1e41wd8f6a4c0d98aaca5@mail.gmail.com> References: <3dbc6d1c0901111335w11ea1e41wd8f6a4c0d98aaca5@mail.gmail.com> Message-ID: On Sun, Jan 11, 2009 at 1:35 PM, Robert Virding wrote: > Sorry for incomplete reply, my machine seems to keep helping me by > automatically clicking the mouse. :-) > > 2009/1/11 Howard Yeh >> >> On Sun, Jan 11, 2009 at 11:11 AM, Howard Yeh wrote: >> >> >> > But writing a wrapper isn't a viable approach... that leaves me with >> > patching port_info? What's the reason of keeping the process id >> > hidden? >> > >> >> Answering my own question, the reason to keep process id hidden >> is that a port isn't always a process, or even local. Right? >> >> But why not make it s.t. erlang:port_close/1 sends a kill signal >> when the port wraps a process? I can't figure out a reliable way >> to kill spawned port process if it doesn't "terminate properly". > > > I think one reason not to SIGKILL the process is that it does not give the > process a chance to clean up before dying. Of course, this doesn't help when > the process refuses to die as it should. > > Robert > > From james.hague@REDACTED Mon Jan 12 00:10:35 2009 From: james.hague@REDACTED (James Hague) Date: Sun, 11 Jan 2009 17:10:35 -0600 Subject: [erlang-questions] Here's hoping we get frames or structs in 2009! Message-ID: I've been using Erlang as my primary language for personal projects for some years now, though I also use and enjoy Perl, Python, REBOL, C++, Lua, and occasionally Forth. Quite often I'm surprised at how much easier it is write certain types of code in Erlang...and I'm also surprised at how awkward it is to write other types of code in Erlang. Sometimes the awkwardness is because I just can't think of a pretty way to avoid destructive updates in an algorithm that's inherently destructive. But much of the time it's from working around the lack of lightweight dictionaries or hashes. In Perl, I don't think twice about creating hashes: (width => 1280, height => 1024, colors=655536) The Python version is similarly clean: dict(width=1280, height=1024, colors=65536) In Erlang, I can create a property list: [{width,1280}, {height,1024}, {colors,65536}] which isn't bad in itself, but not being able to pattern match on these is what hurts.I work around it by manually grabbing properties, but the code ends up bulky and contrived. Yeah, we've all discussed this for years, so here's hoping there's some movement on this front. Syntactically, the version I like the most at the moment is the record syntax without a record name: #{width=1280, height=1024, colors=65536} James From tty.erlang@REDACTED Mon Jan 12 04:50:32 2009 From: tty.erlang@REDACTED (t ty) Date: Sun, 11 Jan 2009 22:50:32 -0500 Subject: [erlang-questions] How to solve the issue with Configuration files? In-Reply-To: <4969F528.9030303@erlang-consulting.com> References: <4969F528.9030303@erlang-consulting.com> Message-ID: <290b3ba10901111950o423d68cey6197c197a8760782@mail.gmail.com> As a general rule I dislike env variables. They get forgotten, mis-configured, isn't inherited in a child process (typically in cron, sometime screen), abused .... IMHO Option 1 is cleaner and saner. Explicit copying is just something your install script does as part of the upgrade. t On Sun, Jan 11, 2009 at 8:33 AM, Mazen Harake wrote: > Dear List, > > During the countless times I've done releasehandling I always end up > thinking about the problem with how to "ship" configuration. > > Option1: > All configuration files are specific for each application and reside in > e.g. priv directory. Benefit is that it then gets included when packing > a release however it won't survive a release upgrade unless the files > are explicitly copied to the new location. > > Option2: > An env variable which tells where a configuration folder is and that is > used in your application (or if you don't care about dependencies, heh, > then a lib which provides that directory or similar). Then each > application use their own files in that dir. Benefit here is that > configuration survives release change but doesn't get packed with the > release. Also this is a b**h to handle, anyone that version control > their configuration will have a nightmare if you want to manually handle > the configuration. > > So the question is; what is the best way to handle configurations? Say > you have 20 xml files which various applications in your release use... > where to put them and how to maintain them? If you can, please share how > you handle them... > > /Mazen > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From pguyot@REDACTED Mon Jan 12 06:35:42 2009 From: pguyot@REDACTED (Paul Guyot) Date: Mon, 12 Jan 2009 06:35:42 +0100 Subject: [erlang-questions] Visible C nodes Message-ID: Hello, I'm trying to setup a process group (pg2) between C nodes that would be visible from erlang nodes and reciprocally. From what I understood reading the source code, I need to make the C node visible by sending DFLAG_PUBLISHED in the challenge, as a node cannot become visible once connected. However, there is no option for doing that, and this means patching erl_interface library. What would exactly be the impact of visible C nodes? Why are C nodes always hidden? Regards, Paul From ryeguy1@REDACTED Mon Jan 12 07:43:27 2009 From: ryeguy1@REDACTED (Ryan Lepidi) Date: Mon, 12 Jan 2009 01:43:27 -0500 Subject: [erlang-questions] is this appropriate usage of dirty read/write? Message-ID: Hello, I just wanted to make sure I understand when it is proper to use dirty reads and writes. From my understanding, it is ok to use them if: 1) slightly stale values don't matter 2) an operation on one variable in the database is not dependent on the value of the other When its ok to use dirty: -adding a new user to the database -changing that user's email address or password -adding a post comment to the database (assuming the posts are in a different table, and are normalized) When it's not ok: -User wants to purchase an item (assuming it's a game server, and the player's money is stored in the database) -When 2 players want to trade items Is my understanding correct? Should I be using dirty operations whenever I can for the speed increase? -------------- next part -------------- An HTML attachment was scrubbed... URL: From bernie@REDACTED Mon Jan 12 08:11:52 2009 From: bernie@REDACTED (Bernard Duggan) Date: Mon, 12 Jan 2009 18:11:52 +1100 Subject: [erlang-questions] Included Applications and application:get_application/0 Message-ID: <496AED38.7090805@m5net.com> Hi all, I'm working on a set of applications in a "primary application/included applications" type arrangement as described in the OTP Design Principles document. I'm curious if there is a programmatic way to tell which of the apps a process is considered to be running in. application:get_application/0 appears to always return the primary application, even when called from an included application. Is this intentional? Is it a bug? Am I misunderstanding something about the nature of included applications, such as them only being "applications" in some senses but not others (and if so, what senses are those...if you follow me)? Cheers, Bernard From vladdu55@REDACTED Mon Jan 12 10:37:16 2009 From: vladdu55@REDACTED (Vlad Dumitrescu) Date: Mon, 12 Jan 2009 10:37:16 +0100 Subject: [erlang-questions] new version of file_monitor.erl - beta testers wanted In-Reply-To: <49692497.7030602@it.uu.se> References: <49692497.7030602@it.uu.se> Message-ID: <95be1d3b0901120137t7ffe1157o89bdd6819a163476@mail.gmail.com> Hi Richard, On Sat, Jan 10, 2009 at 23:43, Richard Carlsson wrote: > I've been rewriting my file monitor module: it's still polling only, but > now it's a gen_server, supports recursive monitoring, and is documented: > http://svn.process-one.net/contribs/trunk/eunit/doc/file_monitor.html. Very nice. One problem I found is that for larger directory trees, the automonitor call times out because it takes more than 5 seconds. The API could be extended with a 'timeout' argument, I suppose. Also, the server is blocking until the automonitor call returns, meaning it can't be cleanly stopped. The automonitor handler should probably use noreply and proceed in the background. This brings up an idea for extending gen_server or creating a new behaviour (gen_task) for long-running operations: it would be useful sometimes to be able to interrupt them and to monitor their status (some kind of progress report?). best regards, Vlad From vladdu55@REDACTED Mon Jan 12 10:44:32 2009 From: vladdu55@REDACTED (Vlad Dumitrescu) Date: Mon, 12 Jan 2009 10:44:32 +0100 Subject: [erlang-questions] new version of file_monitor.erl - beta testers wanted In-Reply-To: <49692497.7030602@it.uu.se> References: <49692497.7030602@it.uu.se> Message-ID: <95be1d3b0901120144q6d8bf49drd3382667ca3e32a5@mail.gmail.com> On Sat, Jan 10, 2009 at 23:43, Richard Carlsson wrote: > I've been rewriting my file monitor module: it's still polling only, but > now it's a gen_server, supports recursive monitoring, and is documented: > http://svn.process-one.net/contribs/trunk/eunit/doc/file_monitor.html. The documentation doesn't match the code. The 'Entries' in the returned answer is a list of tuples, like {added, <<"filename">>} {deleted, <<"filename">>} regards, Vlad From yubao.liu@REDACTED Mon Jan 12 10:54:58 2009 From: yubao.liu@REDACTED (Liu Yubao) Date: Mon, 12 Jan 2009 17:54:58 +0800 Subject: [erlang-questions] What's the best way to select articles by page in a forum? Message-ID: <496B1372.7070905@gmail.com> Hi, I'm trying to implement a web forum with Erlang + Mnesia and meet a big difficult problem. This is the record to represent an article: -record(article, {id, parent_id, topic_id, author, title, content, timestamp}). For a new article: id = md5(author + title + timestamp). parent_id = <<0>>. topic_id = id. For a reply: parent_id = parent's id. topic_id = parent's topic_id. id = md5(parent_id + topic_id + author + title + timestamp). I use md5 digests instead of monotone increasing integers as id because I hope there is no centralized counter that is bad for concurrency and distribution. Now the problem is how I select [N, N + 20) topics efficiently and how I select [N, N + 20) articles in a topic efficiently. In SQL I can do like this: SELECT * FROM article WHERE id = topic_id ORDER BY timestamp SELECT * FROM article WHERE topic_id = ? ORDER BY timestamp and then read the result *one by one*, but it seems mnesia doesn't support this traverse, it only support two kinds of traverse: * traverse whole table (not efficient) * get the whole result set immediately and traverse records in it (consume many memory) Any suggestion is appreciated! Best regards, Liu Yubao From bernie@REDACTED Mon Jan 12 11:21:02 2009 From: bernie@REDACTED (Bernard Duggan) Date: Mon, 12 Jan 2009 21:21:02 +1100 Subject: [erlang-questions] What's the best way to select articles by page in a forum? In-Reply-To: <496B1372.7070905@gmail.com> References: <496B1372.7070905@gmail.com> Message-ID: <496B198E.2080906@m5net.com> I'm neither an SQL nor mnesia expert (yet...), but I'd ask a couple of things first: * Is the memory use of storing twenty items at once really actually a big problem? If they're just forum posts, wouldn't each record mostly just be a smallish blob of text (unless you're routinely dealing with large attachments). I suppose if you were running hundreds or thousands of such queries at once it could start to mount up, but I see so many cases where people assume that something is going to be a performance or memory issue without actually looking at any solid data that it's usually a good question to ask. * If you're using transactions in SQL, which I assume you are, then it seems to me that the results must end up being stored in memory (or somewhere) anyway, even if you only access them one at a time after issuing the query. Otherwise a subsequent transaction could alter or delete them before you're done iterating them and where would you pull the results from then? And the second question kind of leads into what I suspect is the answer. I don't think there's a non-dirty way to do it (possibly not even a dirty one - I can't immediately see one), and certainly not without holding open a transaction lock for the whole period you need the results. I guess if you don't care about transactional integrity, there may be ways around it, but it seems like a web forum would care very much about such things :) Any mnesia experts should of course feel free to point out why I'm an idiot :) Cheers, Bernard Liu Yubao wrote: > Hi, > > I'm trying to implement a web forum with Erlang + Mnesia and meet a big difficult > problem. This is the record to represent an article: > > -record(article, {id, parent_id, topic_id, author, title, content, timestamp}). > > For a new article: > id = md5(author + title + timestamp). > parent_id = <<0>>. > topic_id = id. > > For a reply: > parent_id = parent's id. > topic_id = parent's topic_id. > id = md5(parent_id + topic_id + author + title + timestamp). > > I use md5 digests instead of monotone increasing integers as id because I hope > there is no centralized counter that is bad for concurrency and distribution. > > Now the problem is how I select [N, N + 20) topics efficiently and how I select > [N, N + 20) articles in a topic efficiently. > > In SQL I can do like this: > > SELECT * FROM article WHERE id = topic_id ORDER BY timestamp > SELECT * FROM article WHERE topic_id = ? ORDER BY timestamp > > and then read the result *one by one*, but it seems mnesia doesn't support this > traverse, it only support two kinds of traverse: > > * traverse whole table > (not efficient) > * get the whole result set immediately and traverse records in it > (consume many memory) > > Any suggestion is appreciated! > > > Best regards, > > Liu Yubao > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From richardc@REDACTED Mon Jan 12 11:53:01 2009 From: richardc@REDACTED (Richard Carlsson) Date: Mon, 12 Jan 2009 11:53:01 +0100 Subject: [erlang-questions] new version of file_monitor.erl - beta testers wanted In-Reply-To: <95be1d3b0901120144q6d8bf49drd3382667ca3e32a5@mail.gmail.com> References: <49692497.7030602@it.uu.se> <95be1d3b0901120144q6d8bf49drd3382667ca3e32a5@mail.gmail.com> Message-ID: <496B210D.6000208@it.uu.se> Vlad Dumitrescu wrote: > On Sat, Jan 10, 2009 at 23:43, Richard Carlsson wrote: >> I've been rewriting my file monitor module: it's still polling only, but >> now it's a gen_server, supports recursive monitoring, and is documented: >> http://svn.process-one.net/contribs/trunk/eunit/doc/file_monitor.html. > > The documentation doesn't match the code. The 'Entries' in the > returned answer is a list of tuples, like > {added, <<"filename">>} > {deleted, <<"filename">>} Fixed, thanks. /Richard From richardc@REDACTED Mon Jan 12 11:55:59 2009 From: richardc@REDACTED (Richard Carlsson) Date: Mon, 12 Jan 2009 11:55:59 +0100 Subject: [erlang-questions] new version of file_monitor.erl - beta testers wanted In-Reply-To: <95be1d3b0901120137t7ffe1157o89bdd6819a163476@mail.gmail.com> References: <49692497.7030602@it.uu.se> <95be1d3b0901120137t7ffe1157o89bdd6819a163476@mail.gmail.com> Message-ID: <496B21BF.2020608@it.uu.se> Vlad Dumitrescu wrote: > One problem I found is that for larger directory trees, the > automonitor call times out because it takes more than 5 seconds. The > API could be extended with a 'timeout' argument, I suppose. > > Also, the server is blocking until the automonitor call returns, > meaning it can't be cleanly stopped. The automonitor handler should > probably use noreply and proceed in the background. That seems odd to me, since the call should return pretty much immediately after registering the automonitored root directory. The recursive monitoring of its subdirectories is then done in the background. I've never observed any delay in the call. /Richard From alex.arnon@REDACTED Mon Jan 12 13:29:06 2009 From: alex.arnon@REDACTED (Alex Arnon) Date: Mon, 12 Jan 2009 14:29:06 +0200 Subject: [erlang-questions] Here's hoping we get frames or structs in 2009! In-Reply-To: References: Message-ID: <944da41d0901120429o7e5bb22dt6223fc83db3db86b@mail.gmail.com> +1 May 2009 be the Year of the Lightweight Hash :) On Mon, Jan 12, 2009 at 1:10 AM, James Hague wrote: > I've been using Erlang as my primary language for personal projects > for some years now, though I also use and enjoy Perl, Python, REBOL, > C++, Lua, and occasionally Forth. Quite often I'm surprised at how > much easier it is write certain types of code in Erlang...and I'm also > surprised at how awkward it is to write other types of code in Erlang. > Sometimes the awkwardness is because I just can't think of a pretty > way to avoid destructive updates in an algorithm that's inherently > destructive. But much of the time it's from working around the lack > of lightweight dictionaries or hashes. > > In Perl, I don't think twice about creating hashes: > > (width => 1280, height => 1024, colors=655536) > > The Python version is similarly clean: > > dict(width=1280, height=1024, colors=65536) > > In Erlang, I can create a property list: > > [{width,1280}, {height,1024}, {colors,65536}] > > which isn't bad in itself, but not being able to pattern match on > these is what hurts.I work around it by manually grabbing properties, > but the code ends up bulky and contrived. Yeah, we've all discussed > this for years, so here's hoping there's some movement on this front. > Syntactically, the version I like the most at the moment is the record > syntax without a record name: > > #{width=1280, height=1024, colors=65536} > > James > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kostis@REDACTED Mon Jan 12 13:59:59 2009 From: kostis@REDACTED (Kostis Sagonas) Date: Mon, 12 Jan 2009 14:59:59 +0200 Subject: [erlang-questions] Here's hoping we get frames or structs in 2009! In-Reply-To: References: Message-ID: <496B3ECF.5070609@cs.ntua.gr> James Hague wrote: > I've been using Erlang as my primary language for personal projects > for some years now, though I also use and enjoy Perl, Python, REBOL, > C++, Lua, and occasionally Forth. Quite often I'm surprised at how > much easier it is write certain types of code in Erlang...and I'm also > surprised at how awkward it is to write other types of code in Erlang. > Sometimes the awkwardness is because I just can't think of a pretty > way to avoid destructive updates in an algorithm that's inherently > destructive. But much of the time it's from working around the lack > of lightweight dictionaries or hashes. > > In Perl, I don't think twice about creating hashes: > > (width => 1280, height => 1024, colors=655536) > > The Python version is similarly clean: > > dict(width=1280, height=1024, colors=65536) > > In Erlang, I can create a property list: > > [{width,1280}, {height,1024}, {colors,65536}] > > which isn't bad in itself, but not being able to pattern match on > these is what hurts.I work around it by manually grabbing properties, > but the code ends up bulky and contrived. Yeah, we've all discussed > this for years, so here's hoping there's some movement on this front. > Syntactically, the version I like the most at the moment is the record > syntax without a record name: > > #{width=1280, height=1024, colors=65536} Perhaps I am missing the obvious but I fail to see how the presence of the record name prevents you from doing this today -- especially for things that have a fixed number of "properties" (e.g. width, height, colors) as the above. Kostis From gleber.p@REDACTED Mon Jan 12 14:16:36 2009 From: gleber.p@REDACTED (Gleb Peregud) Date: Mon, 12 Jan 2009 14:16:36 +0100 Subject: [erlang-questions] Here's hoping we get frames or structs in 2009! In-Reply-To: <496B3ECF.5070609@cs.ntua.gr> References: <496B3ECF.5070609@cs.ntua.gr> Message-ID: <14f0e3620901120516q5e02e1a5qf6ab17d6912f63ae@mail.gmail.com> On Mon, Jan 12, 2009 at 1:59 PM, Kostis Sagonas wrote: > James Hague wrote: >> I've been using Erlang as my primary language for personal projects >> for some years now, though I also use and enjoy Perl, Python, REBOL, >> C++, Lua, and occasionally Forth. Quite often I'm surprised at how >> much easier it is write certain types of code in Erlang...and I'm also >> surprised at how awkward it is to write other types of code in Erlang. >> Sometimes the awkwardness is because I just can't think of a pretty >> way to avoid destructive updates in an algorithm that's inherently >> destructive. But much of the time it's from working around the lack >> of lightweight dictionaries or hashes. >> >> In Perl, I don't think twice about creating hashes: >> >> (width => 1280, height => 1024, colors=655536) >> >> The Python version is similarly clean: >> >> dict(width=1280, height=1024, colors=65536) >> >> In Erlang, I can create a property list: >> >> [{width,1280}, {height,1024}, {colors,65536}] >> >> which isn't bad in itself, but not being able to pattern match on >> these is what hurts.I work around it by manually grabbing properties, >> but the code ends up bulky and contrived. Yeah, we've all discussed >> this for years, so here's hoping there's some movement on this front. >> Syntactically, the version I like the most at the moment is the record >> syntax without a record name: >> >> #{width=1280, height=1024, colors=65536} > > Perhaps I am missing the obvious but I fail to see how the presence of > the record name prevents you from doing this today -- especially for > things that have a fixed number of "properties" (e.g. width, height, > colors) as the above. > > Kostis > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > Probably James means that such structure could be used in such a way: Options0 = #{width=1280, height=1024}, ... Options = Options0#{colors = 256}, ... adjust_screen(Options). adjust_screen(#{colors = 65536}) -> erlang:error(unsupported); adjust_screen(Options = #{width = W, height = H, colors = _}) -> %% 'colors = _' would match iff this key is set io:fwrite("selected colors ~b~n", [Options.colors]), %% or it can be Options#colors (confusing) or Options#.colors (awkward...) do_something(...). I opt for inclusion of such structure into the language. It will combine power of dict (dynamic set key-value pairs) and power of tuples/records (pattern matching) -- Gleb Peregud http://gleber.pl/ Every minute is to be grasped. Time waits for nobody. -- Inscription on a Zen Gong From bengt.kleberg@REDACTED Mon Jan 12 14:39:23 2009 From: bengt.kleberg@REDACTED (Bengt Kleberg) Date: Mon, 12 Jan 2009 14:39:23 +0100 Subject: [erlang-questions] Problematic error: code server called the unloaded module `init' In-Reply-To: <200812302342.13039.vincent.dephily@mobile-devices.fr> References: <200812302342.13039.vincent.dephily@mobile-devices.fr> Message-ID: <1231767563.4586.14.camel@seasc1137.dyn.rnd.as.sw.ericsson.se> Greetings, I have 2 ideas/suggestions. 1) erlexec is not documented so you might want to use erl instead. 2) According to the man page for erl (http://erlang.org/doc/man/erl.html) you should only write "-config foo". bengt On Tue, 2008-12-30 at 23:42 +0100, Vincent de Phily wrote: > Hi list, > > here's an error I can't quite figure out and started getting on some of my > servers, as far as I can tell without code change or environement > modifications : > > > $ erlexec -name foo@REDACTED -config foo.config +W w > > > > Crash dump was written to: erl_crash.dump > > The code server called the unloaded module `init' > > When I look at the crash dump, I do have 'init' in my modules list, along with > lots of standard modules (but none of my own modules) : > > > =loaded_modules > > Current code: 1064029 > > Old code: 0 > > =mod:otp_ring0 > > Current size: 620 > > =mod:init > > Current size: 31160 > > =mod:prim_inet > > Current size: 50792 > > ... > > and an 'init' process : > > =proc:<0.0.0> > > State: Waiting > > Name: init > > Spawned as: otp_ring0:start/2 > > Spawned by: [] > > Started: Tue Dec 30 23:25:05 2008 > > Message queue length: 0 > > Number of heap fragments: 0 > > Heap fragment data: 0 > > Link list: [<0.1.0>, <0.5.0>, <0.4.0>, <0.2.0>] > > Reductions: 4938 > > Stack+heap: 377 > > OldHeap: 0 > > Heap unused: 229 > > OldHeap unused: 0 > > Program counter: 0xb4b7a250 (init:boot_loop/2 + 32) > > CP: 0x081f4340 () > > arity = 0 > > (I can provide more of the dump if desired) > > > I don't know where to begin with this one; google only picked up a > seemingly-irrelevant thread on this mailinglist. This is a recent erlang > version. Any ideas ? > From james.hague@REDACTED Mon Jan 12 16:27:34 2009 From: james.hague@REDACTED (James Hague) Date: Mon, 12 Jan 2009 09:27:34 -0600 Subject: [erlang-questions] Here's hoping we get frames or structs in 2009! In-Reply-To: <496B3ECF.5070609@cs.ntua.gr> References: <496B3ECF.5070609@cs.ntua.gr> Message-ID: > Perhaps I am missing the obvious but I fail to see how the presence of > the record name prevents you from doing this today -- especially for > things that have a fixed number of "properties" (e.g. width, height, > colors) as the above. Records are passable for simple cases, like the example I gave, though having to share record definitions between modules is a pain, and necessitates a makefile or equivalent instead of recompiling a single module. That's so anti-Erlang, which is why I prefer association lists and a light wrapper around lists:keysearch (or proplists, which I'm less keen on). The biggest downside to records is that they're fixed and brittle. I want to have widely varying contents, where I can query the "color" property, even though I don't know what the other properties may be. At the moment I can define 10 different records, and even though they all have a "color" field there's no way to get at it without matching on record type first. James From ed.korsberg@REDACTED Mon Jan 12 17:09:07 2009 From: ed.korsberg@REDACTED (Ed Korsberg) Date: Mon, 12 Jan 2009 11:09:07 -0500 Subject: [erlang-questions] Question about erlang history at Ericsson Message-ID: I am new to this Erlang forum so please excuse any 'newbe' errors on my part. I recently learned of the power of Erlang while attending a conference and while I find the technology of the Erlang language interesting, I am really curious how Ericsson engineering and management had the courage to produce a real revenue generating product on a radical previously unproven design. Many companies have internal engineering resources to create innovative research projects but it is rare for these research projects to make the transition to shipping products complete with all the quality control and field support required. I would be curious to learn how Ericsson managed this transition from an internal R&D development to a real shipping product. -------------- next part -------------- An HTML attachment was scrubbed... URL: From masklinn@REDACTED Mon Jan 12 17:12:29 2009 From: masklinn@REDACTED (Masklinn) Date: Mon, 12 Jan 2009 17:12:29 +0100 Subject: [erlang-questions] Here's hoping we get frames or structs in 2009! In-Reply-To: References: Message-ID: <4CD28831-E4EA-4F7F-8697-08D054793A1F@masklinn.net> On 12 Jan 2009, at 00:10 , James Hague wrote: > The Python version is similarly clean: > > dict(width=1280, height=1024, colors=65536) > Just an fyi, this is *not* the python literal syntax for dicts, which would be: {'width':1280, 'height':1024, 'colors':65536} what you posted is the ability to use arbitrary keyword arguments in the dict constructor, it's fairly recent (Python 2.3) and while it's slightly shorter for dicts where keys are exclusively strings (2 less characters per key above 2 keys), it also has limitations: * Keys have to be strings, python's dictionaries aren't actually limited to string indexing (using the literal syntax one can use e.g. integers, tuples or frozensets as keys) * Python keywords can't be used as keys (so e.g. class, def, if, else, in, for, ... will generate a syntax error if you're not using the literal syntax) * Much harder to statically analyze (even though the literal syntax kind-of loses this in Python 3.0 with dict comprehensions) From qiulang@REDACTED Mon Jan 12 17:16:31 2009 From: qiulang@REDACTED (lang qiu) Date: Tue, 13 Jan 2009 00:16:31 +0800 Subject: [erlang-questions] Which part of parent process should receive 'EXIT' message when child process exit(reason) after sending parent a normal message ? Message-ID: Hi all, The IRC Lite example in "programming erlang" makes me think some question that I thought I have understood. 1. Which part of parent process should receive 'EXIT' message when child process exit(reason) after sending parent a normal message ? So in the chat_client.erl, try_to_connect(Parent, Host, Port, Pwd) -> ... Parent ! {*connected, MM*}, exit(*connectorFinished*) end. While in parents *disconnected/3*, ... receive {*connected, MM*} -> ... *wait_login_response*(Widget, MM); {*'EXIT', _Pid, _Reason*} -> %% if we add this clause here ... *wait_login_response/2* defines, ... receive { {*'EXIT', _Pid, _Reason*} -> %% it actually just define Other -> ... ... The result shows that wait_login_response/2 receives the 'EXIT' message not disconnected/3. I further test that if try_to_connect sends more messages after {*connected, MM*} , they will all be received by wait_login_response instead of disconnected/3 even there are match patterns in disconnected/3 (Correct me if I am wrong). So for a general cases, is this a good idea (design) to make the first message match part receives the remaining messages after the first match (if the first match part has its own receive loop) instead of the other part of receiving function ? Or I miss something here ? 2. Why mod_chat_controller *only *receives login message ? After all, chat_client uses lib_chan_mm:send(MM) for both login and relay messages ? 3. When I close a window, except for the expected message "I'm leaving the group", the server also output the error message "server error should die with exit(normal) was:{mm_closed,}". Why does this happen and how to fix it ? Thanks! Qiulang -------------- next part -------------- An HTML attachment was scrubbed... URL: From ed.korsberg@REDACTED Mon Jan 12 18:26:53 2009 From: ed.korsberg@REDACTED (Ed Korsberg) Date: Mon, 12 Jan 2009 12:26:53 -0500 Subject: [erlang-questions] To what VxWorks platforms has Erlang been ported? Message-ID: I read the Erlang has been ported at one time to WindRiver's VxWorks. However to what hardware platform/processor has this been ported to? We are currently using VxWorks 6.6 for ARM9 and XScale processors. We also have it for Freescale Coldfire MCF5329. I rather doubt Erlang has been ported to these variations of the VxWorks OS but I thought I would ask anyway. How would someone proceed in porting Erlang to a new platform? -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomasl_erlang@REDACTED Mon Jan 12 17:56:25 2009 From: thomasl_erlang@REDACTED (Thomas Lindgren) Date: Mon, 12 Jan 2009 08:56:25 -0800 (PST) Subject: [erlang-questions] Question about erlang history at Ericsson In-Reply-To: Message-ID: <920691.10457.qm@web111403.mail.gq1.yahoo.com> --- On Mon, 1/12/09, Ed Korsberg wrote: > I would be curious to learn how Ericsson managed this > transition from an > internal R&D development to > a real shipping product. Try this one: http://www.erlang.se/publications/bjarnelic.ps Bjarne D?cker was the manager of CS Lab (home of Erlang) while Erlang was being developed, and can still usually be found organizing EUC :-) Best, Thomas From tuncer.ayaz@REDACTED Mon Jan 12 19:07:57 2009 From: tuncer.ayaz@REDACTED (Tuncer Ayaz) Date: Mon, 12 Jan 2009 19:07:57 +0100 Subject: [erlang-questions] Question about erlang history at Ericsson In-Reply-To: <920691.10457.qm@web111403.mail.gq1.yahoo.com> References: <920691.10457.qm@web111403.mail.gq1.yahoo.com> Message-ID: <4ac8254d0901121007y4f682552u4541ff1d30c260e5@mail.gmail.com> On Mon, Jan 12, 2009 at 5:56 PM, Thomas Lindgren wrote: > > --- On Mon, 1/12/09, Ed Korsberg wrote: >> I would be curious to learn how Ericsson managed this >> transition from an >> internal R&D development to >> a real shipping product. > > Try this one: http://www.erlang.se/publications/bjarnelic.ps > > Bjarne D?cker was the manager of CS Lab (home of Erlang) while > Erlang was being developed, and can still usually be found > organizing EUC :-) Additionally, the following paper from Joe is insightful: HOPL-III: A History of Erlang http://lambda-the-ultimate.org/node/2811 From chsu79@REDACTED Mon Jan 12 19:25:21 2009 From: chsu79@REDACTED (Christian) Date: Mon, 12 Jan 2009 19:25:21 +0100 Subject: [erlang-questions] Here's hoping we get frames or structs in 2009! In-Reply-To: References: Message-ID: On Mon, Jan 12, 2009 at 00:10, James Hague wrote: > but the code ends up bulky and contrived. Yeah, we've all discussed > this for years, so here's hoping there's some movement on this front. > Syntactically, the version I like the most at the moment is the record > syntax without a record name: > > #{width=1280, height=1024, colors=65536} Ponder this approach I implemented: 1> Assoc = record:list_to_assoc([foo, bar, baz]). {{bar,3},{baz,4},{foo,2}} 2> record:in(baz, Assoc). 4 Basically a map from atoms to integers. I choose to perform binary search. One can then create a tuple where this Assoc takes the place of the atom tag in a plain record: 3> Rec = record:new(Assoc). {{{bar,3},{baz,4},{foo,2}},[],[],[]} And operations use the atom->integer map to implement basic manipulations on tuples by field name: 4> Rec1 = record:set(baz, x, Rec). {{{bar,3},{baz,4},{foo,2}},[],[],x} 5> record:get(baz, Rec1). x The downside in this implementation of Assoc is that there is going to be lots of repeated references to new copies of same-valued tuples. Every copy inserted and taken out of ets will create a new one, as well as when they are sent between processes using the normal memory model. But would it be ugly to 'intern' this Assoc into a new first-class type? A reference counted atom() to integer() map type? Each module could put the assoc objects it needs in the constant pool so they would not need to intern the assoc object over and over again. Checking that an assoc contains a number of fields or the tuple element they're mapped to is efficient enough that it is no worser compared to the existing non-constant-complexity guards and bifs. I actually cant think of any downside to the approach that is a problem for the intended use. It just looks very difficult to create a new type and guards for it, requiring changes to both the compiler and the vm. From rvirding@REDACTED Mon Jan 12 19:26:18 2009 From: rvirding@REDACTED (Robert Virding) Date: Mon, 12 Jan 2009 19:26:18 +0100 Subject: [erlang-questions] Here's hoping we get frames or structs in 2009! In-Reply-To: <14f0e3620901120516q5e02e1a5qf6ab17d6912f63ae@mail.gmail.com> References: <496B3ECF.5070609@cs.ntua.gr> <14f0e3620901120516q5e02e1a5qf6ab17d6912f63ae@mail.gmail.com> Message-ID: <3dbc6d1c0901121026h40c362cy3587aa374b629063@mail.gmail.com> 2009/1/12 Gleb Peregud > > Probably James means that such structure could be used in such a way: > > Options0 = #{width=1280, height=1024}, > ... > Options = Options0#{colors = 256}, > ... > adjust_screen(Options). > > adjust_screen(#{colors = 65536}) -> erlang:error(unsupported); > adjust_screen(Options = #{width = W, height = H, colors = _}) -> %% > 'colors = _' would match iff this key is set > io:fwrite("selected colors ~b~n", [Options.colors]), %% or it can > be Options#colors (confusing) or Options#.colors (awkward...) > do_something(...). > > I opt for inclusion of such structure into the language. It will > combine power of dict (dynamic set key-value pairs) and power of > tuples/records (pattern matching) I don't think that that will be the case. The suggestions for implementations given so far all assume relatively small structs/frames, they would not be replacements for dicts but a replacement, or rather a complement to, records. This said I think that they would be a great feature and think they should be included. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From masse@REDACTED Mon Jan 12 20:15:03 2009 From: masse@REDACTED (mats cronqvist) Date: Mon, 12 Jan 2009 20:15:03 +0100 Subject: [erlang-questions] Question about erlang history at Ericsson In-Reply-To: (Ed Korsberg's message of "Mon\, 12 Jan 2009 11\:09\:07 -0500") References: Message-ID: <87iqokpc94.fsf@sterlett.hq.kred> "Ed Korsberg" writes: > Many companies have internal engineering resources to create innovative > research projects but it is > rare for these research projects to make the transition to shipping products > complete with all the quality > control and field support required. Sounds like you've been there... > I would be curious to learn how Ericsson managed this transition > from an internal R&D development to a real shipping product. Ericsson at the time had made many many tons of money on a product (AXE 10) that ran huge programs written in a proprietary language (PLEX) on custom HW. So the concept of shipping stuff that was the result of in-house development was deeply ingrained; indeed it was the whole point of Ericsson. This tradition was thrown out in the mid-80s, when it was decided that the next generation AXE was to be implemented in C++. This turned into a huge disaster (according to Swedish Wikipedia that project cost Ericsson about 1 billion US$.) So there was a window of opportunity, and a generation of leaders that thought Ericson was capable of doing bleeding-edge stuff internally. Plus it actually worked. mats From roger.larsson@REDACTED Mon Jan 12 21:54:18 2009 From: roger.larsson@REDACTED (Roger Larsson) Date: Mon, 12 Jan 2009 21:54:18 +0100 Subject: [erlang-questions] Software crisis (Was: Re: Question about erlang history at Ericsson) In-Reply-To: <920691.10457.qm@web111403.mail.gq1.yahoo.com> References: <920691.10457.qm@web111403.mail.gq1.yahoo.com> Message-ID: <200901122154.19024.roger.larsson@e-gatan.se> 'The strange word is "crisis". Projects in other engineering fields also experience problems. A case in point is the tunnel building project through Hallands?sen, Sweden [Da96].' Bjarne D?ckers report The tunnel is still not finished... (8 years later, in Oct 2008 was 57% done) Svenska English (not updated) Pictures /RogerL On Monday 12 January 2009, Thomas Lindgren wrote: > --- On Mon, 1/12/09, Ed Korsberg wrote: > > I would be curious to learn how Ericsson managed this > > transition from an > > internal R&D development to > > a real shipping product. > > Try this one: http://www.erlang.se/publications/bjarnelic.ps > > Bjarne D?cker was the manager of CS Lab (home of Erlang) while Erlang was > being developed, and can still usually be found organizing EUC :-) > > Best, > Thomas > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions -------------- next part -------------- An HTML attachment was scrubbed... URL: From simone8280@REDACTED Mon Jan 12 21:56:54 2009 From: simone8280@REDACTED (simone8280@REDACTED) Date: Mon, 12 Jan 2009 21:56:54 +0100 (CET) Subject: [erlang-questions] use of disksup Message-ID: <27418990.1391651231793814277.JavaMail.defaultUser@defaultHost> Hi! I'm new in eralng programming; I want to write a small application for know the size of a disk and its available space, in Windows environment. I found the module disksup (function get_disk_data()). I try to use it but without success, I'm not able to configure it (it need a configuration with module os_mon). Can you help me? I need to configure get_disk_data() function and to specify the disk I want to analyze (for example I want to know the space's amount of drive a:). If you write a few line of source of exemple I'm very happy. (well there are an infinity of way to know the size of a disk but I want to do it with erlang) thankyou, see you at next From sten.gruener@REDACTED Mon Jan 12 22:57:59 2009 From: sten.gruener@REDACTED (Sten Gruener) Date: Mon, 12 Jan 2009 22:57:59 +0100 Subject: [erlang-questions] Asynchronios call of C library Message-ID: Hi, in my project I am used to call C-library functions from erlang using erl_ddll and EI for transfering data between erlang and C. The problem is, the calls are synchronious, and all the instances of the driver in fact share same memory. I need to have asynchronious calls, which means each insance of thedriver haveing each own instance of the .so library. Is there any way to do it? I have heared some rumours but cannot find a way to do it. BR, Sten Gruener From rvirding@REDACTED Mon Jan 12 23:07:55 2009 From: rvirding@REDACTED (Robert Virding) Date: Mon, 12 Jan 2009 23:07:55 +0100 Subject: [erlang-questions] Question about erlang history at Ericsson In-Reply-To: References: Message-ID: <3dbc6d1c0901121407j3afad440v25ae6a91096da478@mail.gmail.com> 2009/1/12 Ed Korsberg > I am new to this Erlang forum so please excuse any 'newbe' errors on my > part. > I recently learned of the power of Erlang while attending a conference and > while I find the technology > of the Erlang language interesting, I am really curious how Ericsson > engineering and management had the > courage to produce a real revenue generating product on a radical > previously unproven design. > > Many companies have internal engineering resources to create innovative > research projects but it is > rare for these research projects to make the transition to shipping > products complete with all the quality > control and field support required. > > I would be curious to learn how Ericsson managed this transition from an > internal R&D development to > a real shipping product. The references you got from Thomas and Tuncer are good and give some insight into the development of Erlang and the problems the lab had when doing it. BUT, one basic thing you must realise and is that the development of Erlang was pure skunk-works and we in the lab decided more or less on our on accord to do it. We were very lucky to get in contact with a group who were both willing and able to try new technology for their development. It has never really been sanctioned by management and only really been officially allowed to be used when other more prefered alternatives have failed. Even then there were many requests to phase it out and use other technologies. Another thing to realise is that Ericsson, like most other large companies, is not a homogenous entity and while we only ever had very limited management support there were groups inside Ericsson who had the need of, and saw the benefits, of using Erlang in their products. And who were willing to fight to use it. Basically we were continually fighting to keep Erlang alive, spread it and try to support groups who were using it. Rather depressing perhaps but, I think, quite common for new technology in larger companies. Of course the really big happening for the spread of Erlang out of Ericsson was being able to release it as public source. There were many in Ericsson who saw the benefits of not using restricted in-house developed technologies, but unfortunately for us the official solution to this was to use external products instead. It did, however, make it easier to get permission to release it as open source. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From kenneth.lundin@REDACTED Mon Jan 12 23:08:33 2009 From: kenneth.lundin@REDACTED (Kenneth Lundin) Date: Mon, 12 Jan 2009 23:08:33 +0100 Subject: [erlang-questions] use of disksup In-Reply-To: <27418990.1391651231793814277.JavaMail.defaultUser@defaultHost> References: <27418990.1391651231793814277.JavaMail.defaultUser@defaultHost> Message-ID: Hi, The disksup module belongs to the os_mon application which in turn is dependent on the sasl application. Therefore you need to start these applications before you call disksup:get_disk_data(). Like this (in the Erlang shell) 1> application:start(sasl). ok 2> application:start(os_mon). ok 3> disksup:get_disk_data(). [{"C:\\",200047001600,69},{"G:\\",39991275520,35}] 4> The above result was what I got on my Windows XP machine. It means that C: has a total space of 200047001600 bytes and 69% is occupied, G: has 39991275520 bytes and 35% is occupied. While writing this I noticed that the documentation says that the unit should be Kbytes but it is not in this case. I have to check if there is a documentation error or if it is a different behaviour on Windows than on Linux. I think the use of disksup on Windows is very sparse compared to Linux and Solaris and that might be the reason for not detecting this before, if it is bytes only on Windows. /Regards Kenneth Erlang/OTP Ericsson On Mon, Jan 12, 2009 at 9:56 PM, simone8280@REDACTED wrote: > Hi! I'm new in eralng programming; I want to write a small application for know > the size of a disk and its available space, in Windows environment. I found the > module disksup (function get_disk_data()). I try to use it but without success, > I'm not able to configure it (it need a configuration with module os_mon). Can > you help me? I need to configure get_disk_data() function and to specify the > disk I want to analyze (for example I want to know the space's amount of drive > a:). If you write a few line of source of exemple I'm very happy. (well there > are an infinity of way to know the size of a disk but I want to do it with > erlang) > > thankyou, see you at next > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From michael.truog@REDACTED Mon Jan 12 23:25:56 2009 From: michael.truog@REDACTED (michael.truog@REDACTED) Date: Tue, 13 Jan 2009 00:25:56 +0200 Subject: [erlang-questions] Asynchronios call of C library In-Reply-To: References: Message-ID: The Erlang Driver Tool Kit code should show you how to do it. It can do both. http://ww.snookles.com/erlang/edtk/ -----Original Message----- From: erlang-questions-bounces@REDACTED [mailto:erlang-questions-bounces@REDACTED] On Behalf Of ext Sten Gruener Sent: Monday, January 12, 2009 1:58 PM To: erlang-questions@REDACTED Subject: [erlang-questions] Asynchronios call of C library Hi, in my project I am used to call C-library functions from erlang using erl_ddll and EI for transfering data between erlang and C. The problem is, the calls are synchronious, and all the instances of the driver in fact share same memory. I need to have asynchronious calls, which means each insance of thedriver haveing each own instance of the .so library. Is there any way to do it? I have heared some rumours but cannot find a way to do it. BR, Sten Gruener _______________________________________________ erlang-questions mailing list erlang-questions@REDACTED http://www.erlang.org/mailman/listinfo/erlang-questions From yubao.liu@REDACTED Tue Jan 13 04:03:00 2009 From: yubao.liu@REDACTED (Liu Yubao) Date: Tue, 13 Jan 2009 11:03:00 +0800 Subject: [erlang-questions] What's the best way to select articles by page in a forum? In-Reply-To: <496B198E.2080906@m5net.com> References: <496B1372.7070905@gmail.com> <496B198E.2080906@m5net.com> Message-ID: <496C0464.1070705@gmail.com> Bernard Duggan wrote: > I'm neither an SQL nor mnesia expert (yet...), but I'd ask a couple of Me too;-) > things first: > > * Is the memory use of storing twenty items at once really actually a > big problem? If they're just forum posts, wouldn't each record mostly > just be a smallish blob of text (unless you're routinely dealing with > large attachments). I suppose if you were running hundreds or thousands > of such queries at once it could start to mount up, but I see so many > cases where people assume that something is going to be a performance or > memory issue without actually looking at any solid data that it's > usually a good question to ask. > Yes, I also think twenty items won't consume too much memory, the problem is I don't know how to get the twenty items efficiently without traversing the whole table or the whole result set each time, I need some logic like this: get_topics(LastId, LastTimestamp, Count) -> F = fun () -> qlc:e(qlc:q([Article || Article <- mnesia:table(article, {n_objects, Count}]), Article#article.id =:= Article#article.topic_id, Article#article.timestamp >= LastTimestamp])) end. {atomic, Articles} = mnesia:transaction(F). case find_article(Articles, LastId) of -1 -> Articles; % the last article has been deleted N -> lists:nthtail(Articles, N) end. I almost get it except I haven't figure out how to get a result set ordered by timestamp. > * If you're using transactions in SQL, which I assume you are, then it > seems to me that the results must end up being stored in memory (or > somewhere) anyway, even if you only access them one at a time after > issuing the query. Otherwise a subsequent transaction could alter or > delete them before you're done iterating them and where would you pull > the results from then? > You remind me, I should use one transaction for one query to a page, not one transaction for queries to all pages. Because I touch only 20 items in a transaction I guess that won't consume too much memory. This is not a perfect transaction protected traverse over *all items* but I think users won't care (even won't be aware of), they just want to view the articles page by page from the oldest to the newest. > And the second question kind of leads into what I suspect is the answer. > I don't think there's a non-dirty way to do it (possibly not even a > dirty one - I can't immediately see one), and certainly not without > holding open a transaction lock for the whole period you need the results. > > I guess if you don't care about transactional integrity, there may be > ways around it, but it seems like a web forum would care very much about > such things :) > > Any mnesia experts should of course feel free to point out why I'm an > idiot :) > You questions are valuable, they help me sort out the solution, thank you very much! > Cheers, > > Bernard > > Liu Yubao wrote: >> Hi, >> >> I'm trying to implement a web forum with Erlang + Mnesia and meet a big difficult >> problem. This is the record to represent an article: >> >> -record(article, {id, parent_id, topic_id, author, title, content, timestamp}). >> >> For a new article: >> id = md5(author + title + timestamp). >> parent_id = <<0>>. >> topic_id = id. >> >> For a reply: >> parent_id = parent's id. >> topic_id = parent's topic_id. >> id = md5(parent_id + topic_id + author + title + timestamp). >> >> I use md5 digests instead of monotone increasing integers as id because I hope >> there is no centralized counter that is bad for concurrency and distribution. >> >> Now the problem is how I select [N, N + 20) topics efficiently and how I select >> [N, N + 20) articles in a topic efficiently. >> >> In SQL I can do like this: >> >> SELECT * FROM article WHERE id = topic_id ORDER BY timestamp >> SELECT * FROM article WHERE topic_id = ? ORDER BY timestamp >> >> and then read the result *one by one*, but it seems mnesia doesn't support this >> traverse, it only support two kinds of traverse: >> >> * traverse whole table >> (not efficient) >> * get the whole result set immediately and traverse records in it >> (consume many memory) >> >> Any suggestion is appreciated! >> >> >> Best regards, >> >> Liu Yubao >> >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions@REDACTED >> http://www.erlang.org/mailman/listinfo/erlang-questions > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From saleyn@REDACTED Tue Jan 13 05:45:00 2009 From: saleyn@REDACTED (Serge Aleynikov) Date: Mon, 12 Jan 2009 23:45:00 -0500 Subject: [erlang-questions] extended timer module to handle absolute time-of-day timers Message-ID: <496C1C4C.8090306@gmail.com> I extended the timer module to handle absolute time specifications. With this implementation it's possible to have messages sent on given days of week at a certain time of day. Five new functions are added: apply_at_local_time/4, send_at_local_time/3, exit_at_local_time/3, apply_daily_at_local_time/5, send_daily_at_local_time/4. Example1: Send a shutdown message to Pid at 23:00:00 every Friday and Sunday. timer:send_daily_at_local_time([fri,sun], {23,0,0}, Pid, shutdown). Example2: Send a restart message to Pid at "6:00:00": timer:send_at_local_time({6,0,0}, Pid, restart). Legacy timer_server's functionality is not affected. The rationale behind this extension is that I frequently needed functionality to schedule some "cron-like" recurrent activities, and was always relying either on cron+erl_call or coding that activity with help of timer:send_after/3 or timer:send_interval/2. As I finally got sick of dealing with shortcomings of the timer module, I put together this extension. Let me know if you also find it useful, and in such case perhaps we can get it included in the OTP. Serge -------------- next part -------------- A non-text attachment was scrubbed... Name: timer.erl Type: text/x-erlang Size: 15216 bytes Desc: not available URL: From saleyn@REDACTED Tue Jan 13 05:48:27 2009 From: saleyn@REDACTED (Serge Aleynikov) Date: Mon, 12 Jan 2009 23:48:27 -0500 Subject: [erlang-questions] extended timer module to handle absolute time-of-day timers Message-ID: <496C1D1B.3050501@gmail.com> Sorry - previous email had a wrong attachment. I extended the timer module to handle absolute time specifications. With this implementation it's possible to have messages sent on given days of week at a certain time of day. Five new functions are added: apply_at_local_time/4, send_at_local_time/3, exit_at_local_time/3, apply_daily_at_local_time/5, send_daily_at_local_time/4. Example1: Send a shutdown message to Pid at 23:00:00 every Friday and Sunday. timer:send_daily_at_local_time([fri,sun], {23,0,0}, Pid, shutdown). Example2: Send a restart message to Pid at "6:00:00": timer:send_at_local_time({6,0,0}, Pid, restart). Legacy timer_server's functionality is not affected. The rationale behind this extension is that I frequently needed functionality to schedule some "cron-like" recurrent activities, and was always relying either on cron+erl_call or coding that activity with help of timer:send_after/3 or timer:send_interval/2. As I finally got sick of dealing with shortcomings of the timer module, I put together this extension. Let me know if you also find it useful, and in such case perhaps we can get it included in the OTP. Serge -------------- next part -------------- A non-text attachment was scrubbed... Name: timer.erl Type: text/x-erlang Size: 15243 bytes Desc: not available URL: From ryeguy1@REDACTED Tue Jan 13 06:19:40 2009 From: ryeguy1@REDACTED (Ryan Lepidi) Date: Tue, 13 Jan 2009 00:19:40 -0500 Subject: [erlang-questions] gen_server question Message-ID: Hello, When the server is terminated due to an error occurring in one of its functions, what happens if another process calls one of the server's functions in between the time the server is terminated and the time the supervisor restarts it? Will the call be queued and executed once the server is back up? Or is there a chance that it could be lost? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hayeah@REDACTED Tue Jan 13 06:45:47 2009 From: hayeah@REDACTED (Howard Yeh) Date: Mon, 12 Jan 2009 21:45:47 -0800 Subject: [erlang-questions] gen_server question In-Reply-To: References: Message-ID: > 2009/1/12 Ryan Lepidi : > Hello, > > When the server is terminated due to an error occurring in one of its > functions, what happens if another process calls one of the server's > functions in between the time the server is terminated and the time the > supervisor restarts it? Hi Ryan, correct me if i am wrong: messages are dropped if the receiving process is dead. with gen_server, if you use synchronized call, you can specify a timeout value gen_server:call(ServerRef, Request, Timeout) "The call may fail for several reasons, including timeout and the called gen_server dying before or during the call." I think you get either a badarg (pid doesn't exist (as it's dead)) or timeout (if the process died after message had been sent) >Will the call be queued and executed once the server > is back up? no > Or is there a chance that it could be lost? yes Howard > > Thanks. > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From vychodil.hynek@REDACTED Tue Jan 13 09:29:21 2009 From: vychodil.hynek@REDACTED (Hynek Vychodil) Date: Tue, 13 Jan 2009 09:29:21 +0100 Subject: [erlang-questions] Here's hoping we get frames or structs in 2009! In-Reply-To: References: Message-ID: <20090113082922.8183624013@relay.gooddata.com> What 'record' module implementation are you talking about? http://www.erlang.org/doc/man/record.html -> 404 Not found On Mon, Jan 12, 2009 at 7:25 PM, Christian wrote: > On Mon, Jan 12, 2009 at 00:10, James Hague wrote: > > but the code ends up bulky and contrived. Yeah, we've all discussed > > this for years, so here's hoping there's some movement on this front. > > Syntactically, the version I like the most at the moment is the record > > syntax without a record name: > > > > #{width=1280, height=1024, colors=65536} > > Ponder this approach I implemented: > > 1> Assoc = record:list_to_assoc([foo, bar, baz]). > {{bar,3},{baz,4},{foo,2}} > 2> record:in(baz, Assoc). > 4 > > Basically a map from atoms to integers. I choose to perform binary > search. One can then create a tuple where this Assoc takes the place > of the atom tag in a plain record: > > 3> Rec = record:new(Assoc). > {{{bar,3},{baz,4},{foo,2}},[],[],[]} > > And operations use the atom->integer map to implement basic > manipulations on tuples by field name: > > 4> Rec1 = record:set(baz, x, Rec). > {{{bar,3},{baz,4},{foo,2}},[],[],x} > > 5> record:get(baz, Rec1). > x > > The downside in this implementation of Assoc is that there is going to > be lots of repeated references to new copies of same-valued tuples. > Every copy inserted and taken out of ets will create a new one, as > well as when they are sent between processes using the normal memory > model. > > > But would it be ugly to 'intern' this Assoc into a new first-class > type? A reference counted atom() to integer() map type? Each module > could put the assoc objects it needs in the constant pool so they > would not need to intern the assoc object over and over again. > > > Checking that an assoc contains a number of fields or the tuple > element they're mapped to is efficient enough that it is no worser > compared to the existing non-constant-complexity guards and bifs. > > > I actually cant think of any downside to the approach that is a > problem for the intended use. It just looks very difficult to create a > new type and guards for it, requiring changes to both the compiler and > the vm. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero! Try Good Data now for free: www.gooddata.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From raimo+erlang-questions@REDACTED Tue Jan 13 09:36:40 2009 From: raimo+erlang-questions@REDACTED (Raimo Niskanen) Date: Tue, 13 Jan 2009 09:36:40 +0100 Subject: [erlang-questions] : gen_server question In-Reply-To: References: Message-ID: <20090113083640.GA28495@erix.ericsson.se> On Mon, Jan 12, 2009 at 09:45:47PM -0800, Howard Yeh wrote: > > 2009/1/12 Ryan Lepidi : > > Hello, > > > > When the server is terminated due to an error occurring in one of its > > functions, what happens if another process calls one of the server's > > functions in between the time the server is terminated and the time the > > supervisor restarts it? > > Hi Ryan, > > correct me if i am wrong: > > messages are dropped if the receiving process is dead. > > with gen_server, if you use synchronized call, you can specify a timeout value > > gen_server:call(ServerRef, Request, Timeout) > > "The call may fail for several reasons, including timeout and the > called gen_server dying before or during the call." > > I think you get either a badarg (pid doesn't exist (as it's dead)) or > timeout (if the process died after message had been sent) Since gen_server:call nowadays uses erlang:monitor on the target process, the call should fail if the process is dead or dies during the call. Using timeout is generally a bad thing. The monitors should cover all cases, except the case when the client simply can not wait any longer. If you use timeout you will have to be prepared to take care of any garbage late answers that may arrive after a timeout. > > >Will the call be queued and executed once the server > > is back up? > > no > > > Or is there a chance that it could be lost? > > yes How do you mean lost? It will succeed or fail. It fails if the server is dead or as soon as the server dies during the call. If the server dies during the call there is a chance that the server received the message, did its thing, but died before sending the reply, so a failed call may actually have triggered server side effects. If the connection breaks up it may take a while before the remote node is deemed dead, but then all monitors for processes on the remote node are triggered. > > Howard > > > > Thanks. > > > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions@REDACTED > > http://www.erlang.org/mailman/listinfo/erlang-questions > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions -- / Raimo Niskanen, Erlang/OTP, Ericsson AB From kenneth.lundin@REDACTED Tue Jan 13 09:39:55 2009 From: kenneth.lundin@REDACTED (Kenneth Lundin) Date: Tue, 13 Jan 2009 09:39:55 +0100 Subject: [erlang-questions] use of disksup In-Reply-To: References: <27418990.1391651231793814277.JavaMail.defaultUser@defaultHost> Message-ID: It is a bug (on Windows only) that the total disk size is reported in bytes instead of as documented kbytes. This will be corrected in R13 (i.e the next scheduled release). The fix is simple, just BSR 10 on the value. /Kenneth Erlang/OTP Ericsson On Mon, Jan 12, 2009 at 11:08 PM, Kenneth Lundin wrote: > Hi, > > The disksup module belongs to the os_mon application which in turn is > dependent on the sasl application. > Therefore you need to start these applications before you call > disksup:get_disk_data(). > > Like this (in the Erlang shell) > > 1> application:start(sasl). > ok > 2> application:start(os_mon). > ok > 3> disksup:get_disk_data(). > [{"C:\\",200047001600,69},{"G:\\",39991275520,35}] > 4> > > The above result was what I got on my Windows XP machine. > > It means that C: has a total space of 200047001600 bytes and 69% is > occupied, G: has 39991275520 bytes and 35% is occupied. > While writing this I noticed that the documentation says that the unit > should be Kbytes but it is not in this case. I have to check > if there is a documentation error or if it is a different behaviour on > Windows than on Linux. > I think the use of disksup on Windows is very sparse compared to Linux > and Solaris and that might be the reason for not detecting this > before, if it is bytes only on Windows. > > /Regards Kenneth Erlang/OTP Ericsson > > > > On Mon, Jan 12, 2009 at 9:56 PM, simone8280@REDACTED > wrote: >> Hi! I'm new in eralng programming; I want to write a small application for know >> the size of a disk and its available space, in Windows environment. I found the >> module disksup (function get_disk_data()). I try to use it but without success, >> I'm not able to configure it (it need a configuration with module os_mon). Can >> you help me? I need to configure get_disk_data() function and to specify the >> disk I want to analyze (for example I want to know the space's amount of drive >> a:). If you write a few line of source of exemple I'm very happy. (well there >> are an infinity of way to know the size of a disk but I want to do it with >> erlang) >> >> thankyou, see you at next >> >> >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions@REDACTED >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > From bernie@REDACTED Tue Jan 13 09:44:38 2009 From: bernie@REDACTED (Bernard Duggan) Date: Tue, 13 Jan 2009 19:44:38 +1100 Subject: [erlang-questions] Included Applications and application:get_application/0 In-Reply-To: References: <496AED38.7090805@m5net.com> Message-ID: <496C5476.5060203@m5net.com> Hi Litao, I do get what you mean, and I figured that that might have been the case (thanks, though, for quoting the docs for me - I did manage to miss that third sentence, which makes it clear that it's intended behaviour and not a bug). It does raise the question, however, of handling configuration. It seems like, under the current system, configuration that I put in the included app's .app file will not be retrieved if I call application:get_env/1. Instead I have to explicitly call application:get_env/2 with the application name. This means that any code which is shared between apps in my system but which relies on per-app configuration needs to have the app name explicitly passed down from code that is specific to the given app. Additionally, even code specific to the app needs to hard-code the application name every time it gets a config parameter. In other words, there's no neat way to override a configuration parameter in an included app's configuration, since it's not actually that app's configuration...kind of. I know that's a bit rambling, but hopefully you can see what I'm getting at: the configuration given for an included app in it's .app, sys.config or a specified .config file isn't easily reachable without hard-coding the included app's name throughout the code. Perhaps someone can suggest a tidy workaround for this? I've been pondering it most of the day and haven't really come up with anything satisfactory. Cheers, Bernard litao cheng wrote: > Hi, Bernard. > I think you have some misunderstanding with the included application in > erlang otp. > In the OTP Design Principles - Included Application 8.1, the document says: > " > The application controller will automatically load any included applications > when loading a primary application, but not start them. Instead, the top > supervisor of the included application must be started by a supervisor in > the including application > This means that when running, an included application is in fact part of the > primary application and a process in an included application will consider > itself belonging to the primary application. > " > From the document, we can known the Top supervisor of the included > application must be started by the primary application. > > Now, Let's see what happen when we call application:get_application/0 in > included application, it will call > application_controller:get_application(group_leader()) (in application.erl > ), the group_leader() must be same as the primary application, because they > run in the same supervisor tree. If you don't agree with this conclusion, > let's continue! In application_controller.erl, get_application/1 call > ets:match/2 from the ac_table:ets:match(ac_tab, {{application_master, '$1'}, > Master}), the item with the element is application_master is only inserted > by started application, the included application insert item to ac_tab with > 'loaded' identify. > > I hope you can understand my mean. :) > > BS > > > 2009/1/12 Bernard Duggan > >> Hi all, >> I'm working on a set of applications in a "primary >> application/included applications" type arrangement as described in the >> OTP Design Principles document. I'm curious if there is a programmatic >> way to tell which of the apps a process is considered to be running in. >> application:get_application/0 appears to always return the primary >> application, even when called from an included application. Is this >> intentional? Is it a bug? Am I misunderstanding something about the >> nature of included applications, such as them only being "applications" >> in some senses but not others (and if so, what senses are those...if you >> follow me)? >> >> Cheers, >> >> Bernard >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions@REDACTED >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > From antoine.koener@REDACTED Tue Jan 13 10:11:33 2009 From: antoine.koener@REDACTED (Antoine Koener) Date: Tue, 13 Jan 2009 10:11:33 +0100 Subject: [erlang-questions] extended timer module to handle absolute time-of-day timers In-Reply-To: <496C1D1B.3050501@gmail.com> References: <496C1D1B.3050501@gmail.com> Message-ID: <1c89b3a10901130111u7fec793dq1b5d29c9aeb0c619@mail.gmail.com> Hi, 2009/1/13 Serge Aleynikov > > > I extended the timer module to handle absolute time specifications. > By the way; is there any "full blown" scheduler for erlang out there ? -- http://easyerl.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From malcolm@REDACTED Tue Jan 13 13:04:06 2009 From: malcolm@REDACTED (Malcolm Dowse) Date: Tue, 13 Jan 2009 12:04:06 +0000 Subject: [erlang-questions] '--' BIF to be used with caution? Message-ID: <707529930901130404y5418466bmc375525ef765e615@mail.gmail.com> Hello, I ran into an issue with Erlang the other day. I'm not sure if it's a bug, but I thought I should warn others. I was using '--' to get the difference between two large lists. As expected it was very slow, but, to my surprise, ERTS became completely unresponsive for a long time. (Only one CPU was maxed out, and there was still plenty of memory available.) To reproduce (on Ubuntu 7.x, R12B-x), open an Erlang shell and type: spawn(fun() -> lists:seq(1,1000000) -- lists:seq(1,1000000,2) end). The unresponsiveness seems to be caused by '--' being a BIF. Is there a good reason for making it a BIF if it's not always an improvement? All the best, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From ed.korsberg@REDACTED Tue Jan 13 13:58:33 2009 From: ed.korsberg@REDACTED (Ed Korsberg) Date: Tue, 13 Jan 2009 07:58:33 -0500 Subject: [erlang-questions] Question about erlang history at Ericsson In-Reply-To: <3dbc6d1c0901121407j3afad440v25ae6a91096da478@mail.gmail.com> References: <3dbc6d1c0901121407j3afad440v25ae6a91096da478@mail.gmail.com> Message-ID: This is a fascinating history lesson and matches what I suspected to hear. The sad part of the story from what I read in the paper is that Ericsson pulled the plug on future product development using Erlang even after it was shown to be viable and valuable in several shipping products. It was a calculated business decision to do so but not a courageous one. It is a shame to see visionaries shut down by bean counters. On Mon, Jan 12, 2009 at 5:07 PM, Robert Virding wrote: > 2009/1/12 Ed Korsberg > >> I am new to this Erlang forum so please excuse any 'newbe' errors on my >> part. >> I recently learned of the power of Erlang while attending a conference and >> while I find the technology >> of the Erlang language interesting, I am really curious how Ericsson >> engineering and management had the >> courage to produce a real revenue generating product on a radical >> previously unproven design. >> >> Many companies have internal engineering resources to create innovative >> research projects but it is >> rare for these research projects to make the transition to shipping >> products complete with all the quality >> control and field support required. >> >> I would be curious to learn how Ericsson managed this transition from an >> internal R&D development to >> a real shipping product. > > > The references you got from Thomas and Tuncer are good and give some > insight into the development of Erlang and the problems the lab had when > doing it. > > BUT, one basic thing you must realise and is that the development of Erlang > was pure skunk-works and we in the lab decided more or less on our on accord > to do it. We were very lucky to get in contact with a group who were both > willing and able to try new technology for their development. It has never > really been sanctioned by management and only really been officially allowed > to be used when other more prefered alternatives have failed. Even then > there were many requests to phase it out and use other technologies. > > Another thing to realise is that Ericsson, like most other large companies, > is not a homogenous entity and while we only ever had very limited > management support there were groups inside Ericsson who had the need of, > and saw the benefits, of using Erlang in their products. And who were > willing to fight to use it. Basically we were continually fighting to keep > Erlang alive, spread it and try to support groups who were using it. > > Rather depressing perhaps but, I think, quite common for new technology in > larger companies. > > Of course the really big happening for the spread of Erlang out of Ericsson > was being able to release it as public source. There were many in Ericsson > who saw the benefits of not using restricted in-house developed > technologies, but unfortunately for us the official solution to this was to > use external products instead. It did, however, make it easier to get > permission to release it as open source. > > Robert > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From saleyn@REDACTED Tue Jan 13 14:18:27 2009 From: saleyn@REDACTED (Serge Aleynikov) Date: Tue, 13 Jan 2009 08:18:27 -0500 Subject: [erlang-questions] extended timer module to handle absolute time-of-day timers In-Reply-To: <1c89b3a10901130111u7fec793dq1b5d29c9aeb0c619@mail.gmail.com> References: <496C1D1B.3050501@gmail.com> <1c89b3a10901130111u7fec793dq1b5d29c9aeb0c619@mail.gmail.com> Message-ID: <496C94A3.4040701@gmail.com> Can you elaborate on the "full blown" part. The timer module is a scheduler. Are looking for cron-like or Microsoft-Outlook-like functionality? Antoine Koener wrote: > Hi, > > 2009/1/13 Serge Aleynikov > >> >> I extended the timer module to handle absolute time specifications. >> > > By the way; is there any "full blown" scheduler for erlang out there ? > From mikpe@REDACTED Tue Jan 13 14:31:05 2009 From: mikpe@REDACTED (Mikael Pettersson) Date: Tue, 13 Jan 2009 14:31:05 +0100 Subject: [erlang-questions] '--' BIF to be used with caution? In-Reply-To: <707529930901130404y5418466bmc375525ef765e615@mail.gmail.com> References: <707529930901130404y5418466bmc375525ef765e615@mail.gmail.com> Message-ID: <18796.38809.183338.116021@harpo.it.uu.se> Malcolm Dowse writes: > Hello, > > I ran into an issue with Erlang the other day. I'm not sure if it's a bug, > but I thought I should warn others. > > I was using '--' to get the difference between two large lists. As expected > it was very slow, but, to my surprise, ERTS became completely unresponsive > for a long time. (Only one CPU was maxed out, and there was still plenty of > memory available.) > > To reproduce (on Ubuntu 7.x, R12B-x), open an Erlang shell and type: > > spawn(fun() -> lists:seq(1,1000000) -- lists:seq(1,1000000,2) end). > > The unresponsiveness seems to be caused by '--' being a BIF. Is there a good > reason for making it a BIF if it's not always an improvement? 1) The time complexity for '--'/2 is quadratic, so you shouldn't expect it to be fast. 2) The unresponsiveness appears to be an implementation bug/limitation. BIFs have a mechanism for "yielding" the CPU when "enough work" has been done, in order to allow other processes to make progress, but the implementation of '--'/2 does not make use of that mechanism so it has to run to completion. From antoine.koener@REDACTED Tue Jan 13 14:37:07 2009 From: antoine.koener@REDACTED (Antoine Koener) Date: Tue, 13 Jan 2009 14:37:07 +0100 Subject: [erlang-questions] extended timer module to handle absolute time-of-day timers In-Reply-To: <496C94A3.4040701@gmail.com> References: <496C1D1B.3050501@gmail.com> <1c89b3a10901130111u7fec793dq1b5d29c9aeb0c619@mail.gmail.com> <496C94A3.4040701@gmail.com> Message-ID: <1c89b3a10901130537q4acfbae6v594949b0c38f163c@mail.gmail.com> On Tue, Jan 13, 2009 at 2:18 PM, Serge Aleynikov wrote: > Can you elaborate on the "full blown" part. The timer module is a > scheduler. Are looking for cron-like or Microsoft-Outlook-like > functionality? Sorry :) I was thinking about something like $Universe or Control-M. The purpose is to manage "jobs". A more accurate description could be a "Job Scheduler". I think that erlang is perfect for this task ! -- http://easyerl.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From chsu79@REDACTED Tue Jan 13 14:44:48 2009 From: chsu79@REDACTED (Christian) Date: Tue, 13 Jan 2009 14:44:48 +0100 Subject: [erlang-questions] gen_server question In-Reply-To: References: Message-ID: > correct me if i am wrong: > > messages are dropped if the receiving process is dead. > > with gen_server, if you use synchronized call, you can specify a timeout value > > gen_server:call(ServerRef, Request, Timeout) > > "The call may fail for several reasons, including timeout and the > called gen_server dying before or during the call." > > I think you get either a badarg (pid doesn't exist (as it's dead)) or > timeout (if the process died after message had been sent) Every time I want to remind myself on how this works i look at the do_call/4 function in lib/stdlib/src/gen.erl, it is the one that implement the gen_server:call currently. (Disclaimer, there can of course be undocumented features in the code that one should not rely on. But it is so much easier to understand code than english that describes code. :) What you learn is that gen_server:call will create a monitor on the server for the duration of the call. So it will detect immediately if the server has crashed, or if it crashes while it is waiting on a reply. Another fun trivia is that the monitor reference is used as a unique id to identify the correct request/response from the gen_server. Timeouts are really just relevant for gen_servers that are so bogged down that they cant get around to process your request and reply to it in time. (Also some code there for if its a node that doesnt support monitoring of processes). The gen_server will not notice that the caller have timed out, so it will process the request when it gets to it, unless it has crashed for other reasons by then. From ulf@REDACTED Tue Jan 13 14:47:07 2009 From: ulf@REDACTED (Ulf Wiger) Date: Tue, 13 Jan 2009 14:47:07 +0100 Subject: [erlang-questions] Question about erlang history at Ericsson In-Reply-To: References: <3dbc6d1c0901121407j3afad440v25ae6a91096da478@mail.gmail.com> Message-ID: <8209f740901130547v2ac449edi8d665ef43d15d72b@mail.gmail.com> 2009/1/13 Ed Korsberg : > This is a fascinating history lesson and matches what I suspected to hear. > The sad part of the story from what I read in the paper is that Ericsson > pulled the plug on future product development using Erlang even after it was > shown to be viable and valuable in several shipping products. It was a > calculated business decision to do so but not a courageous one. It is a > shame to see visionaries shut down by bean counters. Strictly speaking, the document that Bjarne referred to was an ERA (Ericsson Radio) document, and the policy not to use Erlang only referred to that division. It was assumed that the policy became corporate policy when its authors later moved up to corporate management, but this was, at least formally, incorrect. No such policy document ever existed at the corporate level, and the old ERA policy document disappeared when ERA was transformed into something else in a large reorganization. There are of course several approval levels in a large company, and different technologies basically need to be rubber-stamped as viable for business-critical applications. Erlang has received such approval for the product areas where it's actually used in important products. A fair description of Erlang's status within the company today is that it's regarded as a well-respected niche technology. That's not to say that there aren't detractors, but a more common situation is that people agree that Erlang has obvious strengths, but feel that they can't use it due to legacy considerations - a perfectly valid stance, especially in areas where the existing products are market leaders. (: BR, Ulf W > > On Mon, Jan 12, 2009 at 5:07 PM, Robert Virding wrote: >> >> 2009/1/12 Ed Korsberg >>> >>> I am new to this Erlang forum so please excuse any 'newbe' errors on my >>> part. >>> I recently learned of the power of Erlang while attending a conference >>> and while I find the technology >>> of the Erlang language interesting, I am really curious how Ericsson >>> engineering and management had the >>> courage to produce a real revenue generating product on a radical >>> previously unproven design. >>> >>> Many companies have internal engineering resources to create innovative >>> research projects but it is >>> rare for these research projects to make the transition to shipping >>> products complete with all the quality >>> control and field support required. >>> >>> I would be curious to learn how Ericsson managed this transition from an >>> internal R&D development to >>> a real shipping product. >> >> The references you got from Thomas and Tuncer are good and give some >> insight into the development of Erlang and the problems the lab had when >> doing it. >> >> BUT, one basic thing you must realise and is that the development of >> Erlang was pure skunk-works and we in the lab decided more or less on our on >> accord to do it. We were very lucky to get in contact with a group who were >> both willing and able to try new technology for their development. It has >> never really been sanctioned by management and only really been officially >> allowed to be used when other more prefered alternatives have failed. Even >> then there were many requests to phase it out and use other technologies. >> >> Another thing to realise is that Ericsson, like most other large >> companies, is not a homogenous entity and while we only ever had very >> limited management support there were groups inside Ericsson who had the >> need of, and saw the benefits, of using Erlang in their products. And who >> were willing to fight to use it. Basically we were continually fighting to >> keep Erlang alive, spread it and try to support groups who were using it. >> >> Rather depressing perhaps but, I think, quite common for new technology in >> larger companies. >> >> Of course the really big happening for the spread of Erlang out of >> Ericsson was being able to release it as public source. There were many in >> Ericsson who saw the benefits of not using restricted in-house developed >> technologies, but unfortunately for us the official solution to this was to >> use external products instead. It did, however, make it easier to get >> permission to release it as open source. >> >> Robert >> > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From vychodil.hynek@REDACTED Tue Jan 13 15:05:20 2009 From: vychodil.hynek@REDACTED (Hynek Vychodil) Date: Tue, 13 Jan 2009 15:05:20 +0100 Subject: [erlang-questions] gen_server question In-Reply-To: References: Message-ID: <20090113140521.861762402F@relay.gooddata.com> It's very well written. Anyway for one who can't found it in code, answer is: In case when server doesn't exists gen_server:call function exits with {noproc, {gen_server, call, [Name, Request, Timeout]}}. On Tue, Jan 13, 2009 at 2:44 PM, Christian wrote: > > correct me if i am wrong: > > > > messages are dropped if the receiving process is dead. > > > > with gen_server, if you use synchronized call, you can specify a timeout > value > > > > gen_server:call(ServerRef, Request, Timeout) > > > > "The call may fail for several reasons, including timeout and the > > called gen_server dying before or during the call." > > > > I think you get either a badarg (pid doesn't exist (as it's dead)) or > > timeout (if the process died after message had been sent) > > Every time I want to remind myself on how this works i look at the > do_call/4 function in > lib/stdlib/src/gen.erl, it is the one that implement the > gen_server:call currently. > > (Disclaimer, there can of course be undocumented features in the code > that one should not rely on. But it is so much easier to understand > code than english that describes code. :) > > What you learn is that gen_server:call will create a monitor on the > server for the duration of the call. So it will detect immediately if > the server has crashed, or if it crashes while it is waiting on a > reply. Another fun trivia is that the monitor reference is used as a > unique id to identify the correct request/response from the > gen_server. > > Timeouts are really just relevant for gen_servers that are so bogged > down that they cant get around to process your request and reply to it > in time. (Also some code there for if its a node that doesnt support > monitoring of processes). The gen_server will not notice that the > caller have timed out, so it will process the request when it gets to > it, unless it has crashed for other reasons by then. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero! Try Good Data now for free: www.gooddata.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From anders.danne@REDACTED Tue Jan 13 16:06:01 2009 From: anders.danne@REDACTED (Anders Danne) Date: Tue, 13 Jan 2009 16:06:01 +0100 Subject: [erlang-questions] Question about erlang history at Ericsson In-Reply-To: <3dbc6d1c0901121407j3afad440v25ae6a91096da478@mail.gmail.com> References: <3dbc6d1c0901121407j3afad440v25ae6a91096da478@mail.gmail.com> Message-ID: <496CADD9.7060403@ericsson.com> Robert Virding skrev: > > BUT, one basic thing you must realise and is that the development of > Erlang was pure skunk-works and we in the lab decided more or less on > our on accord to do it. We were very lucky to get in contact with a > group who were both willing and able to try new technology for their > development. It has never really been sanctioned by management and > only really been officially allowed to be used when other more > prefered alternatives have failed. Even then there were many requests > to phase it out and use other technologies. Erlang was the result from approved research projects and not a skunk-work. Ericsson's CTO was well aware about the activities. But like other research activities this was based on initiatives from researchers not from managers and business needs. ///Anders From francesco@REDACTED Tue Jan 13 16:48:21 2009 From: francesco@REDACTED (Francesco Cesarini (Erlang Training and Consulting)) Date: Tue, 13 Jan 2009 15:48:21 +0000 Subject: [erlang-questions] Question about erlang history at Ericsson In-Reply-To: References: Message-ID: <496CB7C5.90000@erlang-consulting.com> One of the things which is not obvious from this thread are the iterative cycles Erlang went through when it was invented. The CS lab first spent a few years prototyping telecom applications with existing languages (1985). Conclusion was that many had great features, but no one language encompassed them all... So they decided to invent their own, spending a few years prototyping telecom applications fine tuning the language in every iteration. When they felt comfortable with it, they got the first external users to evaluate it (1987). And from there, it had even more iterations (in the process, resulting in Mike Williams writing the first C based virtual machine in 1991). A year after the the first C based VM came out (The first one was in Prolog), a very small group of developers started using it to build the mobility server (1992), a product which went live two years later (1994). Feedback from support issues and further development after the system started selling was once again fed back to the CS lab, who in 1995 added new features such as distribution, records, macros, include files, funs and lists comprehensions. With this level of maturity, the language was now ready to be used in larger systems and the AXD301 and ANX projects became reality (1995) . In conjunction with them, the CS lab jump started the OTP project after merging it with a lightweight version of it called BOS. OTP R1 was released in 1996. So to say that the technology was unproven is not 100% correct. Maybe it was not proven in large scale projects, but it certainly was proven and validated in commercial products Ericsson was selling. This was more than other languages [which may not be named] who have 9 lives and a marketing department with generous funds behind them. By 1995, Erlang Systems (They did Training & Consulting) with a staff of about 25 employees dedicated to supporting Ericsson projects. The OTP department, as they are usually called, was also created around that time to support the development of Erlang itself. More info is also available in the paper wirtten for HOPL: http://www.cs.chalmers.se/Cs/Grundutb/Kurser/ppxt/HT2007/general/languages/armstrong-erlang_history.pdf Francesco (Feeling old but nostalgic :-) ) -- http://www.erlang-consulting.com Ed Korsberg wrote: > I am new to this Erlang forum so please excuse any 'newbe' errors on > my part. > I recently learned of the power of Erlang while attending a conference > and while I find the technology > of the Erlang language interesting, I am really curious how Ericsson > engineering and management had the > courage to produce a real revenue generating product on a radical > previously unproven design. > > Many companies have internal engineering resources to create > innovative research projects but it is > rare for these research projects to make the transition to shipping > products complete with all the quality > control and field support required. > > I would be curious to learn how Ericsson managed this transition from > an internal R&D development to > a real shipping product. > ------------------------------------------------------------------------ > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From vychodil.hynek@REDACTED Tue Jan 13 17:02:59 2009 From: vychodil.hynek@REDACTED (Hynek Vychodil) Date: Tue, 13 Jan 2009 17:02:59 +0100 Subject: [erlang-questions] '--' BIF to be used with caution? In-Reply-To: <707529930901130404y5418466bmc375525ef765e615@mail.gmail.com> References: <707529930901130404y5418466bmc375525ef765e615@mail.gmail.com> Message-ID: <20090113160300.58A672402F@relay.gooddata.com> '--' have O(N.M) complexity, if you suspect big M use you own O(M+N.logM) implementation. Do not use '--' for big M. 2009/1/13 Malcolm Dowse > Hello, > > I ran into an issue with Erlang the other day. I'm not sure if it's a bug, > but I thought I should warn others. > > I was using '--' to get the difference between two large lists. As expected > it was very slow, but, to my surprise, ERTS became completely unresponsive > for a long time. (Only one CPU was maxed out, and there was still plenty of > memory available.) > > To reproduce (on Ubuntu 7.x, R12B-x), open an Erlang shell and type: > > spawn(fun() -> lists:seq(1,1000000) -- lists:seq(1,1000000,2) end). > > The unresponsiveness seems to be caused by '--' being a BIF. Is there a > good reason for making it a BIF if it's not always an improvement? > > All the best, > > Malcolm > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero! Try Good Data now for free: www.gooddata.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From erlangy@REDACTED Tue Jan 13 17:03:39 2009 From: erlangy@REDACTED (Michael McDaniel) Date: Tue, 13 Jan 2009 08:03:39 -0800 Subject: [erlang-questions] extended timer module to handle absolute time-of-day timers In-Reply-To: <496C1D1B.3050501@gmail.com> References: <496C1D1B.3050501@gmail.com> Message-ID: <20090113160339.GJ10545@delora.autosys.us> Thanks - I like it. Just as I like timed_supervisor.erl which I use everyday (strictly speaking, it's always running!). I think the new functions would be useful additions to the OTP included timer module. ~Michael On Mon, Jan 12, 2009 at 11:48:27PM -0500, Serge Aleynikov wrote: > Sorry - previous email had a wrong attachment. > > > I extended the timer module to handle absolute time specifications. > > With this implementation it's possible to have messages sent on given > days of week at a certain time of day. Five new functions are added: > apply_at_local_time/4, send_at_local_time/3, exit_at_local_time/3, > apply_daily_at_local_time/5, send_daily_at_local_time/4. > > > Example1: Send a shutdown message to Pid at 23:00:00 every Friday and > Sunday. > timer:send_daily_at_local_time([fri,sun], {23,0,0}, Pid, shutdown). > > Example2: Send a restart message to Pid at "6:00:00": > timer:send_at_local_time({6,0,0}, Pid, restart). > > Legacy timer_server's functionality is not affected. > > The rationale behind this extension is that I frequently needed > functionality to schedule some "cron-like" recurrent activities, and was > always relying either on cron+erl_call or coding that activity with help > of timer:send_after/3 or timer:send_interval/2. As I finally got sick > of dealing with shortcomings of the timer module, I put together this > extension. > > Let me know if you also find it useful, and in such case perhaps we can > get it included in the OTP. > > Serge > > %% ``The contents of this file are subject to the Erlang Public License, > %% Version 1.1, (the "License"); you may not use this file except in > %% compliance with the License. You should have received a copy of the > %% Erlang Public License along with this software. If not, it can be > %% retrieved via the world wide web at http://www.erlang.org/. > %% > %% Software distributed under the License is distributed on an "AS IS" > %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See > %% the License for the specific language governing rights and limitations > %% under the License. > %% > %% The Initial Developer of the Original Code is Ericsson Utvecklings AB. > %% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings > %% AB. All Rights Reserved.'' > %% > %% Contributor: Serge Aleynikov > %% 12-Jan-2009 Added support for absolute time timers including: > %% apply_at_local_time/4, send_at_local_time/3, exit_at_local_time/3, > %% apply_daily_at_local_time/5, send_daily_at_local_time/4 > %% > %% $Id$ > %% > -module(timer). > > -export([apply_after/4, > send_after/3, send_after/2, > exit_after/3, exit_after/2, kill_after/2, kill_after/1, > apply_interval/4, send_interval/3, send_interval/2, > apply_at_local_time/4, send_at_local_time/3, > exit_at_local_time/3, kill_at_local_time/2, > apply_daily_at_local_time/5, send_daily_at_local_time/4, > cancel/1, sleep/1, tc/3, now_diff/2, > seconds/1, minutes/1, hours/1, hms/3]). > > -export([start_link/0, start/0, > handle_call/3, handle_info/2, > init/1, > code_change/3, handle_cast/2, terminate/2]). > > %% internal exports for test purposes only > -export([get_status/0]). > > %% Max > -define(MAX_TIMEOUT, 16#0800000). > -define(TIMER_TAB, timer_tab). > -define(INTERVAL_TAB, timer_interval_tab). > > %% > %% Interface functions > %% > %% Time is in milliseconds. > %% TimeOfDay is in time() format (e.g. {3,59,15} = "03:59:15") > %% > apply_at_local_time(TimeOfDay, M, F, A) -> > req(apply_at_local_time, {TimeOfDay, {M, F, A}}). > > apply_after(Time, M, F, A) -> > req(apply_after, {Time, {M, F, A}}). > > send_at_local_time(TimeOfDay, Pid, Message) -> > req(apply_at_local_time, {TimeOfDay, {?MODULE, send, [Pid, Message]}}). > > send_after(Time, Pid, Message) -> > req(apply_after, {Time, {?MODULE, send, [Pid, Message]}}). > > send_after(Time, Message) -> > send_after(Time, self(), Message). > > exit_at_local_time(TimeOfDay, Pid, Reason) -> > req(apply_at_local_time, {TimeOfDay, {erlang, exit, [Pid, Reason]}}). > > exit_after(Time, Pid, Reason) -> > req(apply_after, {Time, {erlang, exit, [Pid, Reason]}}). > > exit_after(Time, Reason) -> > exit_after(Time, self(), Reason). > > kill_at_local_time(TimeOfDay, Pid) -> > exit_at_local_time(TimeOfDay, Pid, kill). > > kill_after(Time, Pid) -> > exit_after(Time, Pid, kill). > > kill_after(Time) -> > exit_after(Time, self(), kill). > > %% @spec (DaysOfWeek, TimeOfDay::time(), M, F, A) -> > %% {ok, TRef::ref()} | {error, Reason} > %% DaysOfWeek = [DayOfWeek] > %% DayOfWeek = integer() | sun | mon | tue | wed | thu | fri | sat > apply_daily_at_local_time(DaysOfWeek, TimeOfDay, M, F, A) -> > req(apply_daily_at_local_time, {DaysOfWeek, TimeOfDay, self(), {M, F, A}}). > > apply_interval(Time, M, F, A) -> > req(apply_interval, {Time, self(), {M, F, A}}). > > %% @spec (DaysOfWeek, TimeOfDay::time(), Pid::pid(), M, F, A) -> > %% {ok, TRef::ref()} | {error, Reason} > %% DaysOfWeek = [DayOfWeek] > %% DayOfWeek = integer() | sun | mon | tue | wed | thu | fri | sat > send_daily_at_local_time(DaysOfWeek, TimeOfDay, Pid, Message) -> > Details = {?MODULE, send, [Pid, Message]}, > req(apply_daily_at_local_time, {DaysOfWeek, TimeOfDay, Pid, Details}). > > send_interval(Time, Pid, Message) -> > req(apply_interval, {Time, Pid, {?MODULE, send, [Pid, Message]}}). > > send_interval(Time, Message) -> > send_interval(Time, self(), Message). > > cancel(BRef) -> > req(cancel, BRef). > > sleep(T) -> > receive > after T -> ok > end. > > %% > %% Measure the execution time (in microseconds) for an MFA. > %% > tc(M, F, A) -> > Before = erlang:now(), > Val = (catch apply(M, F, A)), > After = erlang:now(), > {now_diff(After, Before), Val}. > > %% > %% Calculate the time difference (in microseconds) of two > %% erlang:now() timestamps, T2-T1. > %% > now_diff({A2, B2, C2}, {A1, B1, C1}) -> > ((A2-A1)*1000000 + B2-B1)*1000000 + C2-C1. > > %% > %% Convert seconds, minutes etc. to milliseconds. > %% > seconds(Seconds) -> > 1000*Seconds. > minutes(Minutes) -> > 1000*60*Minutes. > hours(Hours) -> > 1000*60*60*Hours. > hms(H, M, S) -> > hours(H) + minutes(M) + seconds(S). > > %% > %% Start/init functions > %% > > %% Start is only included because of backward compatibility! > start() -> > ensure_started(). > > start_link() -> > gen_server:start_link({local, timer_server}, ?MODULE, [], []). > > init([]) -> > process_flag(trap_exit, true), > ets:new(?TIMER_TAB,[named_table,ordered_set,protected]), > ets:new(?INTERVAL_TAB,[named_table,protected]), > {ok, [], infinity}. > > ensure_started() -> > case whereis(timer_server) of > undefined -> > C = {timer_server, {?MODULE, start_link, []}, permanent, 1000, > worker, [?MODULE]}, > supervisor:start_child(kernel_safe_sup, C), % kernel_safe_sup > ok; > _ -> ok > end. > > %% server calls > > req(Req, Arg) -> > SysTime = now(), > ensure_started(), > gen_server:call(timer_server, {Req, Arg, SysTime}, infinity). > > %% > %% handle_call(Request, From, Timers) -> > %% {reply, Response, Timers, Timeout} > %% > %% Time and Timeout is in milliseconds. WhenStarted is in now() format. > %% Started is in microseconds. > %% > handle_call({apply_after, {Time, Op}, WhenStarted}, _From, _Ts) > when is_integer(Time), Time >= 0 -> > Started = system_time(WhenStarted), > BRef = {Started + 1000*Time, make_ref()}, > Timer = {BRef, timeout, Op}, > ets:insert(?TIMER_TAB, Timer), > Timeout = timer_timeout(now()), > {reply, {ok, BRef}, [], Timeout}; > > handle_call({apply_at_local_time, {{H,M,S} = _Time, Op}, WhenStarted}, From, Ts) > when is_integer(H), H >= 0, H < 24 > , is_integer(M), M >= 0, M < 61 > , is_integer(S), S >= 0, S < 61 > -> > {_, {H1,M1,S1}} = calendar:now_to_local_time(WhenStarted), > Interval = hms(H-H1, M-M1, S-S1), > if Interval < 0 -> > {reply, {error, expired}, [], next_timeout()}; > true -> > handle_call({apply_after, {Interval, Op}, WhenStarted}, From, Ts) > end; > > handle_call({apply_daily_at_local_time, {DaysOfWeek, {H,M,S} = Time, To, MFA}, WhenStarted}, _From, _Ts) > when is_integer(H), H >= 0, H < 24 > , is_integer(M), M >= 0, M < 61 > , is_integer(S), S >= 0, S < 61 > , is_list(DaysOfWeek) > -> > try > DaysOfWeek =:= [] andalso throw(badarg), > %% Represent days of week > %% as a 7-element tuple with 1's being the days of week > %% when to fire the timer and 0's when not to fire. > DOWs = lists:foldl(fun(I, T) -> setelement(I, T, 1) end, > erlang:make_tuple(7, 0), [to_dow(D) || D <- DaysOfWeek]), > {Date, Started} = calendar:now_to_local_time(WhenStarted), > DOW = calendar:day_of_the_week(Date), > Interval = dow_interval(DOWs, DOW, Time, Started, 0), > %% To must be a pid or a registered name > Pid = get_pid(To), > is_pid(Pid) orelse throw(badarg), > catch link(Pid), > Ref = make_ref(), > BRef1 = {interval, Ref}, > BRef2 = {system_time(WhenStarted) + Interval*1000000, Ref}, > Timer = {BRef2, {daily_local_time, DOWs, Time, Pid}, MFA}, > ets:insert(?INTERVAL_TAB,{BRef1,BRef2,Pid}), > ets:insert(?TIMER_TAB, Timer), > Timeout = timer_timeout(now()), > {reply, {ok, BRef1}, [], Timeout} > catch throw:Reason -> > {reply, {error, Reason}, [], next_timeout()} > end; > > handle_call({apply_interval, {Time, To, MFA}, WhenStarted}, _From, _Ts) > when is_integer(Time), Time >= 0 -> > Started = system_time(WhenStarted), > %% To must be a pid or a registered name > case get_pid(To) of > Pid when is_pid(Pid) -> > catch link(Pid), > NowSysTime = now(), > Ref = make_ref(), > BRef1 = {interval, Ref}, > Interval = Time*1000, > BRef2 = {Started + Interval, Ref}, > Timer = {BRef2, {repeat, Interval, Pid}, MFA}, > ets:insert(?INTERVAL_TAB,{BRef1,BRef2,Pid}), > ets:insert(?TIMER_TAB, Timer), > Timeout = timer_timeout(NowSysTime), > {reply, {ok, BRef1}, [], Timeout}; > _ -> > {reply, {error, badarg}, [], next_timeout()} > end; > > handle_call({cancel, BRef = {_Time, Ref}, _}, _From, Ts) > when is_reference(Ref) -> > delete_ref(BRef), > {reply, {ok, cancel}, Ts, next_timeout()}; > handle_call({cancel, _BRef, _}, _From, Ts) -> > {reply, {error, badarg}, Ts, next_timeout()}; > handle_call({apply_after, _, _}, _From, Ts) -> > {reply, {error, badarg}, Ts, next_timeout()}; > handle_call({apply_at_local_time, {_, _Op}, _}, _From, Ts) -> > {reply, {error, badarg}, Ts, next_timeout()}; > handle_call({apply_interval, _, _}, _From, Ts) -> > {reply, {error, badarg}, Ts, next_timeout()}; > handle_call(_Else, _From, Ts) -> % Catch anything else > {noreply, Ts, next_timeout()}. > > handle_info(timeout, Ts) -> % Handle timeouts > Timeout = timer_timeout(now()), > {noreply, Ts, Timeout}; > handle_info({'EXIT', Pid, _Reason}, Ts) -> % Oops, someone died > pid_delete(Pid), > {noreply, Ts, next_timeout()}; > handle_info(_OtherMsg, Ts) -> % Other Msg's > {noreply, Ts, next_timeout()}. > > handle_cast(_Req, Ts) -> % Not predicted but handled > {noreply, Ts, next_timeout()}. > > terminate(_Reason, _State) -> > ok. > > code_change(_OldVsn, State, _Extra) -> > %% According to the man for gen server no timer can be set here. > {ok, State}. > > %% > %% timer_timeout(NowSysTime) > %% > %% Apply and remove already timed-out timers. A timer is a tuple > %% {Time, BRef, Op, MFA}, where Time is in microseconds. > %% Returns {Timeout, Timers}, where Timeout is in milliseconds. > %% > timer_timeout(NowSysTime) -> > SysTime = system_time(NowSysTime), > case ets:first(?TIMER_TAB) of > '$end_of_table' -> > infinity; > {Time, _Ref} when Time > SysTime -> > Timeout = (Time - SysTime) div 1000, > %% Returned timeout must fit in a small int > min(Timeout, ?MAX_TIMEOUT); > Key -> > case ets:lookup(?TIMER_TAB, Key) of > [{Key, timeout, MFA}] -> > ets:delete(?TIMER_TAB,Key), > do_apply(MFA), > timer_timeout(NowSysTime); > [{{Time, Ref}, Repeat = {repeat, Interv, To}, MFA}] -> > ets:delete(?TIMER_TAB,Key), > NewTime = Time + Interv, > %% Update the interval entry (last in table) > ets:insert(?INTERVAL_TAB,{{interval,Ref},{NewTime,Ref},To}), > do_apply(MFA), > ets:insert(?TIMER_TAB, {{NewTime, Ref}, Repeat, MFA}), > timer_timeout(NowSysTime); > [{{_Time, Ref}, Repeat = {daily_local_time, DOWs, TimeOfDay, Pid}, MFA}] -> > ets:delete(?TIMER_TAB,Key), > {Date, CurTime} = calendar:now_to_local_time(add_second(NowSysTime)), > DOW = calendar:day_of_the_week(Date), > Interval = dow_interval(DOWs, DOW, TimeOfDay, CurTime, 0), > NewTime = system_time(NowSysTime) + Interval*1000000, > %% Update the interval entry (last in table) > ets:insert(?INTERVAL_TAB,{{interval,Ref},{NewTime,Ref},Pid}), > do_apply(MFA), > ets:insert(?TIMER_TAB, {{NewTime, Ref}, Repeat, MFA}), > timer_timeout(NowSysTime) > end > end. > > %% > %% delete_ref > %% > > delete_ref(BRef = {interval, _}) -> > case ets:lookup(?INTERVAL_TAB, BRef) of > [{_, BRef2, _Pid}] -> > ets:delete(?INTERVAL_TAB, BRef), > ets:delete(?TIMER_TAB, BRef2); > _ -> % TimerReference does not exist, do nothing > ok > end; > delete_ref(BRef) -> > ets:delete(?TIMER_TAB,BRef). > > %% > %% pid_delete > %% > > pid_delete(Pid) -> > IntervalTimerList = > ets:select(?INTERVAL_TAB, > [{{'_', '_','$1'}, > [{'==','$1',Pid}], > ['$_']}]), > lists:foreach(fun({IntKey, TimerKey, _ }) -> > ets:delete(?INTERVAL_TAB,IntKey), > ets:delete(?TIMER_TAB,TimerKey) > end, IntervalTimerList). > > %% Calculate time to the next timeout. Returned timeout must fit in a > %% small int. > > next_timeout() -> > case ets:first(?TIMER_TAB) of > '$end_of_table' -> > infinity; > {Time, _ } -> > min(positive((Time - system_time()) div 1000), ?MAX_TIMEOUT) > end. > > %% Help functions > do_apply({M,F,A}) -> > case {M, F, A} of > {?MODULE, send, A} -> > %% If send op. send directly, (faster than spawn) > catch send(A); > {erlang, exit, [Name, Reason]} -> > catch exit(get_pid(Name), Reason); > _ -> > %% else spawn process with the operation > catch spawn(M,F,A) > end. > > max(X, Y) when X > Y -> > X; > max(_X, Y) -> > Y. > > min(X, Y) when X < Y -> > X; > min(_X, Y) -> > Y. > > positive(X) -> > max(X, 0). > > to_dow(mon) -> 1; > to_dow(tue) -> 2; > to_dow(wed) -> 3; > to_dow(thu) -> 4; > to_dow(fri) -> 5; > to_dow(sat) -> 6; > to_dow(sun) -> 7; > to_dow(I) when is_integer(I), I >= 1, I =< 7 -> I; > to_dow(_) -> throw(badarg). > > seconds_diff({H2,M2,S2}, {H1,M1,S1}) -> > (H2-H1)*3600 + (M2-M1)*60 + (S2-S1). > > add_second({M,S,U}) when S < 1000000 -> > {M,S+1,U}; > add_second({M,_,U}) -> > {M+1,0,U}. > > dow_interval(DOWs, Dow, Time, NowTime, 0) when element(Dow, DOWs) =:= 1 -> > case seconds_diff(Time, NowTime) of > TodayInterval when TodayInterval >= 0 -> > TodayInterval; > _ -> > % Current time passed target time for today. > % Find interval from NowTime to future Time. > dow_interval(DOWs, Dow, Time, NowTime, 1) > end; > dow_interval(DOWs, Dow, Time, NowTime, _) -> > % Current time is in another DayOfWeek. > % Find interval from NowTime to future Time. > NextDays = get_days(DOWs, (Dow rem 7) + 1, 0), > seconds_diff({24,0,0}, NowTime) % Seconds from now until end-of-day > + NextDays*86400 % Seconds in days until given day of week > + seconds_diff(Time, {0,0,0}). % Seconds from beginning of day to Time > > get_days(DOWs, Dow, N) when element(Dow, DOWs) =:= 1 -> > N; > get_days(DOWs, Dow, N) when N < 8 -> > get_days(DOWs, (Dow rem 7) + 1, N+1); > get_days(_, _, _) -> > throw(badarg). > > %% > %% system_time() -> time in microseconds > %% > system_time() -> > Now = erlang:now(), > system_time(Now). > system_time(Now) -> > {M,S,U} = Now, > 1000000*(M*1000000 + S) + U. > > send([Pid, Msg]) -> > Pid ! Msg. > > get_pid(Name) when is_pid(Name) -> > Name; > get_pid(undefined) -> > undefined; > get_pid(Name) when is_atom(Name) -> > get_pid(whereis(Name)); > get_pid(_) -> > undefined. > > %% > %% get_status() -> > %% {{TimerTabName,TotalNumTimers},{IntervalTabName,NumIntervalTimers}} > %% > %% This function is for test purposes only; it is used by the test suite. > %% There is a small possibility that there is a mismatch of one entry > %% between the 2 tables if this call is made when the timer server is > %% in the middle of a transaction > > get_status() -> > Info1 = ets:info(?TIMER_TAB), > {value,{size,TotalNumTimers}} = lists:keysearch(size, 1, Info1), > Info2 = ets:info(?INTERVAL_TAB), > {value,{size,NumIntervalTimers}} = lists:keysearch(size, 1, Info2), > {{?TIMER_TAB,TotalNumTimers},{?INTERVAL_TAB,NumIntervalTimers}}. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions -- Michael McDaniel Portland, Oregon, USA http://trip.autosys.us http://autosys.us From matthias@REDACTED Tue Jan 13 18:33:07 2009 From: matthias@REDACTED (Matthias Lang) Date: Tue, 13 Jan 2009 18:33:07 +0100 Subject: [erlang-questions] To what VxWorks platforms has Erlang been ported? In-Reply-To: References: Message-ID: <20090113173307.GA4007@contorpis.lisalinda.com> On Monday, January 12, Ed Korsberg wrote: > I read the Erlang has been ported at one time to WindRiver's VxWorks. > However to what hardware platform/processor has this been ported to? There are other people who know far more about this than I do, but since there's been no answer from them (yet?), here's what I know: I'm fairly sure it Erlang ran (runs, those devices are almost certainly still in use) on VxWorks on the Motorola 68360. I also think it's also used on Motorola's PPC 603 and MPC 860 CPUs. > We are currently using VxWorks 6.6 for ARM9 and XScale processors. > We also have it for Freescale Coldfire MCF5329. > I rather doubt Erlang has been ported to these variations of the VxWorks OS > but I thought I would ask anyway. Not that I'm aware of, but other people know more. > How would someone proceed in porting Erlang to a new platform? For a new CPU using linux, there's a rough note here: http://www.trapexit.org/Cross_compiling For VxWorks, I'd start off looking for the string 'vxworks' in 'otp_build' in the top of the tree. Hope this helps. I haven't used Erlang on VxWorks for about a decade, though I still get phantom pains in my scarred limbs every time someone reminds me of VxWorks. Though I hear it has memory protection these days. Matt From erlang@REDACTED Tue Jan 13 22:34:18 2009 From: erlang@REDACTED (Joe Armstrong) Date: Tue, 13 Jan 2009 22:34:18 +0100 Subject: [erlang-questions] Question about erlang history at Ericsson In-Reply-To: References: Message-ID: <9b08084c0901131334p6a023524l47f2007496d76354@mail.gmail.com> 2009/1/12 Ed Korsberg : > I am new to this Erlang forum so please excuse any 'newbe' errors on my > part. > I recently learned of the power of Erlang while attending a conference and > while I find the technology > of the Erlang language interesting, I am really curious how Ericsson > engineering and management had the > courage to produce a real revenue generating product on a radical previously > unproven design. > > Many companies have internal engineering resources to create innovative > research projects but it is > rare for these research projects to make the transition to shipping products > complete with all the quality > control and field support required. > > I would be curious to learn how Ericsson managed this transition from an > internal R&D development to > a real shipping product. The transition was easy - they paid to do this. It became a real shipping project when they decided to use Erlang for the AXD301 - at that stage they put in the necessary $$$'s. Now why did they choose Erlang for this project? - because all other alternatives had failed - ie it was not the strength of Erlang that was the deciding factor - rather the non-existence of alternatives. Now how come the Erlang stuff was developed in the first place? This was a happy accident - In the early 1980's a computer science lab was formed - most of the guys in the newly formed lab had zero experience with technology transfer, so we all thought that all we had to do was "invert stuff" and then "sell the idea to the management" nobody told us that this was like permanently banging your hand against a brick wall. Inventing stuff is the easy bit ... The selling stuff was tricky - we were very bad at this but very optimistic (still am :-) - we made all the classic mistakes - insulting people - getting into technical wars - The turning point came when Erlang was banned - at the time we were very pissed off but like most carefull considered management decsions the net result was the exact opposite of what was planned - the consequences of the ban were difficult to forsee - but chaos was created - so things changed rapidly. Thinking back the *important* things were: - enthusiasm and optimism (believe in what you do) - serendipity - chaos - smart people - finance I think we systematically under-rate the significance of chance and chaos. Most significant change takes place in very short time periods of chaos. Erlang had many periods when nothing happened for years then rapid changes could take place in very short time periods, always when a crisis occurred (ie Erlang was banned, a big project failed etc). Moral - forget about careful planning and move quickly when a crisis occurs - trust your gut feelings. Cheers /Joe Armstrong > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From victor.sovetov@REDACTED Wed Jan 14 01:21:46 2009 From: victor.sovetov@REDACTED (Viktor Sovietov) Date: Tue, 13 Jan 2009 16:21:46 -0800 (PST) Subject: [erlang-questions] mnesia: composite keys? In-Reply-To: References: <200901092245.09386.peter@sabaini.at> <71f43ded-7365-4e63-891c-17c1baccf775@y1g2000pra.googlegroups.com> Message-ID: On Jan 10, 9:10?pm, Paul Mineiro wrote: > On Fri, 9 Jan 2009, Viktor Sovietov wrote: > > If you use ordered_set tables that tuple keys are useful, because you > > can organize hierarchies inside one table. In other hand, you can't > > save such tables on disk, so... Anyway, Erlang isn't MUMPS, so you > > simply have not any mechanism to operate with complex keys. > > I have a nonstandard extension to mnesia that allows one to define new > table types, plus a disk-based ordered set table so defined. > > http://code.google.com/p/mnesiaex/ > > Also we use tuples as keys extensively in our application. I found this useful as well, I use it with tcerl, but again, there still is no mechanism to navigate index trees efficiently : ( Unfortunately. Sincerely, --Victor > > -- p > > > > > > > > > Sincerely, > > > --Victor > > > On Jan 9, 11:45?pm, Peter Sabaini wrote: > > > Hello list, > > > > I've read[1] that mnesia doesn't support composite keys. It seems I can use > > > keys made up of tuples though: > > > > (emacs@REDACTED)11> mnesia:create_table(test, [{attributes, [id, data]}]). > > > {atomic,ok} > > > (emacs@REDACTED)19> Ins = fun() -> mnesia:write({test, {a_key, 0}, "asdfasdf"}) > > > end. > > > #Fun > > > (emacs@REDACTED)20> mnesia:transaction(Ins). > > > {atomic,ok} > > > (emacs@REDACTED)21> R = fun() -> mnesia:read(test, {a_key, 0}) end. > > > #Fun > > > (emacs@REDACTED)22> mnesia:transaction(R). > > > {atomic,[{test,{a_key,0},"asdfasdf"}]} > > > > Is tuples as keys common practice or A Really Bad Idea(tm)? > > > > thx, > > > peter. > > > > [1]http://www.erlang.org/pipermail/erlang-questions/2008-February/032903... > > > > ?signature.asc > > > < 1KViewDownload > > > > _______________________________________________ > > > erlang-questions mailing list > > > erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions > > _______________________________________________ > > erlang-questions mailing list > > erlang-questi...@REDACTED > >http://www.erlang.org/mailman/listinfo/erlang-questions > > In an artificial world, only extremists live naturally. > > ? ? ? ? -- Paul Graham > _______________________________________________ > erlang-questions mailing list > erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions From cureadvocate@REDACTED Wed Jan 14 01:46:05 2009 From: cureadvocate@REDACTED (Steven Edwards) Date: Tue, 13 Jan 2009 19:46:05 -0500 Subject: [erlang-questions] net_adm:ping/1 returning pang; epmd shows nodes Message-ID: I am having some trouble with Erlang installed under andLinux. epmd shows four live nodes (test1-4) running in separate SSH sessions, but I am unable to ping any of them with net_adm:ping/1. net_adm:names/0 returns the tuple {error,address}. I'm obviously a newbie. Can anyone offer suggestions or--even better--solutions? :) Thanks, Steven -------------- next part -------------- An HTML attachment was scrubbed... URL: From hayeah@REDACTED Wed Jan 14 01:58:47 2009 From: hayeah@REDACTED (Howard Yeh) Date: Tue, 13 Jan 2009 16:58:47 -0800 Subject: [erlang-questions] gen_server question In-Reply-To: <20090113140521.8701C24063@relay.gooddata.com> References: <20090113140521.8701C24063@relay.gooddata.com> Message-ID: I read the gen_server stuff recursively today. i liked the middleman trick when multi_calling remote nodes. very nice stuff. proc_lib and sys are cool too. On Tue, Jan 13, 2009 at 6:05 AM, Hynek Vychodil wrote: > It's very well written. Anyway for one who can't found it in code, answer > is: In case when server doesn't exists gen_server:call function exits with > {noproc, {gen_server, call, [Name, Request, Timeout]}}. > > On Tue, Jan 13, 2009 at 2:44 PM, Christian wrote: >> >> > correct me if i am wrong: >> > >> > messages are dropped if the receiving process is dead. >> > >> > with gen_server, if you use synchronized call, you can specify a timeout >> > value >> > >> > gen_server:call(ServerRef, Request, Timeout) >> > >> > "The call may fail for several reasons, including timeout and the >> > called gen_server dying before or during the call." >> > >> > I think you get either a badarg (pid doesn't exist (as it's dead)) or >> > timeout (if the process died after message had been sent) >> >> Every time I want to remind myself on how this works i look at the >> do_call/4 function in >> lib/stdlib/src/gen.erl, it is the one that implement the >> gen_server:call currently. >> >> (Disclaimer, there can of course be undocumented features in the code >> that one should not rely on. But it is so much easier to understand >> code than english that describes code. :) >> >> What you learn is that gen_server:call will create a monitor on the >> server for the duration of the call. So it will detect immediately if >> the server has crashed, or if it crashes while it is waiting on a >> reply. Another fun trivia is that the monitor reference is used as a >> unique id to identify the correct request/response from the >> gen_server. >> >> Timeouts are really just relevant for gen_servers that are so bogged >> down that they cant get around to process your request and reply to it >> in time. (Also some code there for if its a node that doesnt support >> monitoring of processes). The gen_server will not notice that the >> caller have timed out, so it will process the request when it gets to >> it, unless it has crashed for other reasons by then. >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions@REDACTED >> http://www.erlang.org/mailman/listinfo/erlang-questions > > > > -- > --Hynek (Pichi) Vychodil > > Analyze your data in minutes. Share your insights instantly. Thrill your > boss. Be a data hero! > Try Good Data now for free: www.gooddata.com > From anupam.kapoor@REDACTED Wed Jan 14 03:23:12 2009 From: anupam.kapoor@REDACTED (Anupam Kapoor) Date: Wed, 14 Jan 2009 07:53:12 +0530 Subject: [erlang-questions] variable argument preprocessor macros Message-ID: hi all, is there a way to define a variable argument macro in erlang ? something like '...' (elipsis) stuff in C ? i tried to look for the information, but could not really find anything pertinent. for example, i would like to be able to say: SIMPLE_SERVER_DEBUG("mesg-1", "mesg-2") in one place, and in some other place SIMPLE_SERVER_DEUBG("mesg-1", "mesg-2", mesg-3, mesg-4) etc etc i have just started dabbling in the language, so please be gentle :o) kind regards anupam -- In the beginning was the lambda, and the lambda was with Emacs, and Emacs was the lambda. From rvirding@REDACTED Wed Jan 14 03:40:34 2009 From: rvirding@REDACTED (Robert Virding) Date: Wed, 14 Jan 2009 03:40:34 +0100 Subject: [erlang-questions] variable argument preprocessor macros In-Reply-To: References: Message-ID: <3dbc6d1c0901131840x57fbb638m995ff1d244181927@mail.gmail.com> No. The only thing you can do is have is to have: SIMPLE_SERVER_DEBUG_2("mesg-1", "mesg-2") and SIMPLE_SERVER_DEUBG_4("mesg-1", "mesg-2", mesg-3, mesg-4) Which is generally not a problem for you. An alternative would be to use LFE which has proper lisp and scheme macros. If you like writing in lisp. :-) Robert 2009/1/14 Anupam Kapoor > hi all, > > is there a way to define a variable argument macro in erlang ? > something like '...' (elipsis) stuff in C ? i tried to look for the > information, but could not really find anything pertinent. > > for example, i would like to be able to say: > SIMPLE_SERVER_DEBUG("mesg-1", "mesg-2") in one place, > and in some other place > SIMPLE_SERVER_DEUBG("mesg-1", "mesg-2", mesg-3, mesg-4) > etc etc > > i have just started dabbling in the language, so please be gentle :o) > > kind regards > anupam > -- > In the beginning was the lambda, and the lambda was with Emacs, and > Emacs was the lambda. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From saleyn@REDACTED Wed Jan 14 04:04:01 2009 From: saleyn@REDACTED (Serge Aleynikov) Date: Tue, 13 Jan 2009 22:04:01 -0500 Subject: [erlang-questions] extended timer module to handle absolute time-of-day timers In-Reply-To: <20090113160339.GJ10545@delora.autosys.us> References: <496C1D1B.3050501@gmail.com> <20090113160339.GJ10545@delora.autosys.us> Message-ID: <496D5621.2070207@gmail.com> Since you are using the timed_supervisor, I'll post an updated version to trapexit that fixes some bugs within the week or so. Serge Michael McDaniel wrote: > Thanks - I like it. Just as I like timed_supervisor.erl which I use > everyday (strictly speaking, it's always running!). > > I think the new functions would be useful additions to the > OTP included timer module. > > > ~Michael > > > On Mon, Jan 12, 2009 at 11:48:27PM -0500, Serge Aleynikov wrote: >> Sorry - previous email had a wrong attachment. >> >> >> I extended the timer module to handle absolute time specifications. >> >> With this implementation it's possible to have messages sent on given >> days of week at a certain time of day. Five new functions are added: >> apply_at_local_time/4, send_at_local_time/3, exit_at_local_time/3, >> apply_daily_at_local_time/5, send_daily_at_local_time/4. >> >> >> Example1: Send a shutdown message to Pid at 23:00:00 every Friday and >> Sunday. >> timer:send_daily_at_local_time([fri,sun], {23,0,0}, Pid, shutdown). >> >> Example2: Send a restart message to Pid at "6:00:00": >> timer:send_at_local_time({6,0,0}, Pid, restart). >> >> Legacy timer_server's functionality is not affected. >> >> The rationale behind this extension is that I frequently needed >> functionality to schedule some "cron-like" recurrent activities, and was >> always relying either on cron+erl_call or coding that activity with help >> of timer:send_after/3 or timer:send_interval/2. As I finally got sick >> of dealing with shortcomings of the timer module, I put together this >> extension. >> >> Let me know if you also find it useful, and in such case perhaps we can >> get it included in the OTP. >> >> Serge >> > >> %% ``The contents of this file are subject to the Erlang Public License, >> %% Version 1.1, (the "License"); you may not use this file except in >> %% compliance with the License. You should have received a copy of the >> %% Erlang Public License along with this software. If not, it can be >> %% retrieved via the world wide web at http://www.erlang.org/. >> %% >> %% Software distributed under the License is distributed on an "AS IS" >> %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See >> %% the License for the specific language governing rights and limitations >> %% under the License. >> %% >> %% The Initial Developer of the Original Code is Ericsson Utvecklings AB. >> %% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings >> %% AB. All Rights Reserved.'' >> %% >> %% Contributor: Serge Aleynikov >> %% 12-Jan-2009 Added support for absolute time timers including: >> %% apply_at_local_time/4, send_at_local_time/3, exit_at_local_time/3, >> %% apply_daily_at_local_time/5, send_daily_at_local_time/4 >> %% >> %% $Id$ >> %% >> -module(timer). >> >> -export([apply_after/4, >> send_after/3, send_after/2, >> exit_after/3, exit_after/2, kill_after/2, kill_after/1, >> apply_interval/4, send_interval/3, send_interval/2, >> apply_at_local_time/4, send_at_local_time/3, >> exit_at_local_time/3, kill_at_local_time/2, >> apply_daily_at_local_time/5, send_daily_at_local_time/4, >> cancel/1, sleep/1, tc/3, now_diff/2, >> seconds/1, minutes/1, hours/1, hms/3]). >> >> -export([start_link/0, start/0, >> handle_call/3, handle_info/2, >> init/1, >> code_change/3, handle_cast/2, terminate/2]). >> >> %% internal exports for test purposes only >> -export([get_status/0]). >> >> %% Max >> -define(MAX_TIMEOUT, 16#0800000). >> -define(TIMER_TAB, timer_tab). >> -define(INTERVAL_TAB, timer_interval_tab). >> >> %% >> %% Interface functions >> %% >> %% Time is in milliseconds. >> %% TimeOfDay is in time() format (e.g. {3,59,15} = "03:59:15") >> %% >> apply_at_local_time(TimeOfDay, M, F, A) -> >> req(apply_at_local_time, {TimeOfDay, {M, F, A}}). >> >> apply_after(Time, M, F, A) -> >> req(apply_after, {Time, {M, F, A}}). >> >> send_at_local_time(TimeOfDay, Pid, Message) -> >> req(apply_at_local_time, {TimeOfDay, {?MODULE, send, [Pid, Message]}}). >> >> send_after(Time, Pid, Message) -> >> req(apply_after, {Time, {?MODULE, send, [Pid, Message]}}). >> >> send_after(Time, Message) -> >> send_after(Time, self(), Message). >> >> exit_at_local_time(TimeOfDay, Pid, Reason) -> >> req(apply_at_local_time, {TimeOfDay, {erlang, exit, [Pid, Reason]}}). >> >> exit_after(Time, Pid, Reason) -> >> req(apply_after, {Time, {erlang, exit, [Pid, Reason]}}). >> >> exit_after(Time, Reason) -> >> exit_after(Time, self(), Reason). >> >> kill_at_local_time(TimeOfDay, Pid) -> >> exit_at_local_time(TimeOfDay, Pid, kill). >> >> kill_after(Time, Pid) -> >> exit_after(Time, Pid, kill). >> >> kill_after(Time) -> >> exit_after(Time, self(), kill). >> >> %% @spec (DaysOfWeek, TimeOfDay::time(), M, F, A) -> >> %% {ok, TRef::ref()} | {error, Reason} >> %% DaysOfWeek = [DayOfWeek] >> %% DayOfWeek = integer() | sun | mon | tue | wed | thu | fri | sat >> apply_daily_at_local_time(DaysOfWeek, TimeOfDay, M, F, A) -> >> req(apply_daily_at_local_time, {DaysOfWeek, TimeOfDay, self(), {M, F, A}}). >> >> apply_interval(Time, M, F, A) -> >> req(apply_interval, {Time, self(), {M, F, A}}). >> >> %% @spec (DaysOfWeek, TimeOfDay::time(), Pid::pid(), M, F, A) -> >> %% {ok, TRef::ref()} | {error, Reason} >> %% DaysOfWeek = [DayOfWeek] >> %% DayOfWeek = integer() | sun | mon | tue | wed | thu | fri | sat >> send_daily_at_local_time(DaysOfWeek, TimeOfDay, Pid, Message) -> >> Details = {?MODULE, send, [Pid, Message]}, >> req(apply_daily_at_local_time, {DaysOfWeek, TimeOfDay, Pid, Details}). >> >> send_interval(Time, Pid, Message) -> >> req(apply_interval, {Time, Pid, {?MODULE, send, [Pid, Message]}}). >> >> send_interval(Time, Message) -> >> send_interval(Time, self(), Message). >> >> cancel(BRef) -> >> req(cancel, BRef). >> >> sleep(T) -> >> receive >> after T -> ok >> end. >> >> %% >> %% Measure the execution time (in microseconds) for an MFA. >> %% >> tc(M, F, A) -> >> Before = erlang:now(), >> Val = (catch apply(M, F, A)), >> After = erlang:now(), >> {now_diff(After, Before), Val}. >> >> %% >> %% Calculate the time difference (in microseconds) of two >> %% erlang:now() timestamps, T2-T1. >> %% >> now_diff({A2, B2, C2}, {A1, B1, C1}) -> >> ((A2-A1)*1000000 + B2-B1)*1000000 + C2-C1. >> >> %% >> %% Convert seconds, minutes etc. to milliseconds. >> %% >> seconds(Seconds) -> >> 1000*Seconds. >> minutes(Minutes) -> >> 1000*60*Minutes. >> hours(Hours) -> >> 1000*60*60*Hours. >> hms(H, M, S) -> >> hours(H) + minutes(M) + seconds(S). >> >> %% >> %% Start/init functions >> %% >> >> %% Start is only included because of backward compatibility! >> start() -> >> ensure_started(). >> >> start_link() -> >> gen_server:start_link({local, timer_server}, ?MODULE, [], []). >> >> init([]) -> >> process_flag(trap_exit, true), >> ets:new(?TIMER_TAB,[named_table,ordered_set,protected]), >> ets:new(?INTERVAL_TAB,[named_table,protected]), >> {ok, [], infinity}. >> >> ensure_started() -> >> case whereis(timer_server) of >> undefined -> >> C = {timer_server, {?MODULE, start_link, []}, permanent, 1000, >> worker, [?MODULE]}, >> supervisor:start_child(kernel_safe_sup, C), % kernel_safe_sup >> ok; >> _ -> ok >> end. >> >> %% server calls >> >> req(Req, Arg) -> >> SysTime = now(), >> ensure_started(), >> gen_server:call(timer_server, {Req, Arg, SysTime}, infinity). >> >> %% >> %% handle_call(Request, From, Timers) -> >> %% {reply, Response, Timers, Timeout} >> %% >> %% Time and Timeout is in milliseconds. WhenStarted is in now() format. >> %% Started is in microseconds. >> %% >> handle_call({apply_after, {Time, Op}, WhenStarted}, _From, _Ts) >> when is_integer(Time), Time >= 0 -> >> Started = system_time(WhenStarted), >> BRef = {Started + 1000*Time, make_ref()}, >> Timer = {BRef, timeout, Op}, >> ets:insert(?TIMER_TAB, Timer), >> Timeout = timer_timeout(now()), >> {reply, {ok, BRef}, [], Timeout}; >> >> handle_call({apply_at_local_time, {{H,M,S} = _Time, Op}, WhenStarted}, From, Ts) >> when is_integer(H), H >= 0, H < 24 >> , is_integer(M), M >= 0, M < 61 >> , is_integer(S), S >= 0, S < 61 >> -> >> {_, {H1,M1,S1}} = calendar:now_to_local_time(WhenStarted), >> Interval = hms(H-H1, M-M1, S-S1), >> if Interval < 0 -> >> {reply, {error, expired}, [], next_timeout()}; >> true -> >> handle_call({apply_after, {Interval, Op}, WhenStarted}, From, Ts) >> end; >> >> handle_call({apply_daily_at_local_time, {DaysOfWeek, {H,M,S} = Time, To, MFA}, WhenStarted}, _From, _Ts) >> when is_integer(H), H >= 0, H < 24 >> , is_integer(M), M >= 0, M < 61 >> , is_integer(S), S >= 0, S < 61 >> , is_list(DaysOfWeek) >> -> >> try >> DaysOfWeek =:= [] andalso throw(badarg), >> %% Represent days of week >> %% as a 7-element tuple with 1's being the days of week >> %% when to fire the timer and 0's when not to fire. >> DOWs = lists:foldl(fun(I, T) -> setelement(I, T, 1) end, >> erlang:make_tuple(7, 0), [to_dow(D) || D <- DaysOfWeek]), >> {Date, Started} = calendar:now_to_local_time(WhenStarted), >> DOW = calendar:day_of_the_week(Date), >> Interval = dow_interval(DOWs, DOW, Time, Started, 0), >> %% To must be a pid or a registered name >> Pid = get_pid(To), >> is_pid(Pid) orelse throw(badarg), >> catch link(Pid), >> Ref = make_ref(), >> BRef1 = {interval, Ref}, >> BRef2 = {system_time(WhenStarted) + Interval*1000000, Ref}, >> Timer = {BRef2, {daily_local_time, DOWs, Time, Pid}, MFA}, >> ets:insert(?INTERVAL_TAB,{BRef1,BRef2,Pid}), >> ets:insert(?TIMER_TAB, Timer), >> Timeout = timer_timeout(now()), >> {reply, {ok, BRef1}, [], Timeout} >> catch throw:Reason -> >> {reply, {error, Reason}, [], next_timeout()} >> end; >> >> handle_call({apply_interval, {Time, To, MFA}, WhenStarted}, _From, _Ts) >> when is_integer(Time), Time >= 0 -> >> Started = system_time(WhenStarted), >> %% To must be a pid or a registered name >> case get_pid(To) of >> Pid when is_pid(Pid) -> >> catch link(Pid), >> NowSysTime = now(), >> Ref = make_ref(), >> BRef1 = {interval, Ref}, >> Interval = Time*1000, >> BRef2 = {Started + Interval, Ref}, >> Timer = {BRef2, {repeat, Interval, Pid}, MFA}, >> ets:insert(?INTERVAL_TAB,{BRef1,BRef2,Pid}), >> ets:insert(?TIMER_TAB, Timer), >> Timeout = timer_timeout(NowSysTime), >> {reply, {ok, BRef1}, [], Timeout}; >> _ -> >> {reply, {error, badarg}, [], next_timeout()} >> end; >> >> handle_call({cancel, BRef = {_Time, Ref}, _}, _From, Ts) >> when is_reference(Ref) -> >> delete_ref(BRef), >> {reply, {ok, cancel}, Ts, next_timeout()}; >> handle_call({cancel, _BRef, _}, _From, Ts) -> >> {reply, {error, badarg}, Ts, next_timeout()}; >> handle_call({apply_after, _, _}, _From, Ts) -> >> {reply, {error, badarg}, Ts, next_timeout()}; >> handle_call({apply_at_local_time, {_, _Op}, _}, _From, Ts) -> >> {reply, {error, badarg}, Ts, next_timeout()}; >> handle_call({apply_interval, _, _}, _From, Ts) -> >> {reply, {error, badarg}, Ts, next_timeout()}; >> handle_call(_Else, _From, Ts) -> % Catch anything else >> {noreply, Ts, next_timeout()}. >> >> handle_info(timeout, Ts) -> % Handle timeouts >> Timeout = timer_timeout(now()), >> {noreply, Ts, Timeout}; >> handle_info({'EXIT', Pid, _Reason}, Ts) -> % Oops, someone died >> pid_delete(Pid), >> {noreply, Ts, next_timeout()}; >> handle_info(_OtherMsg, Ts) -> % Other Msg's >> {noreply, Ts, next_timeout()}. >> >> handle_cast(_Req, Ts) -> % Not predicted but handled >> {noreply, Ts, next_timeout()}. >> >> terminate(_Reason, _State) -> >> ok. >> >> code_change(_OldVsn, State, _Extra) -> >> %% According to the man for gen server no timer can be set here. >> {ok, State}. >> >> %% >> %% timer_timeout(NowSysTime) >> %% >> %% Apply and remove already timed-out timers. A timer is a tuple >> %% {Time, BRef, Op, MFA}, where Time is in microseconds. >> %% Returns {Timeout, Timers}, where Timeout is in milliseconds. >> %% >> timer_timeout(NowSysTime) -> >> SysTime = system_time(NowSysTime), >> case ets:first(?TIMER_TAB) of >> '$end_of_table' -> >> infinity; >> {Time, _Ref} when Time > SysTime -> >> Timeout = (Time - SysTime) div 1000, >> %% Returned timeout must fit in a small int >> min(Timeout, ?MAX_TIMEOUT); >> Key -> >> case ets:lookup(?TIMER_TAB, Key) of >> [{Key, timeout, MFA}] -> >> ets:delete(?TIMER_TAB,Key), >> do_apply(MFA), >> timer_timeout(NowSysTime); >> [{{Time, Ref}, Repeat = {repeat, Interv, To}, MFA}] -> >> ets:delete(?TIMER_TAB,Key), >> NewTime = Time + Interv, >> %% Update the interval entry (last in table) >> ets:insert(?INTERVAL_TAB,{{interval,Ref},{NewTime,Ref},To}), >> do_apply(MFA), >> ets:insert(?TIMER_TAB, {{NewTime, Ref}, Repeat, MFA}), >> timer_timeout(NowSysTime); >> [{{_Time, Ref}, Repeat = {daily_local_time, DOWs, TimeOfDay, Pid}, MFA}] -> >> ets:delete(?TIMER_TAB,Key), >> {Date, CurTime} = calendar:now_to_local_time(add_second(NowSysTime)), >> DOW = calendar:day_of_the_week(Date), >> Interval = dow_interval(DOWs, DOW, TimeOfDay, CurTime, 0), >> NewTime = system_time(NowSysTime) + Interval*1000000, >> %% Update the interval entry (last in table) >> ets:insert(?INTERVAL_TAB,{{interval,Ref},{NewTime,Ref},Pid}), >> do_apply(MFA), >> ets:insert(?TIMER_TAB, {{NewTime, Ref}, Repeat, MFA}), >> timer_timeout(NowSysTime) >> end >> end. >> >> %% >> %% delete_ref >> %% >> >> delete_ref(BRef = {interval, _}) -> >> case ets:lookup(?INTERVAL_TAB, BRef) of >> [{_, BRef2, _Pid}] -> >> ets:delete(?INTERVAL_TAB, BRef), >> ets:delete(?TIMER_TAB, BRef2); >> _ -> % TimerReference does not exist, do nothing >> ok >> end; >> delete_ref(BRef) -> >> ets:delete(?TIMER_TAB,BRef). >> >> %% >> %% pid_delete >> %% >> >> pid_delete(Pid) -> >> IntervalTimerList = >> ets:select(?INTERVAL_TAB, >> [{{'_', '_','$1'}, >> [{'==','$1',Pid}], >> ['$_']}]), >> lists:foreach(fun({IntKey, TimerKey, _ }) -> >> ets:delete(?INTERVAL_TAB,IntKey), >> ets:delete(?TIMER_TAB,TimerKey) >> end, IntervalTimerList). >> >> %% Calculate time to the next timeout. Returned timeout must fit in a >> %% small int. >> >> next_timeout() -> >> case ets:first(?TIMER_TAB) of >> '$end_of_table' -> >> infinity; >> {Time, _ } -> >> min(positive((Time - system_time()) div 1000), ?MAX_TIMEOUT) >> end. >> >> %% Help functions >> do_apply({M,F,A}) -> >> case {M, F, A} of >> {?MODULE, send, A} -> >> %% If send op. send directly, (faster than spawn) >> catch send(A); >> {erlang, exit, [Name, Reason]} -> >> catch exit(get_pid(Name), Reason); >> _ -> >> %% else spawn process with the operation >> catch spawn(M,F,A) >> end. >> >> max(X, Y) when X > Y -> >> X; >> max(_X, Y) -> >> Y. >> >> min(X, Y) when X < Y -> >> X; >> min(_X, Y) -> >> Y. >> >> positive(X) -> >> max(X, 0). >> >> to_dow(mon) -> 1; >> to_dow(tue) -> 2; >> to_dow(wed) -> 3; >> to_dow(thu) -> 4; >> to_dow(fri) -> 5; >> to_dow(sat) -> 6; >> to_dow(sun) -> 7; >> to_dow(I) when is_integer(I), I >= 1, I =< 7 -> I; >> to_dow(_) -> throw(badarg). >> >> seconds_diff({H2,M2,S2}, {H1,M1,S1}) -> >> (H2-H1)*3600 + (M2-M1)*60 + (S2-S1). >> >> add_second({M,S,U}) when S < 1000000 -> >> {M,S+1,U}; >> add_second({M,_,U}) -> >> {M+1,0,U}. >> >> dow_interval(DOWs, Dow, Time, NowTime, 0) when element(Dow, DOWs) =:= 1 -> >> case seconds_diff(Time, NowTime) of >> TodayInterval when TodayInterval >= 0 -> >> TodayInterval; >> _ -> >> % Current time passed target time for today. >> % Find interval from NowTime to future Time. >> dow_interval(DOWs, Dow, Time, NowTime, 1) >> end; >> dow_interval(DOWs, Dow, Time, NowTime, _) -> >> % Current time is in another DayOfWeek. >> % Find interval from NowTime to future Time. >> NextDays = get_days(DOWs, (Dow rem 7) + 1, 0), >> seconds_diff({24,0,0}, NowTime) % Seconds from now until end-of-day >> + NextDays*86400 % Seconds in days until given day of week >> + seconds_diff(Time, {0,0,0}). % Seconds from beginning of day to Time >> >> get_days(DOWs, Dow, N) when element(Dow, DOWs) =:= 1 -> >> N; >> get_days(DOWs, Dow, N) when N < 8 -> >> get_days(DOWs, (Dow rem 7) + 1, N+1); >> get_days(_, _, _) -> >> throw(badarg). >> >> %% >> %% system_time() -> time in microseconds >> %% >> system_time() -> >> Now = erlang:now(), >> system_time(Now). >> system_time(Now) -> >> {M,S,U} = Now, >> 1000000*(M*1000000 + S) + U. >> >> send([Pid, Msg]) -> >> Pid ! Msg. >> >> get_pid(Name) when is_pid(Name) -> >> Name; >> get_pid(undefined) -> >> undefined; >> get_pid(Name) when is_atom(Name) -> >> get_pid(whereis(Name)); >> get_pid(_) -> >> undefined. >> >> %% >> %% get_status() -> >> %% {{TimerTabName,TotalNumTimers},{IntervalTabName,NumIntervalTimers}} >> %% >> %% This function is for test purposes only; it is used by the test suite. >> %% There is a small possibility that there is a mismatch of one entry >> %% between the 2 tables if this call is made when the timer server is >> %% in the middle of a transaction >> >> get_status() -> >> Info1 = ets:info(?TIMER_TAB), >> {value,{size,TotalNumTimers}} = lists:keysearch(size, 1, Info1), >> Info2 = ets:info(?INTERVAL_TAB), >> {value,{size,NumIntervalTimers}} = lists:keysearch(size, 1, Info2), >> {{?TIMER_TAB,TotalNumTimers},{?INTERVAL_TAB,NumIntervalTimers}}. > >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions@REDACTED >> http://www.erlang.org/mailman/listinfo/erlang-questions > From saleyn@REDACTED Wed Jan 14 04:18:50 2009 From: saleyn@REDACTED (Serge Aleynikov) Date: Tue, 13 Jan 2009 22:18:50 -0500 Subject: [erlang-questions] extended timer module to handle absolute time-of-day timers In-Reply-To: <1c89b3a10901130537q4acfbae6v594949b0c38f163c@mail.gmail.com> References: <496C1D1B.3050501@gmail.com> <1c89b3a10901130111u7fec793dq1b5d29c9aeb0c619@mail.gmail.com> <496C94A3.4040701@gmail.com> <1c89b3a10901130537q4acfbae6v594949b0c38f163c@mail.gmail.com> Message-ID: <496D599A.2030308@gmail.com> I don't know of an open source one, but a combination of timed_supervisor [1] and erlexec [2] is nearly 90% of what's needed to build one. It's in my plans to create such a job scheduler, but I'm not sure yet if it'll be possible to open source it... Serge [1] http://forum.trapexit.org/viewtopic.php?p=44147#44147 [2] http://code.google.com/p/erlexec/ Antoine Koener wrote: > On Tue, Jan 13, 2009 at 2:18 PM, Serge Aleynikov wrote: > >> Can you elaborate on the "full blown" part. The timer module is a >> scheduler. Are looking for cron-like or Microsoft-Outlook-like >> functionality? > > > Sorry :) > I was thinking about something like $Universe or Control-M. > > The purpose is to manage "jobs". A more accurate description could be a "Job > Scheduler". > I think that erlang is perfect for this task ! > From rtrlists@REDACTED Wed Jan 14 10:32:00 2009 From: rtrlists@REDACTED (Robert Raschke) Date: Wed, 14 Jan 2009 09:32:00 +0000 Subject: [erlang-questions] Question about erlang history at Ericsson In-Reply-To: <9b08084c0901131334p6a023524l47f2007496d76354@mail.gmail.com> References: <9b08084c0901131334p6a023524l47f2007496d76354@mail.gmail.com> Message-ID: <6a3ae47e0901140132j61e1eab6u4f524a8329ff5220@mail.gmail.com> On Tue, Jan 13, 2009 at 9:34 PM, Joe Armstrong wrote: [... snip ...] > I think we systematically under-rate the significance of chance and > chaos. Most significant change > takes place in very short time periods of chaos. Erlang had many > periods when nothing happened for years > then rapid changes could take place in very short time periods, always > when a crisis occurred > (ie Erlang was banned, a big project failed etc). > > Moral - forget about careful planning and move quickly when a crisis > occurs - trust your gut feelings. Joe, have you been reading Virginia Satir and Jerry Weinberg? Funnily enough, the presentation is usually the other way round, if you want change (or cope with it), then you'll need to be able to cope with the neccessary bit of chaos to see you through. The hardest thing to get right, though, is the ability to express (or take advantage of) your gut feelings. Tricky one that. Robby From qiulang@REDACTED Wed Jan 14 10:51:23 2009 From: qiulang@REDACTED (lang qiu) Date: Wed, 14 Jan 2009 17:51:23 +0800 Subject: [erlang-questions] Questions about lib_chan and IRC Lite (other than the one had been asked before). Message-ID: Hi all, Nobody replies my question about IRC Lite, so I ask it the second time (Change the title in hoping that it may cause some attention). And I notice that someone asked about some other questions about IRC Lite before, which may suggest this example is tricky. So my here is my question, if a process sends another process several messages *in a row* while in the receiving process when it processes the first message, it does that in its own receiving loop, then all the remaining message the first process sends goes into this loop and this may against the purpose. My words may sound nonsense. So check these codes, In the chat_client.erl, try_to_connect(Parent, Host, Port, Pwd) -> ... Parent ! {*connected, MM*}, exit(*connectorFinished*) end. While in parent *disconnected/3*, ... receive {*connected, MM*} -> lib_chan_mm:send(MM, {login, Group, Nick}), *wait_login_response*(Widget, MM); {*'EXIT', _Pid, _Reason*} -> %% if we add this clause here ... *wait_login_response/2* defines, ... receive ... Other -> io:format("chat_client login unexpected:~p~p~n",[Other,MM]), ... The result shows that wait_login_response/2 receives try_to_connect's 'EXIT' message not disconnected/3. I further test that if try_to_connect sends more messages after {*connected, MM*} , they will all be received by wait_login_response instead of disconnected/3 even there are match patterns in disconnected/3 (Correct me if I am wrong). But this may not be a good idea. Maybe it is better to let disconnected/3 processes the 'EXIT' message instead of wait_login_response/2 (because it should only deal with the login related message). So how do we fix this problem ? Or I miss something here ? Thanks, Qiulang -------------- next part -------------- An HTML attachment was scrubbed... URL: From rickard.s.green@REDACTED Wed Jan 14 10:59:19 2009 From: rickard.s.green@REDACTED (Rickard Green) Date: Wed, 14 Jan 2009 10:59:19 +0100 Subject: [erlang-questions] [erlang-bugs] R12B-3/64bit/smp Stuck disk_log_server In-Reply-To: <496CA465.8080302@ericsson.com> References: <496B3B9E.3070407@ericsson.com> <496CA465.8080302@ericsson.com> Message-ID: <496DB777.5090400@ericsson.com> A source patch can now be downloaded: http://www.erlang.org/download/patches/otp_src_R12B-5_OTP-7738.patch http://www.erlang.org/download/patches/otp_src_R12B-5_OTP-7738.readme Regards, Rickard Green, Erlang/OTP, Ericsson AB. Rickard Green wrote: > I'll prepare a source patch fixing the problem. I wont be able to post > it until tomorrow, though. > > Regards, > Rickard Green, Erlang/OTP, Ericsson AB. > > > Geoff Cant wrote: >> Hi Rickard, thank you very much - this sounds correct to me. The >> customer cluster is still running a cron job that effectively does >> lists:foreach(fun erlang:garbage_collect/1, erlang:processes()) every >> ten minutes. >> >> This script was introduced as a stop-gap measure when running a heavily >> loaded ejabberd cluster on the 32bit VM where an out of memory condition >> would take down the node and then the entire cluster due to some >> problems with cross-node monitor storms. The cluster now runs on 64bit >> VMs so we'll revisit the memory consumption problem and avoid using >> erlang:garbage_collect/1. >> >> We'll disable the script and see if the problem recurs. >> >> Once again, thank you very much - I'm always very impressed by the level >> of support the OTP team gives the erlang community. >> >> Cheers, >> --Geoff >> >> >> Rickard Green writes: >> >>> Hi Geoff, >>> >>> I've looked at this and found a bug that may have caused this. When a >>> process garbage collect another process and the process being garbage >>> collected also receives a message during the garbage collect, the >>> process being garbage collected can end up in the state that you >>> described. >>> >>> This kind of garbage collect only happen when someone calls the >>> garbage_collect/1 BIF or when code is purged. In the case with the >>> disk_log server being stuck I think we can rule out the purge, i.e., >>> if it is this bug that caused your problem another process must have >>> garbage collected the disk_log server via the garbage_collect/1 >>> BIF. Do you have any code that may have garbage collected the disk_log >>> server via the garbage_collect/1 BIF? The garbage collect may also >>> have been done explicitly in the shell. >>> >>> Regards, >>> Rickard Green, Erlang/OTP, Ericsson AB. >> >> > From gleber.p@REDACTED Wed Jan 14 11:20:15 2009 From: gleber.p@REDACTED (Gleb Peregud) Date: Wed, 14 Jan 2009 11:20:15 +0100 Subject: [erlang-questions] Questions about lib_chan and IRC Lite (other than the one had been asked before). In-Reply-To: References: Message-ID: <14f0e3620901140220p2f253b08n11b966d9992a788a@mail.gmail.com> 2009/1/14 lang qiu : > Hi all, > > Nobody replies my question about IRC Lite, so I ask it the second time > (Change the title in hoping that it may cause some attention). And I notice > that someone asked about some other questions about IRC Lite before, which > may suggest this example is tricky. > > So my here is my question, if a process sends another process several > messages in a row while in the receiving process when it processes the first > message, it does that in its own receiving loop, then all the remaining > message the first process sends goes into this loop and this may against the > purpose. > > My words may sound nonsense. So check these codes, > > In the chat_client.erl, > > try_to_connect(Parent, Host, Port, Pwd) -> > ... > Parent ! {connected, MM}, > exit(connectorFinished) > end. > > While in parent disconnected/3, > ... > receive > {connected, MM} -> > lib_chan_mm:send(MM, {login, Group, Nick}), > wait_login_response(Widget, MM); > {'EXIT', _Pid, _Reason} -> %% if we add this clause here > ... > wait_login_response/2 defines, > ... > receive > ... > Other -> > io:format("chat_client login unexpected:~p~p~n",[Other,MM]), > ... > > The result shows that wait_login_response/2 receives try_to_connect's 'EXIT' > message not disconnected/3. I further test that if try_to_connect sends more > messages after {connected, MM} , they will all be received by > wait_login_response instead of disconnected/3 even there are match patterns > in disconnected/3 (Correct me if I am wrong). But this may not be a good > idea. Maybe it is better to let disconnected/3 processes the 'EXIT' message > instead of wait_login_response/2 (because it should only deal with the login > related message). So how do we fix this problem ? Or I miss something here > ? > > Thanks, > > Qiulang > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > You can try alter the code in the following way: try_to_connect(Parent, Host, Port, Pwd) -> ... Parent ! {connected, self(), MM}, exit(connectorFinished) end. While in parent disconnected/3, ... receive {connected, Connector, MM} -> lib_chan_mm:send(MM, {login, Group, Nick}), receive {'EXIT', Connector, connectorFinished} -> ok end, wait_login_response(Widget, MM); {'EXIT', _Pid, _Reason} -> %% if we add this clause here ... wait_login_response/2 defines, ... receive ... Other -> io:format("chat_client login unexpected:~p~p~n",[Other,MM]), ... This change makes parent:disconnected/3 catch 'EXIT' message of connector at the appropriate moment. Note: I don't know what remaining code looks like, hence this is based solely on code in your email. -- Gleb Peregud http://gleber.pl/ Every minute is to be grasped. Time waits for nobody. -- Inscription on a Zen Gong From 0x6e6562@REDACTED Wed Jan 14 16:11:00 2009 From: 0x6e6562@REDACTED (Ben Hood) Date: Wed, 14 Jan 2009 15:11:00 +0000 Subject: [erlang-questions] Structuring an Eunit Suite Message-ID: <269388e30901140711q244c1becjc02713279574bf16@mail.gmail.com> Hi, I'm currently using Eunit in a very agricultural fashion and would like to use more of the Eunit infrastructure to make the tests less verbose. I have a suite of tests that each connect to a message server and execute a number of commands. I want to be able to parameterize where the connection supplied from, so that I can re-use the tests on different transports. What I've got now is a suite that looks like this: foo_test() -> test_util:foo_test(new_connection()). ...... new_connection() -> %% returns a specific connection to the server ...... and all of the real tests are in the test_util module, e.g: foo_test(Connection) -> %% assert something Ideally I would like eunit to do something like "foreach _test function in the test_util module, create a new connection and pass it as a function argument" Is this possible? Thanks for any suggestions, Ben PS The link the source is here: http://hg.rabbitmq.com/rabbitmq-erlang-client/file/437d0e4d66c8/src/network_client_test.erl http://hg.rabbitmq.com/rabbitmq-erlang-client/file/437d0e4d66c8/src/test_util.erl From qiulang@REDACTED Wed Jan 14 16:27:27 2009 From: qiulang@REDACTED (lang qiu) Date: Wed, 14 Jan 2009 23:27:27 +0800 Subject: [erlang-questions] Questions about lib_chan and IRC Lite (other than the one had been asked before). In-Reply-To: <14f0e3620901140220p2f253b08n11b966d9992a788a@mail.gmail.com> References: <14f0e3620901140220p2f253b08n11b966d9992a788a@mail.gmail.com> Message-ID: First of all, thanks for answering my question! But the solution you provided does not solve the problem completely. Because the main problem here is that if a process sends several messages in a row, then the receiving process may fail to process them correctly. Your solution can only solve the problem if the process only send *2* *messages *in a row, receive {connected, Connector, MM} -> lib_chan_mm:send(MM, {login, Group, Nick}), * receive {'EXIT', Connector, connectorFinished} -> ok end,* %% *can only take 1 more message *here even if you add more receiving match pattern, %% the remaining message still goes into wait_login_response/2 wait_login_response(Widget, MM); For example if try_to_connect/4 sends 3 messages to parent, try_to_connect(Parent, Host, Port, Pwd) -> ... Parent ! {connected, self(), MM}, Parent ! {hello, self(), MM), exit(*connectorFinished*) end. The parent still fails to process them even with your solution, disconnected(Widget, Group, Nick) -> receive {connected, Connector, MM} -> receive {hello, _ } -> io:format("hello in connected~n"); // The following clause won't work! {'EXIT', _Connector, connectorFinished} -> io:format("connect finished ~n") end, lib_chan_mm:send(MM, {login, Group, Nick}), wait_login_response(Widget, MM); Because the added receive codes can only take 1 more message, the remaining messages still goes in to wait_login_response(Widget, MM); So I still think we should make the outer receive codes process the message instead of letting one of matching section (connected here) process the remaining message. But is that possible ? Thanks! PS maybe you need to see the whole source code so I attach it here. try_to_connect(Parent, Host, Port, Pwd) -> case lib_chan:connect(Host, Port, chat, Pwd, []) of {error, _Why} -> Parent ! {status, {cannot, connect, Host, Port}}, sleep(2000), try_to_connect(Parent, Host, Port, Pwd); {ok, MM} -> lib_chan_mm:controller(MM, Parent), *Parent ! {connected, MM},* Parent ! hello, exit(connectorFinished) end. disconnected(Widget, Group, Nick) -> receive {connected, MM} -> insert_str(Widget, "connected to server\nsending data\n"), receive hello -> io:format("hello in connected~n"); {'EXIT', _Connector, connectorFinished} -> io:format("connect finished ~n") end, lib_chan_mm:send(MM, {login, Group, Nick}), wait_login_response(Widget, MM); {Widget, destroyed} -> exit(died); {status, S} -> insert_str(Widget, to_str(S)), disconnected(Widget, Group, Nick); Other -> io:format("chat_client disconnected unexpected:~p~n",[Other]), disconnected(Widget, Group, Nick) end. wait_login_response(Widget, MM) -> receive {chan, MM, ack} -> io:format("I am login~n"), active(Widget, MM); Other -> io:format("chat_client login unexpected:~p~n",[Other]), wait_login_response(Widget, MM) end. On Wed, Jan 14, 2009 at 6:20 PM, Gleb Peregud wrote: > 2009/1/14 lang qiu : > > Hi all, > > > > Nobody replies my question about IRC Lite, so I ask it the second time > > (Change the title in hoping that it may cause some attention). And I > notice > > that someone asked about some other questions about IRC Lite before, > which > > may suggest this example is tricky. > > > > So my here is my question, if a process sends another process several > > messages in a row while in the receiving process when it processes the > first > > message, it does that in its own receiving loop, then all the remaining > > message the first process sends goes into this loop and this may against > the > > purpose. > > > > My words may sound nonsense. So check these codes, > > > > In the chat_client.erl, > > > > try_to_connect(Parent, Host, Port, Pwd) -> > > ... > > Parent ! {connected, MM}, > > exit(connectorFinished) > > end. > > > > While in parent disconnected/3, > > ... > > receive > > {connected, MM} -> > > lib_chan_mm:send(MM, {login, Group, Nick}), > > wait_login_response(Widget, MM); > > {'EXIT', _Pid, _Reason} -> %% if we add this clause here > > ... > > wait_login_response/2 defines, > > ... > > receive > > ... > > Other -> > > io:format("chat_client login unexpected:~p~p~n",[Other,MM]), > > ... > > > > The result shows that wait_login_response/2 receives try_to_connect's > 'EXIT' > > message not disconnected/3. I further test that if try_to_connect sends > more > > messages after {connected, MM} , they will all be received by > > wait_login_response instead of disconnected/3 even there are match > patterns > > in disconnected/3 (Correct me if I am wrong). But this may not be a good > > idea. Maybe it is better to let disconnected/3 processes the 'EXIT' > message > > instead of wait_login_response/2 (because it should only deal with the > login > > related message). So how do we fix this problem ? Or I miss something > here > > ? > > > > Thanks, > > > > Qiulang > > > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions@REDACTED > > http://www.erlang.org/mailman/listinfo/erlang-questions > > > > > > You can try alter the code in the following way: > > try_to_connect(Parent, Host, Port, Pwd) -> > ... > Parent ! {connected, self(), MM}, > exit(connectorFinished) > end. > > While in parent disconnected/3, > ... > receive > {connected, Connector, MM} -> > lib_chan_mm:send(MM, {login, Group, Nick}), > receive {'EXIT', Connector, connectorFinished} -> ok end, > wait_login_response(Widget, MM); > {'EXIT', _Pid, _Reason} -> %% if we add this clause here > ... > wait_login_response/2 defines, > ... > receive > ... > Other -> > io:format("chat_client login unexpected:~p~p~n",[Other,MM]), > ... > > This change makes parent:disconnected/3 catch 'EXIT' message of > connector at the appropriate moment. Note: I don't know what remaining > code looks like, hence this is based solely on code in your email. > > -- > Gleb Peregud > http://gleber.pl/ > > Every minute is to be grasped. > Time waits for nobody. > -- Inscription on a Zen Gong > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: chat_client.erl Type: application/octet-stream Size: 3772 bytes Desc: not available URL: From 0x6e6562@REDACTED Wed Jan 14 17:03:17 2009 From: 0x6e6562@REDACTED (Ben Hood) Date: Wed, 14 Jan 2009 16:03:17 +0000 Subject: [erlang-questions] gen_server mailbox scans Message-ID: <269388e30901140803t7e86ff2cp4fdf32d1499a12bd@mail.gmail.com> Hi, The issue of excessive mailbox scanning during the bottom half of a gen_server call has been brought up at various stages on this list. The issue has become of some concern to us, so we have patched the gen_server implementation from R11B5 to drain the mailbox in the loop. It seems to do the job but I just wanted to get some feedback from more knowledgable people before this functionality is merged into our main source tree. The patched version is available here: http://hg.rabbitmq.com/rabbitmq-server/file/06b16fb29a1c/src/gen_server2.erl Any remarks or help is appreciated, Ben From klacke@REDACTED Wed Jan 14 20:44:34 2009 From: klacke@REDACTED (=?ISO-8859-1?Q?Claes_Wikstr=F6m?=) Date: Wed, 14 Jan 2009 20:44:34 +0100 Subject: [erlang-questions] inets and ssl start/1 stop/1 In-Reply-To: References: Message-ID: <496E40A2.5080308@hyber.org> Edward Stow wrote: > Hi > > Within a yaws application I am start/1 ing inets and ssl to send a > post request to an external server. > > Should I be stopping these services when my request returns. > > I assume that for each yaws request a new process is started and that > the inets ssl services are stopped when the process exits. > Don't stop anything. /klacke From ulf@REDACTED Thu Jan 15 04:42:26 2009 From: ulf@REDACTED (Ulf Wiger) Date: Thu, 15 Jan 2009 04:42:26 +0100 Subject: [erlang-questions] mnesia: composite keys? In-Reply-To: References: <200901092245.09386.peter@sabaini.at> <71f43ded-7365-4e63-891c-17c1baccf775@y1g2000pra.googlegroups.com> Message-ID: <8209f740901141942k1173bc6m4dabb4d6a7b94da5@mail.gmail.com> Erlhive (erlhive.sf.net) actually supports composite keys through index callbacks. It may have other characteristics that don't suit you, since it's not a generic database solution. BR, Ulf W 2009/1/14, Viktor Sovietov : > > > On Jan 10, 9:10 pm, Paul Mineiro wrote: >> On Fri, 9 Jan 2009, Viktor Sovietov wrote: >> > If you use ordered_set tables that tuple keys are useful, because you >> > can organize hierarchies inside one table. In other hand, you can't >> > save such tables on disk, so... Anyway, Erlang isn't MUMPS, so you >> > simply have not any mechanism to operate with complex keys. >> >> I have a nonstandard extension to mnesia that allows one to define new >> table types, plus a disk-based ordered set table so defined. >> >> http://code.google.com/p/mnesiaex/ >> >> Also we use tuples as keys extensively in our application. > > > I found this useful as well, I use it with tcerl, but again, there > still is no mechanism to navigate index trees efficiently : > ( Unfortunately. > > Sincerely, > > --Victor > >> >> -- p >> >> >> >> >> >> >> >> > Sincerely, >> >> > --Victor >> >> > On Jan 9, 11:45 pm, Peter Sabaini wrote: >> > > Hello list, >> >> > > I've read[1] that mnesia doesn't support composite keys. It seems I >> > > can use >> > > keys made up of tuples though: >> >> > > (emacs@REDACTED)11> mnesia:create_table(test, [{attributes, [id, data]}]). >> > > {atomic,ok} >> > > (emacs@REDACTED)19> Ins = fun() -> mnesia:write({test, {a_key, 0}, >> > > "asdfasdf"}) >> > > end. >> > > #Fun >> > > (emacs@REDACTED)20> mnesia:transaction(Ins). >> > > {atomic,ok} >> > > (emacs@REDACTED)21> R = fun() -> mnesia:read(test, {a_key, 0}) end. >> > > #Fun >> > > (emacs@REDACTED)22> mnesia:transaction(R). >> > > {atomic,[{test,{a_key,0},"asdfasdf"}]} >> >> > > Is tuples as keys common practice or A Really Bad Idea(tm)? >> >> > > thx, >> > > peter. >> >> > > [1]http://www.erlang.org/pipermail/erlang-questions/2008-February/032903... >> >> > > signature.asc >> > > < 1KViewDownload >> >> > > _______________________________________________ >> > > erlang-questions mailing list >> > > erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions >> > _______________________________________________ >> > erlang-questions mailing list >> > erlang-questi...@REDACTED >> >http://www.erlang.org/mailman/listinfo/erlang-questions >> >> In an artificial world, only extremists live naturally. >> >> -- Paul Graham >> _______________________________________________ >> erlang-questions mailing list >> erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From joe@REDACTED Thu Jan 15 05:03:48 2009 From: joe@REDACTED (Joe Williams) Date: Wed, 14 Jan 2009 20:03:48 -0800 Subject: [erlang-questions] Seattle Erlounge, Next Week Message-ID: <496EB5A4.7040603@joetify.com> For anyone in or around the Seattle metro area we are starting an Erlounge up and the first meeting is Wednesday January 21st, 7pm at the Garage. You can find more information at http://erloungeseattle.org/ Hope to see you there. -Joe -- Name: Joseph A. Williams Email: joe@REDACTED Blog: http://www.joeandmotorboat.com/ From chandrashekhar.mullaparthi@REDACTED Thu Jan 15 05:58:44 2009 From: chandrashekhar.mullaparthi@REDACTED (Chandru) Date: Thu, 15 Jan 2009 04:58:44 +0000 Subject: [erlang-questions] gen_server mailbox scans In-Reply-To: <269388e30901140803t7e86ff2cp4fdf32d1499a12bd@mail.gmail.com> References: <269388e30901140803t7e86ff2cp4fdf32d1499a12bd@mail.gmail.com> Message-ID: 2009/1/14 Ben Hood <0x6e6562@REDACTED> > Hi, > > The issue of excessive mailbox scanning during the bottom half of a > gen_server call has been brought up at various stages on this list. > > The issue has become of some concern to us, so we have patched the > gen_server implementation from R11B5 to drain the mailbox in the loop. > > It seems to do the job but I just wanted to get some feedback from > more knowledgable people before this functionality is merged into our > main source tree. > > The patched version is available here: > > > http://hg.rabbitmq.com/rabbitmq-server/file/06b16fb29a1c/src/gen_server2.erl > > Any remarks or help is appreciated, > >From a callback point of view, the changes are probably transparent, but: * process_info(Pid, message_queue_len) will probably lie now because the mailbox has been drained into an internal queue. If your message queue is indeed building up in a message storm, diagnosing the problem will become more difficult. * And if you did a sys:get_status(Pid) on the gen_server, you will copying the entire message queue just to view it... * Crash reports will be MUCH bigger. cheers Chandru -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick@REDACTED Thu Jan 15 08:14:04 2009 From: nick@REDACTED (Nick Gerakines) Date: Wed, 14 Jan 2009 23:14:04 -0800 Subject: [erlang-questions] SF Erlounge, January 15th at EA/Rupture In-Reply-To: References: Message-ID: Just a reminder, tomorrow night (Thursday night) is SF Erlounge. Please see the parent thread for the time and place. Email or call me if you have any questions, comments or if you get lost. For those walking from Caltrain, go 3 blocks up king street and 3 blocks toward market. It's a nice 5-10 minute walk. There is parking in and around the area but most parking garages aren't open too late (the one on 2nd just past Harrison closes at 7pm) and probably aren't cheap. Our office is on the third floor in suite 350. I'll make regular trips to and from the lobby before it starts but feel free to come up. It's OK if you plan on coming early, but please give me a heads up. If you've got an dinner/bar suggestions then send them forth. # Nick Gerakines On Fri, Dec 12, 2008 at 12:04 PM, Nick Gerakines wrote: > Last week I announced that Rupture/EA is interested in hosting SF > Erlounge in January. The response was good and I'd like to set the > date to January 15th at 7:00 pm. This event is open to the public with > drinks and light snacks provided. This is a great chance to meet other > Erlang hackers and spectators and present your ideas. Rupture/EA is > happy to host this until 8:00 pm where we will probably migrate to get > drinks and dinner afterward. > > We are located at Harrison St & 2nd St, just a few blocks north of > South Park, south of Market St. Our office is a comfortable 10 minute > walk from the Caltrain station for anyone in the south-bay who would > like to attend. > > 400 2nd Street, Suite 350 > San Francisco, CA 94107 > > Please contact me if you have any questions or concerns. My mobile is > +1 (415) 963-1165. > > # Nick Gerakines > From aconbere@REDACTED Thu Jan 15 09:04:16 2009 From: aconbere@REDACTED (anders conbere) Date: Thu, 15 Jan 2009 00:04:16 -0800 Subject: [erlang-questions] Seattle Erlounge, Next Week In-Reply-To: <496EB5A4.7040603@joetify.com> References: <496EB5A4.7040603@joetify.com> Message-ID: <8ca3fbe80901150004y201c2f6aw32fcbdf7e671660e@mail.gmail.com> I'm in, don't see why I wouldn't be able to make it. ~ Anders On Wed, Jan 14, 2009 at 8:03 PM, Joe Williams wrote: > > For anyone in or around the Seattle metro area we are starting an > Erlounge up and the first meeting is Wednesday January 21st, 7pm at the > Garage. > You can find more information at http://erloungeseattle.org/ Hope to see > you there. > > -Joe > > -- > Name: Joseph A. Williams > Email: joe@REDACTED > Blog: http://www.joeandmotorboat.com/ > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From 0x6e6562@REDACTED Thu Jan 15 10:08:51 2009 From: 0x6e6562@REDACTED (Ben Hood) Date: Thu, 15 Jan 2009 09:08:51 +0000 Subject: [erlang-questions] gen_server mailbox scans In-Reply-To: References: <269388e30901140803t7e86ff2cp4fdf32d1499a12bd@mail.gmail.com> Message-ID: <269388e30901150108g7280fa02jb9522a5214132949@mail.gmail.com> Chandru, On Thu, Jan 15, 2009 at 4:58 AM, Chandru wrote: > 2009/1/14 Ben Hood <0x6e6562@REDACTED> > * process_info(Pid, message_queue_len) will probably lie now because the > mailbox has been drained into an internal queue. If your message queue is > indeed building up in a message storm, diagnosing the problem will become > more difficult. True - we would have to implement the queue length function in the module itself. > * And if you did a sys:get_status(Pid) on the gen_server, you will copying > the entire message queue just to view it... > * Crash reports will be MUCH bigger. Sure - transferring the mailbox to process memory does make reading the state of the process much more heavyweight. So it would be a good idea to try to avoid this standard calls. However, I still think the benefit of avoiding the scan outweighs these disadvantages in our particular use case. Previously, we used an intermediate process as a buffering proxy to solve this problem, but modifying gen_server seems less intrusive from an API perspective, and it means that we have one less moving part. Ideally it would nice to have an index on the mailbox to avoid the linear scan. Thanks for your thoughts on this issue, Ben From steven.charles.davis@REDACTED Thu Jan 15 10:13:20 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Thu, 15 Jan 2009 01:13:20 -0800 (PST) Subject: [erlang-questions] UBF Message-ID: <82e8f979-bdf6-46e1-96db-cca3513ee438@o40g2000prn.googlegroups.com> All, Having just had a discussion with a friend about client server protocol design, I remembered to reference back to Joe's proposal for UBF. I re-read the pdf paper and the power of "programming by contract" really struck home with me on re-read in a *big way*. Despite the fact that UBF seems to have been rather inactive development-wise for 5 years, it really does look to me like it's the right solution for us (a large amount of small messages, various client platforms/technologies). So I'm wondering... * Does anybody have experience of using UBF? * Was this experience of using UBF 100% positive? * Can anyone think of any downside to using UBF over XML/WSDL (apart from the obvious cultural ones)? thanks! /s From zerthurd@REDACTED Thu Jan 15 10:43:28 2009 From: zerthurd@REDACTED (Maxim Treskin) Date: Thu, 15 Jan 2009 15:43:28 +0600 Subject: [erlang-questions] ABNF compiler for Erlang Message-ID: Hello Is there any tool that compiles ABNF into Erlang code of parser? I have found some mentions of erlang abnfc in google, but where is its sources? -- Maxim Treskin -------------- next part -------------- An HTML attachment was scrubbed... URL: From erik.reitsma@REDACTED Thu Jan 15 11:08:04 2009 From: erik.reitsma@REDACTED (Erik Reitsma) Date: Thu, 15 Jan 2009 11:08:04 +0100 Subject: [erlang-questions] UBF In-Reply-To: <82e8f979-bdf6-46e1-96db-cca3513ee438@o40g2000prn.googlegroups.com> References: <82e8f979-bdf6-46e1-96db-cca3513ee438@o40g2000prn.googlegroups.com> Message-ID: <110BA8ACEE682C479D0B008B6BE4AEB107C58398@esealmw107.eemea.ericsson.se> Hi Steve & others, | Despite the fact that UBF seems to have been rather inactive | development-wise for 5 years, it really does look to me like | it's the right solution for us (a large amount of small | messages, various client platforms/technologies). I think it is. | So I'm wondering... | * Does anybody have experience of using UBF? We use it in our (research) department as the prefered protocol/encoding for communicating with applications on mobile phones (J2ME). The server is either Erlang or Java. We do not use the contract part a lot, since we do not have Java support for it. We especially like the simple encoding rules and that we have implementations for Erlang, J2SE and J2ME. It is also very nice to send over binaries with UBF, since they do not need to be base64 or otherwise encoded. | * Was this experience of using UBF 100% positive? I cannot remember any negative experiences. Since the source is available, we were able to modify some stuff to our liking. E.g. we decoupled the socket setup from the server/client role: the socket may be set up by the UBF server. We needed to retrieve information from the mobile, so it should be UBF server. On the other hand, we cannot set up a TCP connection from the mobile, so we the mobile (i.e. UBF server) sets up the connection. We break some rules this way, but it works. | * Can anyone think of any downside to using UBF over XML/WSDL | (apart from the obvious cultural ones)? There is no code generation for UBF. You cannot generate UBF specs from code either. With UBF in Java you have to unpack the messages by hand, you do not have a generated class per message. Now that I write this, I guess it would be possible to generate code from the contract, only nobody has done that as far as I know. With UBF you have to encode floats into some structure yourself, since UBF does not support floats. Regards, *Erik. From adam@REDACTED Thu Jan 15 12:23:04 2009 From: adam@REDACTED (Adam Lindberg) Date: Thu, 15 Jan 2009 11:23:04 +0000 (GMT) Subject: [erlang-questions] Structuring an Eunit Suite In-Reply-To: <3989383.41001232018171460.JavaMail.root@zimbra> Message-ID: <22239802.41021232018584117.JavaMail.root@zimbra> Hi Ben, Let's see if I understood you correctly... The example in the EUnit documentation: fib_test_() -> [?_assert(fib(0) == 1), ?_assert(fib(1) == 1), ?_assert(fib(2) == 2), ?_assert(fib(3) == 3), ?_assert(fib(4) == 5), ?_assert(fib(5) == 8), ?_assertException(error, function_clause, fib(-1)), ?_assert(fib(31) == 2178309) ]. Could be written as (without the exception assert): fib_test_() -> lists:map(fun assert_fib/1, [{0,1}, {1,1}, {2,2}, {3,3}, {4,5}, {5,8}, {31,2178309}]). assert_fib({Value, Expected) -> ?_assert(fib(Value) == Expected). If foo_test(Connection) returns a test fun, e.g. ?_assert(...) or similar, and you want to run this test for many different types of connections you could generate a list of such tests: foo_test_() -> % Note the trailing underscore [test_util:foo_test(new_connection()), test_util:foo_test(some_other_connection())]. Note that the function name ends in underscore. This means that the function is not a test itself, it returns a test (which will be executed at a later time). Even nicer could be like this: foo_test_() -> lists:map(fun test_util:foo_test/1, [new_connection(), some_other_connection()]). Does this seem to be what you want? Cheers, Adam ----- "Ben Hood" <0x6e6562@REDACTED> wrote: > Hi, > > I'm currently using Eunit in a very agricultural fashion and would > like to use more of the Eunit infrastructure to make the tests less > verbose. > > I have a suite of tests that each connect to a message server and > execute a number of commands. > > I want to be able to parameterize where the connection supplied from, > so that I can re-use the tests on different transports. > > What I've got now is a suite that looks like this: > > foo_test() -> > test_util:foo_test(new_connection()). > ...... > > new_connection() -> > %% returns a specific connection to the server > > ...... > > and all of the real tests are in the test_util module, e.g: > > foo_test(Connection) -> > %% assert something > > Ideally I would like eunit to do something like > > "foreach _test function in the test_util module, create a new > connection and pass it as a function argument" > > Is this possible? > > Thanks for any suggestions, > > Ben > > PS The link the source is here: > > http://hg.rabbitmq.com/rabbitmq-erlang-client/file/437d0e4d66c8/src/network_client_test.erl > http://hg.rabbitmq.com/rabbitmq-erlang-client/file/437d0e4d66c8/src/test_util.erl > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From 0x6e6562@REDACTED Thu Jan 15 12:32:55 2009 From: 0x6e6562@REDACTED (Ben Hood) Date: Thu, 15 Jan 2009 11:32:55 +0000 Subject: [erlang-questions] Structuring an Eunit Suite In-Reply-To: <22239802.41021232018584117.JavaMail.root@zimbra> References: <3989383.41001232018171460.JavaMail.root@zimbra> <22239802.41021232018584117.JavaMail.root@zimbra> Message-ID: <269388e30901150332s62c36f3dqc5a51386682cdeef@mail.gmail.com> Adam, On Thu, Jan 15, 2009 at 11:23 AM, Adam Lindberg wrote: > foo_test_() -> > lists:map(fun test_util:foo_test/1, [new_connection(), some_other_connection()]). > > Does this seem to be what you want? No, it's the other way around. The test_util module has n exported test functions, so I'd like to be able to run every function and pass in the specific connection every time, e.g. test_util:foo_test(new_connection()), test_util:bar_test(new_connection()), test_util:baz_test(new_connection()), ...... and so on for each test in the test_util module. Ben From chandrashekhar.mullaparthi@REDACTED Thu Jan 15 12:34:05 2009 From: chandrashekhar.mullaparthi@REDACTED (Chandru) Date: Thu, 15 Jan 2009 11:34:05 +0000 Subject: [erlang-questions] gen_server mailbox scans In-Reply-To: <269388e30901150108g7280fa02jb9522a5214132949@mail.gmail.com> References: <269388e30901140803t7e86ff2cp4fdf32d1499a12bd@mail.gmail.com> <269388e30901150108g7280fa02jb9522a5214132949@mail.gmail.com> Message-ID: Hi Ben, 2009/1/15 Ben Hood <0x6e6562@REDACTED> > > * And if you did a sys:get_status(Pid) on the gen_server, you will > copying > > the entire message queue just to view it... > > * Crash reports will be MUCH bigger. > > Sure - transferring the mailbox to process memory does make reading > the state of the process much more heavyweight. > > So it would be a good idea to try to avoid this standard calls. > > However, I still think the benefit of avoiding the scan outweighs > these disadvantages in our particular use case. Previously, we used an > intermediate process as a buffering proxy to solve this problem, but > modifying gen_server seems less intrusive from an API perspective, and > it means that we have one less moving part. > > I agree. If you are brave enough to have your own version of gen_server, may be you can have your message queue in an ordered_set ets table, instead of a queue. That way, you still keep the message queue in a separate area, and get all the power of ets. Will work better when you have large message queues to deal with. Is there no way you can throttle your clients before they send a message to the server process? That would make your life a lot easier. cheers Chandru -------------- next part -------------- An HTML attachment was scrubbed... URL: From vychodil.hynek@REDACTED Thu Jan 15 12:34:27 2009 From: vychodil.hynek@REDACTED (Hynek Vychodil) Date: Thu, 15 Jan 2009 12:34:27 +0100 Subject: [erlang-questions] UBF In-Reply-To: <82e8f979-bdf6-46e1-96db-cca3513ee438@o40g2000prn.googlegroups.com> References: <82e8f979-bdf6-46e1-96db-cca3513ee438@o40g2000prn.googlegroups.com> Message-ID: <20090115113427.D781524063@relay.gooddata.com> I have written UBF inspired type notation (schema) for REST API specification in our project. This schema was initially used for documentation and more later for type checking. Due practical use I found some drawback. UBF is not extensible in backward compatibility manner as XML or Protocol buffer (Google) is. UBF type system is not expressive as real project can need. Would be usable if types can by described in functional manner: metaIn() = {meta, name(), author()}; metaOut() = {meta, name(), author(), timestamp()}; metric(X) = {metric, X, content()}; metricIn() = metric(metaIn()); metricOut() = metric(mataOut()); Another successive type system enhancement is ability to add variant to existing list or tuple or dictionary (see above). UBF is lack of dictionary construct (as Erlang) and my attempt to add this to type system is not as nice as original Anyway I found UBF as very inspirative piece of work. UBF is far simplier than XML or ASN.1 or other equivalents. Contracts would be very usefull in big projects. (Unfortunately its using is hard to put trough management.) UBF coding and decoding is very nice and simple. On Thu, Jan 15, 2009 at 10:13 AM, Steve Davis < steven.charles.davis@REDACTED> wrote: > All, > > Having just had a discussion with a friend about client server > protocol design, I remembered to reference back to Joe's proposal for > UBF. I re-read the pdf paper and the power of "programming by > contract" really struck home with me on re-read in a *big way*. > Despite the fact that UBF seems to have been rather inactive > development-wise for 5 years, it really does look to me like it's the > right solution for us (a large amount of small messages, various > client platforms/technologies). > > So I'm wondering... > * Does anybody have experience of using UBF? > * Was this experience of using UBF 100% positive? > * Can anyone think of any downside to using UBF over XML/WSDL (apart > from the obvious cultural ones)? > > thanks! > /s > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero! Try Good Data now for free: www.gooddata.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From tony@REDACTED Thu Jan 15 12:00:49 2009 From: tony@REDACTED (Tony Rogvall) Date: Thu, 15 Jan 2009 12:00:49 +0100 Subject: [erlang-questions] spec( status Message-ID: <019D1530-7BB4-4E7F-A5B3-FFEAC9FD000D@rogvall.se> Hi list! What is the current status on how to use the function type specs? I have seen several versions in the stdlib code! from string.erl: -spec sub_string(string(), pos_integer(), pos_integer()) -> string(). gb_trees.erl (with comment) %%-spec(empty/0 :: () -> gb_tree()). lists.erl: -spec(append/2 :: ([T],[T]) -> [T]). What is the problem here???? What should I use to be a modern Erlang programmer? Of course I would like my type spec work to pay. Are there any edoc/ doxygen stuff that take any of the formats? What/Which formats do dializer use? I would expect that at least the stdlib to be normalized to one notation, why not spend and hour or two to fix it? Thanks /Tony From adam@REDACTED Thu Jan 15 13:12:59 2009 From: adam@REDACTED (Adam Lindberg) Date: Thu, 15 Jan 2009 12:12:59 +0000 (GMT) Subject: [erlang-questions] Structuring an Eunit Suite In-Reply-To: <32351262.41231232021414557.JavaMail.root@zimbra> Message-ID: <23982845.41251232021579540.JavaMail.root@zimbra> So maybe: connection_test_() -> Connections = [new_connection, some_other_connection], Tests = [foo_test, bar_test, baz_test], [make_test(C, T) || C <- Connections, T <- Tests]. make_test(Connection, Test) -> test_util:Test(Connection()). This would give the permutation: 1> [make_test(C, T) || C <- Connections, T <- Tests]. [{new_connection,foo_test}, {new_connection,bar_test}, {new_connection,baz_test}, {some_other_connection,foo_test}, {some_other_connection,bar_test}, {some_other_connection,baz_test}] Cheers, Adam ----- "Ben Hood" <0x6e6562@REDACTED> wrote: > Adam, > > On Thu, Jan 15, 2009 at 11:23 AM, Adam Lindberg > wrote: > > foo_test_() -> > > lists:map(fun test_util:foo_test/1, [new_connection(), > some_other_connection()]). > > > > Does this seem to be what you want? > > No, it's the other way around. > > The test_util module has n exported test functions, so I'd like to be > able to run every function and pass in the specific connection every > time, e.g. > > test_util:foo_test(new_connection()), > test_util:bar_test(new_connection()), > test_util:baz_test(new_connection()), > > ...... and so on for each test in the test_util module. > > Ben From kostis@REDACTED Thu Jan 15 13:21:59 2009 From: kostis@REDACTED (Kostis Sagonas) Date: Thu, 15 Jan 2009 14:21:59 +0200 Subject: [erlang-questions] spec( status In-Reply-To: <019D1530-7BB4-4E7F-A5B3-FFEAC9FD000D@rogvall.se> References: <019D1530-7BB4-4E7F-A5B3-FFEAC9FD000D@rogvall.se> Message-ID: <496F2A67.3070707@cs.ntua.gr> Tony Rogvall wrote: > Hi list! > > What is the current status on how to use the function type specs? > > I have seen several versions in the stdlib code! > > from string.erl: > > -spec sub_string(string(), pos_integer(), pos_integer()) -> string(). > > gb_trees.erl (with comment) > > %%-spec(empty/0 :: () -> gb_tree()). > > lists.erl: > > -spec(append/2 :: ([T],[T]) -> [T]). > > What is the problem here???? What should I use to be a modern Erlang > programmer? There is no problem. It's just software evolution. To be a modern Erlang programmer you need to use the first one (the one from string). The second one is just a comment (no spec). The third is just something that has not been cleaned up at the time when R12B-5 was released. Now it has. > Of course I would like my type spec work to pay. Are there any edoc/ > doxygen stuff that take any of the formats? Edoc will be able to take the 1st one into account. This has not happened yet, but it will. > What/Which formats do dializer use? Currently both the first and the third (for backwards compatibility). As I wrote, the second is a comment. > I would expect that at least the stdlib to be normalized to one > notation, why not spend and hour or two to fix it? Believe me it takes way more than an hour or two, but it has been fixed in the pre-release of R13. Kostis From steven.charles.davis@REDACTED Thu Jan 15 13:35:13 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Thu, 15 Jan 2009 04:35:13 -0800 (PST) Subject: [erlang-questions] UBF In-Reply-To: <20090115113427.D781524063@relay.gooddata.com> References: <82e8f979-bdf6-46e1-96db-cca3513ee438@o40g2000prn.googlegroups.com> <20090115113427.D781524063@relay.gooddata.com> Message-ID: <75db213a-60ef-421c-837e-ef4dc31acfc1@e1g2000pra.googlegroups.com> Thanks both for your input :) On Jan 15, 5:34?am, Hynek Vychodil wrote: > UBF type system is not expressive as real project can need. Would be usable > if types can by described in functional manner: > ? ? ?metaIn() = {meta, name(), author()}; > ? ? ?metaOut() = {meta, name(), author(), timestamp()}; > ? ? ?metric(X) = {metric, X, content()}; > ? ? ?metricIn() = metric(metaIn()); > ? ? ?metricOut() = metric(mataOut()); Hynek - I'm probably wrong(?) but can't that example be expressed legally as: metaIn() = {meta, name(), author()}; metaOut() = {meta, name(), author(), timestamp()}; metric() = {metric, metaIn(), content()} | {metric, metaOut(), content ()}. Thanks again all for the feedback - I"m committing to prototyping using UBF at the very least :) /s From steven.charles.davis@REDACTED Thu Jan 15 13:54:02 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Thu, 15 Jan 2009 04:54:02 -0800 (PST) Subject: [erlang-questions] UBF In-Reply-To: <75db213a-60ef-421c-837e-ef4dc31acfc1@e1g2000pra.googlegroups.com> References: <82e8f979-bdf6-46e1-96db-cca3513ee438@o40g2000prn.googlegroups.com> <20090115113427.D781524063@relay.gooddata.com> <75db213a-60ef-421c-837e-ef4dc31acfc1@e1g2000pra.googlegroups.com> Message-ID: <8534fd0e-c790-4560-8e2d-05aeec827472@r15g2000prd.googlegroups.com> I'm also considering using UBF contracts to test validity of clients that talk the existing (and huge) protocol but in a proprietary binary format. So I'm thinking that the server should be proxied to those clients, and the underlying binary format generated by those clients transformed at the proxy to UBF (the new server's "native" wire protocol) so that the contract checking can be done in a uniform way. I assume that's a valid way forward? /s From vychodil.hynek@REDACTED Thu Jan 15 14:42:15 2009 From: vychodil.hynek@REDACTED (Hynek Vychodil) Date: Thu, 15 Jan 2009 14:42:15 +0100 Subject: [erlang-questions] UBF In-Reply-To: <75db213a-60ef-421c-837e-ef4dc31acfc1@e1g2000pra.googlegroups.com> References: <82e8f979-bdf6-46e1-96db-cca3513ee438@o40g2000prn.googlegroups.com> <20090115113427.D781524063@relay.gooddata.com> <75db213a-60ef-421c-837e-ef4dc31acfc1@e1g2000pra.googlegroups.com> Message-ID: <20090115134216.4317F24063@relay.gooddata.com> It's good enough to enable to pass both metricIn() and metricOut() in some API, but case is enable only metricIn() in one resource and metricOut() in an other one. Not both togheter. Bigger issue comes when between metric() and meta() are many levels of structures instead this one as in example a worse this can happen many times in huge API definition. Solution is separate changing parts (as timestamp()) from common ones but structures become less fancy and consistent. One can end up with XML in UBF description: tag_name() = string() attribute_name() = string() attrribute_value() = string() xml() = {tag, tag_name(), [{attribute_name(), attribute_value()}], [xml()|string()]} which nicely showes how can be made up flexible data in ugly way. On Thu, Jan 15, 2009 at 1:35 PM, Steve Davis wrote: > Thanks both for your input :) > > > On Jan 15, 5:34 am, Hynek Vychodil wrote: > > UBF type system is not expressive as real project can need. Would be > usable > > if types can by described in functional manner: > > metaIn() = {meta, name(), author()}; > > metaOut() = {meta, name(), author(), timestamp()}; > > metric(X) = {metric, X, content()}; > > metricIn() = metric(metaIn()); > > metricOut() = metric(mataOut()); > > Hynek - I'm probably wrong(?) but can't that example be expressed > legally as: > > metaIn() = {meta, name(), author()}; > metaOut() = {meta, name(), author(), timestamp()}; > metric() = {metric, metaIn(), content()} | {metric, metaOut(), content > ()}. > > > Thanks again all for the feedback - I"m committing to prototyping > using UBF at the very least :) > /s > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero! Try Good Data now for free: www.gooddata.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From anders.nygren@REDACTED Thu Jan 15 16:16:43 2009 From: anders.nygren@REDACTED (Anders Nygren) Date: Thu, 15 Jan 2009 09:16:43 -0600 Subject: [erlang-questions] ABNF compiler for Erlang In-Reply-To: References: Message-ID: 2009/1/15 Maxim Treskin : > Hello > > Is there any tool that compiles ABNF into Erlang code of parser? > I have found some mentions of erlang abnfc in google, but where is its > sources? > Yes, I have made an ABNF parser generator for Erlang. I am planning on releasing it but have not had time yet. I hope I will be able to do it this weekend. /Anders From erlang@REDACTED Thu Jan 15 17:37:47 2009 From: erlang@REDACTED (Dominic Williams) Date: Thu, 15 Jan 2009 11:37:47 -0500 (EST) Subject: [erlang-questions] Paris ErlLounge/User Group Message-ID: <568b567da20afa742fa9a5e8c9e68d2c.squirrel@www.geekisp.com> Hello, The Paris ErlLounge is now being held monthly, and there is a trapexit Wiki page for the group to communicate and coordinate: http://www.trapexit.org/ErlangParis The next meeting is this coming Monday 19th January. Best regards, Dominic Williams http://dominicwilliams.net ---- From fess-erlang@REDACTED Thu Jan 15 18:02:48 2009 From: fess-erlang@REDACTED (fess) Date: Thu, 15 Jan 2009 09:02:48 -0800 Subject: [erlang-questions] inets and ssl start/1 stop/1 In-Reply-To: <496E40A2.5080308@hyber.org> References: <496E40A2.5080308@hyber.org> Message-ID: <7D41A21D-1973-48FF-93F3-AE266A75D97D@fess.org> On Jan 14, 2009, at 11:44 AM, Claes Wikstr?m wrote: > Edward Stow wrote: >> Hi >> >> Within a yaws application I am start/1 ing inets and ssl to send a >> post request to an external server. >> >> Should I be stopping these services when my request returns. >> >> I assume that for each yaws request a new process is started and that >> the inets ssl services are stopped when the process exits. >> > > Don't stop anything. > > /klacke inets and ssl are other erlang applications like yaws. [ ie, when you start them you are starting other processes in the supervision tree of the application controller and not likely to be linked to your current process which is handling the request, and not likely to stop until told to. ] Since you're using inets and ssl you generally you want to get them started when you start all your applications [ not on every web request. ] Yaws can help here. Yaws is also a container for starting up erlang itself and the relevant erlang applications, [ assuming you're not using embedded mode. ] to this end it has a mechanism in it's config file called runmod where you can list inets and ssl. And then yaws the container will start erlang, and start your runmods, and start everything that it needs running. http://yaws.hyber.org/yman.yaws?page=yaws.conf 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. I hope that clarifies things. [ and I hope I said that all right. :D ] --fess From anupam.kapoor@REDACTED Thu Jan 15 20:10:41 2009 From: anupam.kapoor@REDACTED (Anupam Kapoor) Date: Fri, 16 Jan 2009 00:40:41 +0530 Subject: [erlang-questions] variable argument preprocessor macros In-Reply-To: <3dbc6d1c0901131840x57fbb638m995ff1d244181927@mail.gmail.com> References: <3dbc6d1c0901131840x57fbb638m995ff1d244181927@mail.gmail.com> Message-ID: On Wed, Jan 14, 2009 at 8:10 AM, Robert Virding wrote: > No. The only thing you can do is have is to have: > > SIMPLE_SERVER_DEBUG_2("mesg-1", "mesg-2") > and > SIMPLE_SERVER_DEUBG_4("mesg-1", "mesg-2", mesg-3, mesg-4) > > Which is generally not a problem for you. well, i have been using exactly the aforementioned thing currently. however, having a bunch of identical (functionality wise) macros, with different names, didn't seem very nice... > An alternative would be to use LFE which has proper lisp and scheme macros. > If you like writing in lisp. :-) i have been playing around with scheme a bit, but for now i will pass :o) thank you anupam -- In the beginning was the lambda, and the lambda was with Emacs, and Emacs was the lambda. From kdronnqvist@REDACTED Thu Jan 15 20:44:14 2009 From: kdronnqvist@REDACTED (=?ISO-8859-1?Q?Daniel_R=F6nnqvist?=) Date: Thu, 15 Jan 2009 20:44:14 +0100 Subject: [erlang-questions] Runtime update of inetrc configuration Message-ID: <65691fa00901151144s231ac3c5mf8b80648539a8bd1@mail.gmail.com> Hello, I'm wondering if it's possible to update the kernel inetrc configuration at runtime? What I want to do is to add more host aliases without restarting Erlang. BR, Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrad-direct-erlang@REDACTED Thu Jan 15 23:40:01 2009 From: mrad-direct-erlang@REDACTED (Michael Radford) Date: Thu, 15 Jan 2009 14:40:01 -0800 Subject: [erlang-questions] BIFs and dialyzer 1.8.3 Message-ID: <20090115224001.GA31806@herbie> I'm in the process of upgrading to R12, and I'm trying to build a default dialyzer PLT, equivalent to the dialyzer_init_plt that used to ship with OTP. When I run this command (using R12B-5, dialyzer 1.8.3): dialyzer --plt dialyzer_init_plt --build_plt \ -r /usr/lib/erlang/lib/stdlib-*/ebin \ -r /usr/lib/erlang/lib/kernel-*/ebin \ -r /usr/lib/erlang/lib/mnesia-*/ebin I get the following warnings: re.erl:41: Call to missing or unexported function unicode:characters_to_binary/2 re.erl:134: Call to missing or unexported function unicode:characters_to_list/2 re.erl:200: Call to missing or unexported function re:compile/2 re.erl:226: Call to missing or unexported function unicode:characters_to_binary/2 re.erl:245: Call to missing or unexported function unicode:characters_to_list/2 re.erl:505: Call to missing or unexported function unicode:characters_to_list/2 re.erl:545: Call to missing or unexported function unicode:characters_to_binary/2 However, those functions do all exist, as BIFs: 1> erlang:is_builtin(re,compile,2). true 2> erlang:is_builtin(unicode,characters_to_binary,2). true 3> erlang:is_builtin(unicode,characters_to_list,2). true Does anyone know what might be going on here? (The R12 installation is the only erlang on the box, so it's not that I'm running the wrong dialyzer version or anything like that. I verified that the dialyzer and shell invocations shown above are both running the same beam executable.) Thanks, Mike From tony@REDACTED Thu Jan 15 22:57:34 2009 From: tony@REDACTED (Tony Rogvall) Date: Thu, 15 Jan 2009 22:57:34 +0100 Subject: [erlang-questions] file documentation bug Message-ID: <5AE0C655-DCDD-4239-AF9F-EDABF9457BCD@rogvall.se> Hi. I found a small bug in the documentation of file:open/2. It says binary This option can only be used if the raw option is specified as well. When specified, read operations on the file using the read/2 function will return binaries rather than lists. However the binary option may be used even without the raw option. /Tony From kostis@REDACTED Fri Jan 16 00:19:24 2009 From: kostis@REDACTED (Kostis Sagonas) Date: Fri, 16 Jan 2009 01:19:24 +0200 Subject: [erlang-questions] BIFs and dialyzer 1.8.3 In-Reply-To: <20090115224001.GA31806@herbie> References: <20090115224001.GA31806@herbie> Message-ID: <496FC47C.10205@cs.ntua.gr> Michael Radford wrote: > I'm in the process of upgrading to R12, and I'm trying to build a > default dialyzer PLT, equivalent to the dialyzer_init_plt that used to > ship with OTP. > ... SNIP > Does anyone know what might be going on here? This is nothing to worry about. Things should be working fine despite these warnings. Kostis From ad.sergey@REDACTED Fri Jan 16 01:48:27 2009 From: ad.sergey@REDACTED (Sergey S) Date: Thu, 15 Jan 2009 16:48:27 -0800 Subject: [erlang-questions] Why does "+K true" degrade TCP/IP performance? Message-ID: While I was looking for a way to speed up handling TCP-requests in my gen_tcp application, I found out this option enabling kernel polling. I heard that lighttpd/nginx both use epoll/kqueue to make working with sockets really fast. But against expectation it didn't speed up my app. Furthermore, when I was using "+K true", my app was working a bit slower. 8913 requests per second without "+K true" against 8264 r/s with one (I used Apache Benchmark utility to test that). Is there people who using benefits of "+K true"? Please tell me, what should I use it for? I guess it will be useful during real high network load (especially when there are thousands of connections), but my test says "don't use it". Thanks. -- Sergey. From tali.wang@REDACTED Fri Jan 16 04:00:39 2009 From: tali.wang@REDACTED (Linan Wang) Date: Fri, 16 Jan 2009 03:00:39 +0000 Subject: [erlang-questions] annoying yikes Message-ID: Hi,I have a small program that works well on my iMac but always report "Yikes! erts_alloc() returned misaligned address 0x4886810e" on a FreeBSD server. Both machines are loaded with R11B5. Any idea why? thanks Linan Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: From fritchie@REDACTED Fri Jan 16 05:42:07 2009 From: fritchie@REDACTED (Scott Lystig Fritchie) Date: Thu, 15 Jan 2009 22:42:07 -0600 Subject: [erlang-questions] UBF In-Reply-To: Message of "Thu, 15 Jan 2009 01:13:20 PST." <82e8f979-bdf6-46e1-96db-cca3513ee438@o40g2000prn.googlegroups.com> Message-ID: <34849.1232080927@snookles.snookles.com> Steve Davis wrote: sd> So I'm wondering... sd> * Does anybody have experience of using UBF? Yes. We're starting to use it in commercial products (mumble name mumble mumble). I forget if it's in the wild right now, but products definitely will be within 3 months. sd> * Was this experience of using UBF 100% positive? Yes. It's quite helpful as a design document for human-to-human use. Most software my (mumble) company creates is written in multiple languages (C++, Java), runs in separate OS processes on multiple boxes. UBF is as useful as other IDL'ish things for communicating with managers and other developers what interfaces between them will be. Hacking the UBF contract parser a bit, we now have QuickCheck automatically generating test cases for us. On several occasions, QuickCheck has found protocol bugs *before* we've fully implemented client- or server-side code ... running QC after implementing only a single function has hit me with several "I didn't think it could break like that!" moments. We're on our way to using UBF for specifying a JSON-RPC-based protocol to a third-party developer. There is no really sweet mapping between Erlang terms and JSON objects, so we've picked something that looks merely sort-of ugly. Using L-Shift's JSON library, we are plowing ahead. sd> * Can anyone think of any downside to using UBF over XML/WSDL (apart sd> from the obvious cultural ones)? Run away! -Scott From bbmaj7@REDACTED Fri Jan 16 04:48:44 2009 From: bbmaj7@REDACTED (Richard Andrews) Date: Thu, 15 Jan 2009 19:48:44 -0800 (PST) Subject: [erlang-questions] Why does "+K true" degrade TCP/IP performance? References: Message-ID: <310555.56577.qm@web65512.mail.ac4.yahoo.com> > Is there people who using benefits of "+K true"? Please tell me, what > should I use it for? I've never used the erl +K option but my understanding is that epoll provides benefits when you have a large number of open sockets to watch. The benefits are because the file-descriptor set is stored in the kernel and only needs to be modified when there are changes, not marshalled and resent completely every call like for poll(). Stay connected to the people that matter most with a smarter inbox. Take a look http://au.docs.yahoo.com/mail/smarterinbox From bernie@REDACTED Fri Jan 16 06:06:38 2009 From: bernie@REDACTED (Bernard Duggan) Date: Fri, 16 Jan 2009 16:06:38 +1100 Subject: [erlang-questions] Why does "+K true" degrade TCP/IP performance? In-Reply-To: <310555.56577.qm@web65512.mail.ac4.yahoo.com> References: <310555.56577.qm@web65512.mail.ac4.yahoo.com> Message-ID: <497015DE.3040308@m5net.com> Richard Andrews wrote: >> Is there people who using benefits of "+K true"? Please tell me, what >> should I use it for? > > I've never used the erl +K option but my understanding is that epoll provides enefits when you have a large number of open sockets to watch. The benefits are because the file-descriptor set is stored in the kernel and only needs to be modified when there are changes, not marshalled and resent completely every call like for poll(). That's pretty much the case. We have a bit of network device simulation software that holds open 5000+ TCP connections, but with relatively low bandwith usage on each. Without kernel polling, it would peg a CPU at 100% more or less permanently. With kernel polling turned on, it barely hits 10% or so (all this is on my relatively low specced laptop). So yeah, it definitely has a use :) Cheers, Bernard From mikkodev@REDACTED Fri Jan 16 10:15:47 2009 From: mikkodev@REDACTED (=?ISO-8859-1?Q?Mikko_H=E4m=E4l=E4inen?=) Date: Fri, 16 Jan 2009 11:15:47 +0200 Subject: [erlang-questions] ASN.1 REAL type problem Message-ID: <1c86c2b30901160115w7c3718e4n7bd84067094e8035@mail.gmail.com> Hi, I've recently started learing erlang and I'm now testing the ASN.1 support. I ran into a small problem with REAL types and hope that someone can help me. I have a C-program that sends a simple ASN.1 der encoded message to the erlang server. Strings and integers work fine but when the erlang server receives a REAL type, it decodes it into a tuple like {2626984072961113,2,-46} (mantissa, base, exponent perhaps?) instead of normal float type. Are there some further steps that I need to take to convert this tuple into a float? Thank you in advance, Mikko From erik.reitsma@REDACTED Fri Jan 16 11:07:07 2009 From: erik.reitsma@REDACTED (Erik Reitsma) Date: Fri, 16 Jan 2009 11:07:07 +0100 Subject: [erlang-questions] UBF In-Reply-To: <34849.1232080927@snookles.snookles.com> References: Message of "Thu, 15 Jan 2009 01:13:20 PST."<82e8f979-bdf6-46e1-96db-cca3513ee438@o40g2000prn.googlegroups.com> <34849.1232080927@snookles.snookles.com> Message-ID: <110BA8ACEE682C479D0B008B6BE4AEB107C80B12@esealmw107.eemea.ericsson.se> | We're on our way to using UBF for specifying a JSON-RPC-based | protocol to a third-party developer. There is no really | sweet mapping between Erlang terms and JSON objects, so we've | picked something that looks merely sort-of ugly. Using | L-Shift's JSON library, we are plowing ahead. Oh yes, I had almost forgotten: I have written an UBF-to-JSON(AJAJ)-gateway, so that I can implement an UBF client in Javascript in a browser. Handling binaries is a bit tricky. For my problem I have chosen to send an URL in the JSON, from which the Javascript application can fetch the binary. Usually this binary is an image. I use this gateway for an application for which we had a J2ME client, and the customer wanted a web client too. Using this gateway we did not have to change the server at all. The server was written in Java, so it was easier to write a generic UBF-to-JSON gateway in Erlang than to add JSON support to the Java server. And now we have a gateway which we can reuse for similar situations. :-) *Erik. From cktgatb@REDACTED Fri Jan 16 11:30:05 2009 From: cktgatb@REDACTED (deepblue) Date: Fri, 16 Jan 2009 02:30:05 -0800 (PST) Subject: [erlang-questions] run-time record limitations Message-ID: Im developing an Erlang system and having reoccurring problems with the fact that record's are compile time pre-processor macros (almost), and that they cant be manipulated at runtime... basically Im working with a property pattern, where properties are added at run-time to objects on the front-end (AS3). Ideally I would reflect this with a list on the Erlang side, since its a fundamental datatype, but then using records in QLC [to query ETS tables] would not be possible since to use them I have to specifically say which record property I want to query over... I have at least 15 columns in the larges table, so listing them all in one huge switch statement (case X of) is just plain ugly. does anyone have any ideas how to elegantly solve this? maybe some built-in functions for creating tuples with appropriate signatures for use in pattern matching (for QLC)? thanks From ulf.wiger@REDACTED Fri Jan 16 11:39:57 2009 From: ulf.wiger@REDACTED (Ulf Wiger (TN/EAB)) Date: Fri, 16 Jan 2009 11:39:57 +0100 Subject: [erlang-questions] UBF In-Reply-To: <82e8f979-bdf6-46e1-96db-cca3513ee438@o40g2000prn.googlegroups.com> References: <82e8f979-bdf6-46e1-96db-cca3513ee438@o40g2000prn.googlegroups.com> Message-ID: <497063FD.8070405@ericsson.com> Steve Davis skrev: > > So I'm wondering... > * Does anybody have experience of using UBF? I used it in the "CyberAthletics" project, which for various reasons never took off (the intended sponsors didn't have any money/interest when I had the time/motivation, and vice versa). Working with UBF was very nice. We had a Java client and an Erlang server, and described the protocol in UBF. I tested the server using an Erlang test client, and the UBF contract checker was very quick to point out misuse of the protocol. I also wrote a small contract-to-hrl generator, so that I could specify the messages in UBF and refer to the resulting records in the code. This allowed me to write callbacks that simply matched on the record pattern, since I could trust that UBF had both parsed the data for me, and verified that the types and context were ok. > * Was this experience of using UBF 100% positive? No. Few experiences have been. (: - UBF wasn't actively maintained, so I had my own set of patches. - UBF doesn't support much in terms of asynchronous communication. - While the decoder supports "semantic tags", the encoder provides no facility for using them. > * Can anyone think of any downside to using UBF over > XML/WSDL (apart from the obvious cultural ones)? There are of course benefits of XML, such as that there's a wealth of tools and lots of expertise to draw from. Whether the pain of using (esp) WSDL is worth these benefits, probably depends on whom you ask. BR, Ulf W From adam@REDACTED Fri Jan 16 12:49:29 2009 From: adam@REDACTED (Adam Lindberg) Date: Fri, 16 Jan 2009 11:49:29 +0000 (GMT) Subject: [erlang-questions] run-time record limitations In-Reply-To: Message-ID: <32510275.42031232106569387.JavaMail.root@zimbra> Hi, Unfortunately you cannot get away from the fact that records have to be defined at compile time. You can do some trickery on records based on the fact that they really are ordered tuples where the first element is the record name as an atom. What you cannot do is change the order of keys or the length of a record, this will make all code referencing that record consider it to be another record or just an anonymous tuple. An example of record mangling, which might give you some ideas: http://stackoverflow.com/questions/62245/merging-records-for-mnesia Cheers, Adam ----- "deepblue" wrote: > Im developing an Erlang system and having reoccurring problems with > the fact that record's are compile time pre-processor macros > (almost), > and that they cant be manipulated at runtime... basically Im working > with a property pattern, where properties are added at run-time to > objects on the front-end (AS3). Ideally I would reflect this with a > list on the Erlang side, since its a fundamental datatype, but then > using records in QLC [to query ETS tables] would not be possible > since > to use them I have to specifically say which record property I want > to > query over... I have at least 15 columns in the larges table, so > listing them all in one huge switch statement (case X of) is just > plain ugly. > > does anyone have any ideas how to elegantly solve this? maybe some > built-in functions for creating tuples with appropriate signatures > for > use in pattern matching (for QLC)? > > thanks > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From steven.charles.davis@REDACTED Fri Jan 16 13:27:04 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Fri, 16 Jan 2009 04:27:04 -0800 (PST) Subject: [erlang-questions] UBF In-Reply-To: <497063FD.8070405@ericsson.com> References: <82e8f979-bdf6-46e1-96db-cca3513ee438@o40g2000prn.googlegroups.com> <497063FD.8070405@ericsson.com> Message-ID: <53635130-0af3-44ed-9c2f-76b480a90200@r36g2000prf.googlegroups.com> On Jan 16, 4:39?am, "Ulf Wiger (TN/EAB)" wrote: > I also wrote a small contract-to-hrl generator, so > that I could specify the messages in UBF and refer > to the resulting records in the code. This allowed > me to write callbacks that simply matched on the > record pattern, since I could trust that UBF had > both parsed the data for me, and verified that the > types and context were ok. What a truly **excellent** idea! > - UBF doesn't support much in terms of asynchronous > ? ?communication. Was the facility provided by EVENT too limiting in some way? Thanks to all for sharing your experiences. This makes fascinating reading (for me at least!). regs, /s From erlang@REDACTED Fri Jan 16 13:35:45 2009 From: erlang@REDACTED (Peter Lund) Date: Fri, 16 Jan 2009 13:35:45 +0100 Subject: [erlang-questions] run-time record limitations In-Reply-To: References: Message-ID: <49707F21.6090607@lundata.se> Define your mnesia record once: -record(myrecord, {mnesia_prim_key, dict}). Where the dict contains a dict. And then in runtime you may add how many dictionary keys you'd like into the dictionary. /Peter deepblue skrev: > Im developing an Erlang system and having reoccurring problems with > the fact that record's are compile time pre-processor macros (almost), > and that they cant be manipulated at runtime... basically Im working > with a property pattern, where properties are added at run-time to > objects on the front-end (AS3). Ideally I would reflect this with a > list on the Erlang side, since its a fundamental datatype, but then > using records in QLC [to query ETS tables] would not be possible since > to use them I have to specifically say which record property I want to > query over... I have at least 15 columns in the larges table, so > listing them all in one huge switch statement (case X of) is just > plain ugly. > > does anyone have any ideas how to elegantly solve this? maybe some > built-in functions for creating tuples with appropriate signatures for > use in pattern matching (for QLC)? > > thanks > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From 0x6e6562@REDACTED Fri Jan 16 13:54:58 2009 From: 0x6e6562@REDACTED (Ben Hood) Date: Fri, 16 Jan 2009 12:54:58 +0000 Subject: [erlang-questions] gen_server mailbox scans In-Reply-To: References: <269388e30901140803t7e86ff2cp4fdf32d1499a12bd@mail.gmail.com> <269388e30901150108g7280fa02jb9522a5214132949@mail.gmail.com> Message-ID: <269388e30901160454jdb85a4ei81ba69a4ab5e5490@mail.gmail.com> Chandru, On Thu, Jan 15, 2009 at 11:34 AM, Chandru wrote: > I agree. If you are brave enough to have your own version of gen_server, may > be you can have your message queue in an ordered_set ets table, instead of a > queue. That way, you still keep the message queue in a separate area, and > get all the power of ets. Will work better when you have large message > queues to deal with. Fair point. This could be an optimization that you could investigate. > Is there no way you can throttle your clients before they send a message to > the server process? That would make your life a lot easier. Unfortuneately not. Dealing with viciforous clients purely asynchronously is fine - it is just that we had to exend our server to make a sychronous call to another server in the context of processing of each message. Ben From cktgatb@REDACTED Fri Jan 16 14:01:24 2009 From: cktgatb@REDACTED (deepblue) Date: Fri, 16 Jan 2009 05:01:24 -0800 (PST) Subject: [erlang-questions] run-time record limitations In-Reply-To: <49707F21.6090607@lundata.se> References: <49707F21.6090607@lundata.se> Message-ID: I wish if I use a dict for my properties then I cant pattern match when Im searching the tables (select(), QLC, etc.) so thats a no go, since, as far as I can tell, I would have to iterate over every single dict item and compare them to the value that I need... On Jan 16, 7:35?am, Peter Lund wrote: > Define your mnesia record once: > > -record(myrecord, {mnesia_prim_key, dict}). > > Where the dict contains a dict. And then in runtime you may add how > many dictionary keys you'd like into the dictionary. > > /Peter > > deepblue skrev: > > > > > Im developing an Erlang system and having reoccurring problems with > > the fact that record's are compile time pre-processor macros (almost), > > and that they cant be manipulated at runtime... basically Im working > > with a property pattern, where properties are added at run-time to > > objects on the front-end (AS3). Ideally I would reflect this with a > > list on the Erlang side, since its a fundamental datatype, but then > > using records in QLC [to query ETS tables] would not be possible since > > to use them I have to specifically say which record property I want to > > query over... I have at least 15 columns in the larges table, so > > listing them all in one huge switch statement (case X of) is just > > plain ugly. > > > does anyone have any ideas how to elegantly solve this? maybe some > > built-in functions for creating tuples with appropriate signatures for > > use in pattern matching (for QLC)? > > > thanks > > _______________________________________________ > > erlang-questions mailing list > > erlang-questi...@REDACTED > >http://www.erlang.org/mailman/listinfo/erlang-questions > > _______________________________________________ > erlang-questions mailing list > erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions From colm.dougan@REDACTED Fri Jan 16 14:12:07 2009 From: colm.dougan@REDACTED (Colm Dougan) Date: Fri, 16 Jan 2009 13:12:07 +0000 Subject: [erlang-questions] ssl_pkix:decode_cert_file exceptions with common PEM files Message-ID: <24d4f39c0901160512w1164d66fn4fd722250720a7b1@mail.gmail.com> Hi, I installed the "ca-certificate" package in Debian which provides common CA Certificate PEM files (like those that would be preinstalled on a web-browser). When I tried using ssl_pkix:decode_cert_file on the CA certificates installed a lot of the certificates caused an exception which appear to be due to a few recurring certificate extensions: 1,2,840,113533,7,65,0 (entrust version extension) 2,16,840,1,113730,1,4 (Netscape CA Revocation URL) 2,16,840,1,113730,1,1 (Netscape Certificate Type) 2,16,840,1,113730,1,8 (Netscape CA policy URL) I had a quick look at the ASN.1 definitions in the pkix directory of the OTP distribution and the above definitions are missing. Is there anyway to add the definitions, or a way to avoid the problem? I am concerned if I use the new SSL erlang library to connect to a secure Web site the certificate validation will fail. Thanks, Colm From bertil.karlsson@REDACTED Fri Jan 16 14:49:30 2009 From: bertil.karlsson@REDACTED (Bertil Karlsson) Date: Fri, 16 Jan 2009 14:49:30 +0100 Subject: [erlang-questions] ASN.1 REAL type problem In-Reply-To: <1c86c2b30901160115w7c3718e4n7bd84067094e8035@mail.gmail.com> References: <1c86c2b30901160115w7c3718e4n7bd84067094e8035@mail.gmail.com> Message-ID: <4970906A.4000606@ericsson.com> Hi, There are no built in support to convert it to a float. The asn1-application supports encode/decode of REAL type in base 2 and 10. Base 10 is always decoded in character string format, according to ISO 6093. /Bertil Mikko H?m?l?inen wrote: > Hi, > > I've recently started learing erlang and I'm now testing the ASN.1 > support. I ran into a small problem with REAL types and hope that > someone can help me. > > I have a C-program that sends a simple ASN.1 der encoded message to > the erlang server. Strings and integers work fine but when the erlang > server receives a REAL type, it decodes it into a tuple like > {2626984072961113,2,-46} (mantissa, base, exponent perhaps?) instead > of normal float type. Are there some further steps that I need to take > to convert this tuple into a float? > > Thank you in advance, > Mikko > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > > From ulf.wiger@REDACTED Fri Jan 16 15:02:33 2009 From: ulf.wiger@REDACTED (Ulf Wiger (TN/EAB)) Date: Fri, 16 Jan 2009 15:02:33 +0100 Subject: [erlang-questions] UBF In-Reply-To: <53635130-0af3-44ed-9c2f-76b480a90200@r36g2000prf.googlegroups.com> References: <82e8f979-bdf6-46e1-96db-cca3513ee438@o40g2000prn.googlegroups.com> <497063FD.8070405@ericsson.com> <53635130-0af3-44ed-9c2f-76b480a90200@r36g2000prf.googlegroups.com> Message-ID: <49709379.9090605@ericsson.com> Steve Davis skrev: > > On Jan 16, 4:39 am, "Ulf Wiger (TN/EAB)" > wrote: >> I also wrote a small contract-to-hrl generator, so >> that I could specify the messages in UBF and refer >> to the resulting records in the code. This allowed >> me to write callbacks that simply matched on the >> record pattern, since I could trust that UBF had >> both parsed the data for me, and verified that the >> types and context were ok. > > What a truly **excellent** idea! Well, if you think so, here's the actual code. (: >> - UBF doesn't support much in terms of asynchronous >> communication. > > Was the facility provided by EVENT too limiting in some way? That was what put it in the "not much" category, and we did use EVENTs, but you can't specify a contract that lets the server receive asynchronous events that affect its state. The only thing you can specify is which events the server can send in each state. This means that the contract checker cannot be used for asynchronous protocols (such as, say, SIP, which is the standard for IP telephony, or XMPP which is the standard for IRC.) BR, Ulf W -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: con2hrl.erl URL: From jeedward@REDACTED Fri Jan 16 14:58:44 2009 From: jeedward@REDACTED (John Edward) Date: Fri, 16 Jan 2009 05:58:44 -0800 (PST) Subject: [erlang-questions] MULTICONF-09 final call for papers Message-ID: <311726.71407.qm@web45915.mail.sp1.yahoo.com> MULTICONF-09 final call for papers ? The 2009 Multi Conference in Computer Science, Information Technology and Control systems and Computational Science and Computer Engineering (MULTICONF-09) (website: http://www.PromoteResearch.org) will be held during July 13-16 2009 in Orlando, FL, USA. We invite draft paper submissions. The event consists of the following conferences: ????????? International Conference on Artificial Intelligence and Pattern Recognition (AIPR-09) ????????? International Conference on Automation, Robotics and Control Systems (ARCS-09) ????????? International Conference on Bioinformatics, Computational Biology, Genomics and Chemoinformatics (BCBGC-09) ????????? International Conference on Enterprise Information Systems and Web Technologies (EISWT-09) ????????? International Conference on High Performance Computing, Networking and Communication Systems (HPCNCS-09) ????????? International Conference on Information Security and Privacy (ISP-09) ????????? International Conference on Recent Advances in Information Technology and Applications (RAITA-09) ????????? International Conference on Software Engineering Theory and Practice (SETP-09) ????????? International Conference on Theory and Applications of Computational Science (TACS-09) ????????? International Conference on Theoretical and Mathematical Foundations of Computer Science (TMFCS-09) ? The website http://www.PromoteResearch.org? contains more details. ? Sincerely John Edward Publicity committee ? ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ingela@REDACTED Fri Jan 16 15:55:10 2009 From: ingela@REDACTED (Ingela Anderton Andin) Date: Fri, 16 Jan 2009 15:55:10 +0100 Subject: [erlang-questions] ssl_pkix:decode_cert_file exceptions with common PEM files In-Reply-To: References: Message-ID: <49709FCE.7000706@erix.ericsson.se> Hi! > Hi, > > I installed the "ca-certificate" package in Debian which provides > common CA Certificate PEM files (like those that would be preinstalled > on a web-browser). > > When I tried using ssl_pkix:decode_cert_file on the CA certificates > installed a lot of the certificates caused an exception which appear > to be due to a few recurring certificate extensions: > > 1,2,840,113533,7,65,0 (entrust version extension) > 2,16,840,1,113730,1,4 (Netscape CA Revocation URL) > 2,16,840,1,113730,1,1 (Netscape Certificate Type) > 2,16,840,1,113730,1,8 (Netscape CA policy URL) > > I had a quick look at the ASN.1 definitions in the pkix directory of > the OTP distribution and the above definitions are missing. Is there > anyway to add the definitions, or a way to avoid the problem? I am > concerned if I use the new SSL erlang library to connect to a secure > Web site the certificate validation will fail. > > The new ssl implementation does not use the ssl_pkix module at all or the ASN-specs in ssl. The new ssl implementation uses the new application public_key for all its certificate handling and a soon as we make public_key a documented application the ssl_pkix module will be come deprecated and later on removed. I do not think that the ssl_pkix module can have been used so much as it seems to be somewhat broken! Note however that the new ssl implementations still has a few limitations that we are working on implementing. Regards Ingela Erlang/OTP - Ericsson From ciprian.craciun@REDACTED Fri Jan 16 16:21:11 2009 From: ciprian.craciun@REDACTED (Ciprian Dorin, Craciun) Date: Fri, 16 Jan 2009 17:21:11 +0200 Subject: [erlang-questions] Using gen_server or writing a new behavior Message-ID: <8e04b5820901160721w47ce6a80p3d388a0be6500f4e@mail.gmail.com> Hello all! I have a somehow philosophycal question about OTP, mainly about gen_server... I want to write my own HTTP framework, the main focus now being the request handlers... So: * I created a request handler supervisor, which managed the request handlers; * each connection handler after resolving the request handler, delegates the request to it; Now my question is the following: * I could implement the request handlers as being normal gen_server instances (first option); * or (second option) I could define a new behavior (let's call it ws_handler), that defines handle_process callback (resembling somehow handle_call), and thus create a new gen_server like process "class"... (actually my handler is just a normal gen_server, that delegates the a special message to this callback); The advantages of the second solution is that it simplifies the handler development, but it adds (for now) unnecessary wrapping (as it is a gen_server behind scenes). Also the disadvantage is that there is no straight-forward way to create a new gen_server like behavior without wrapping it inside a gen_server. So the question is which of the two options would be the preferred one? Or what are your thoughts about this issue? Thanks all, Ciprian Craciun. From chsu79@REDACTED Fri Jan 16 17:30:01 2009 From: chsu79@REDACTED (Christian) Date: Fri, 16 Jan 2009 17:30:01 +0100 Subject: [erlang-questions] Using gen_server or writing a new behavior In-Reply-To: <8e04b5820901160721w47ce6a80p3d388a0be6500f4e@mail.gmail.com> References: <8e04b5820901160721w47ce6a80p3d388a0be6500f4e@mail.gmail.com> Message-ID: On Fri, Jan 16, 2009 at 16:21, Ciprian Dorin, Craciun wrote: > Hello all! > > I have a somehow philosophycal question about OTP, mainly about > gen_server... > > I want to write my own HTTP framework, the main focus now being > the request handlers... So: > * I created a request handler supervisor, which managed the > request handlers; > * each connection handler after resolving the request handler, > delegates the request to it; This is how I have it: * each request is a process that look at the method, url, etc, dispatch to functions that parse what is needed, such as posted bodies or query args. * all the data goes into a function that calls plain ordinary gen_servers (if they need to at all!), still in the same process * the result is sent to a template function that renders the result values to something htmlish, and still in the same process. This is because sending each request directly into a gen_server will limit concurrency. While it processes one requests, others could be _waiting to be served_. The latter being the problem. Additionally, my way the gen_servers that I do need, for ordering access to some resources, have no dependencies on http requests. They instead expose the sanest messages possible for the manipulations to the resource they keep. You should probably look into "beepbeep" since it does pretty much exactly what i describe. It also uses erlydtl which is a pretty cool template language. From ciprian.craciun@REDACTED Fri Jan 16 18:15:32 2009 From: ciprian.craciun@REDACTED (Ciprian Dorin, Craciun) Date: Fri, 16 Jan 2009 19:15:32 +0200 Subject: [erlang-questions] Using gen_server or writing a new behavior In-Reply-To: References: <8e04b5820901160721w47ce6a80p3d388a0be6500f4e@mail.gmail.com> Message-ID: <8e04b5820901160915m4109b02cpa6a48a34f44f9b6@mail.gmail.com> On Fri, Jan 16, 2009 at 6:30 PM, Christian wrote: > On Fri, Jan 16, 2009 at 16:21, Ciprian Dorin, Craciun > wrote: >> Hello all! >> >> I have a somehow philosophycal question about OTP, mainly about >> gen_server... >> >> I want to write my own HTTP framework, the main focus now being >> the request handlers... So: >> * I created a request handler supervisor, which managed the >> request handlers; >> * each connection handler after resolving the request handler, >> delegates the request to it; > > This is how I have it: > > * each request is a process that look at the method, url, etc, > dispatch to functions that parse what is needed, such as posted bodies > or query args. > * all the data goes into a function that calls plain ordinary > gen_servers (if they need to at all!), still in the same process > * the result is sent to a template function that renders the result > values to something htmlish, and still in the same process. What do you mean by "calls plain ordinary gen_servers still in the same process"? Calling a gen_server implies sending a message to a gen_server process, right? > This is because sending each request directly into a gen_server will > limit concurrency. While it processes one requests, others could be > _waiting to be served_. The latter being the problem. Yes, indeed this would happen, and this would be an disadvantage... (Limiting concurency, adding message passing overhead) But there are two reasons I would like to do this (that is using gen_server like processes): * first is that it looks more Erlang-ish, than dispatching the request to a module:function... (the Erlang way is have lot's of processes right?); * second, I could create multiple request handlers that are used in a round robin fashion; (and thus control the load on a given set of URLs, without having fancy code behind it, just by limiting the number of registered handlers); As a side note, this is what bothers me with most Erlang http servers: they use module:callback dispatchers and not processes... It adds performance, but reduces flexibility / OTP-way of doing things (if there is such a thing)... > Additionally, my way the gen_servers that I do need, for ordering > access to some resources, have no dependencies on http requests. They > instead expose the sanest messages possible for the manipulations to > the resource they keep. > > You should probably look into "beepbeep" since it does pretty much > exactly what i describe. It also uses erlydtl which is a pretty cool > template language. I'll look into them. Thanks, Ciprian Craciun. From jebenitez@REDACTED Fri Jan 16 20:11:03 2009 From: jebenitez@REDACTED (Jose Enrique Benitez Jimenez) Date: Fri, 16 Jan 2009 14:11:03 -0500 Subject: [erlang-questions] ODBC driver Message-ID: Hi, I want to connect to an SQL database, I receive the follow error 7> odbc:start(). ok 8> odbc:connect("DNS:localhost",[]). {error,"No SQL-driver information available. Connection to database failed."} SQL server 2000 is already intalled, Do I need the ODBC driver or SQL server 2000 have it ?, in the first case, how can i get it?? (I'm using Windows XP) Thanks. From chsu79@REDACTED Fri Jan 16 20:55:52 2009 From: chsu79@REDACTED (Christian) Date: Fri, 16 Jan 2009 20:55:52 +0100 Subject: [erlang-questions] Using gen_server or writing a new behavior In-Reply-To: <8e04b5820901160915m4109b02cpa6a48a34f44f9b6@mail.gmail.com> References: <8e04b5820901160721w47ce6a80p3d388a0be6500f4e@mail.gmail.com> <8e04b5820901160915m4109b02cpa6a48a34f44f9b6@mail.gmail.com> Message-ID: On Fri, Jan 16, 2009 at 18:15, Ciprian Dorin, Craciun wrote: >> * each request is a process that look at the method, url, etc, >> dispatch to functions that parse what is needed, such as posted bodies >> or query args. >> * all the data goes into a function that calls plain ordinary >> gen_servers (if they need to at all!), still in the same process >> * the result is sent to a template function that renders the result >> values to something htmlish, and still in the same process. > > What do you mean by "calls plain ordinary gen_servers still in the > same process"? Calling a gen_server implies sending a message to a > gen_server process, right? That was a bit unclear. I mean that the controller might not need to call the gen_server at all. Simple form validation can be done in the request process, i.e. if the form values dont match regexps and such, then it can just throw an exception or serve the form again with the complaints added. But if the form submitted is valid it can take it to the next level and actually perform the side-effects, be it either to call a gen_server, or to run a mnesia transaction. >> This is because sending each request directly into a gen_server will >> limit concurrency. While it processes one requests, others could be >> _waiting to be served_. The latter being the problem. > > Yes, indeed this would happen, and this would be an > disadvantage... (Limiting concurency, adding message passing overhead) (Message passing has very low overhead, check out the ring benchmarks.) It's all about the concurrency. It just doesnt make sense to perform form validation in a gen_server and have other processes waiting to have their forms validated. It's not something that depend on each other's completion order. > But there are two reasons I would like to do this (that is using > gen_server like processes): > * first is that it looks more Erlang-ish, than dispatching the > request to a module:function... (the Erlang way is have lot's of > processes right?); > * second, I could create multiple request handlers that are used > in a round robin fashion; (and thus control the load on a given set of > URLs, without having fancy code behind it, just by limiting the number > of registered handlers); I've never felt that the erlang-way is to throw processes at things for the fun of it. Rules for when to use processes is something that has been discussed on the list without any clear rules of thumb being mentioned. It is really up for a situation-per-situation analysis. Here I just dont see what you gain. Two requests are "embarrassingly parallellizable" until they go for the same resource. Let them be dynamically created processes, one per request. I do not buy the second argument because the process scheduler already does the job of making sure processes get a slice of the cpu fairly. If you want to distribute requests over multiple nodes then it might be sensible, but reverse proxies for http already provide a mechanism for it. > As a side note, this is what bothers me with most Erlang http > servers: they use module:callback dispatchers and not processes... It > adds performance, but reduces flexibility / OTP-way of doing things > (if there is such a thing)... It is because the http servers have a process created for that tcp connection, and it has parsed the http headers and now go on to the callback for processing the request. Yaws, mochiweb, iserve... it is all one-process-per-request already. I appreciate the otp behaviours for long-running services. For a single http request i dont bother. The http port listener is a long running process that tends to be supervised and a otp behaviour. If it crashes it is a problem. If a single http request crashes it is not much of a problem, as long as the http listener is up it can start a new acceptor, so it is an isolated problem for just that request. Just log/notify some error status. What flexibility do you lose? Doing the gen_server:reply/2 trick by having a gen_server spawn new processes just seems like duplication to get what you already had with callback-based http servers. From Martin.Logan@REDACTED Thu Jan 15 18:30:40 2009 From: Martin.Logan@REDACTED (Logan, Martin) Date: Thu, 15 Jan 2009 11:30:40 -0600 Subject: [erlang-questions] Yet Another Web Server In-Reply-To: References: Message-ID: <77C1226CCC2F7C41B022662F4775DABC56EC205EA7@EGEXCMB01.oww.root.lcl> Check out crary - it is much more lightweight. http://erlware.org/lib/5.6.3/crary-0.2.3/ -----Original Message----- From: erlang-questions-bounces@REDACTED [mailto:erlang-questions-bounces@REDACTED] On Behalf Of Jose Enrique Benitez Jimenez Sent: Monday, January 05, 2009 12:52 AM To: erlang-questions@REDACTED Subject: [erlang-questions] Yet Another Web Server Greetings, I want include a web server to my Erlang application, can I do this with YAWS? Thanks. _______________________________________________ erlang-questions mailing list erlang-questions@REDACTED http://www.erlang.org/mailman/listinfo/erlang-questions From rvirding@REDACTED Fri Jan 16 23:55:30 2009 From: rvirding@REDACTED (Robert Virding) Date: Fri, 16 Jan 2009 23:55:30 +0100 Subject: [erlang-questions] run-time record limitations In-Reply-To: References: <49707F21.6090607@lundata.se> Message-ID: <3dbc6d1c0901161455g1604e5f3j9c987dc40bf49669@mail.gmail.com> 2009/1/16 deepblue > I wish > if I use a dict for my properties then I cant pattern match when Im > searching the tables (select(), QLC, etc.) so thats a no go, since, as > far as I can tell, I would have to iterate over every single dict item > and compare them to the value that I need... I don't really understand how you mean can't use pattern match, could you give an example? There would be not much more iteration over a dict then there would searching in tables, it depends on your pattern how much scanning needs to be done. One benefit with a dict is that there is no copying as everything is in the same process. Another factor to take into account is how big the tables are. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From rvirding@REDACTED Sat Jan 17 00:01:05 2009 From: rvirding@REDACTED (Robert Virding) Date: Sat, 17 Jan 2009 00:01:05 +0100 Subject: [erlang-questions] gen_server mailbox scans In-Reply-To: References: <269388e30901140803t7e86ff2cp4fdf32d1499a12bd@mail.gmail.com> <269388e30901150108g7280fa02jb9522a5214132949@mail.gmail.com> Message-ID: <3dbc6d1c0901161501j27f901c9u301a4841c6a6bdd1@mail.gmail.com> 2009/1/15 Chandru > Hi Ben, > > I agree. If you are brave enough to have your own version of gen_server, > may be you can have your message queue in an ordered_set ets table, instead > of a queue. That way, you still keep the message queue in a separate area, > and get all the power of ets. Will work better when you have large message > queues to deal with. One thing to remember with ets tables is that you copy data between the process and the table. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From rvirding@REDACTED Sat Jan 17 00:08:16 2009 From: rvirding@REDACTED (Robert Virding) Date: Sat, 17 Jan 2009 00:08:16 +0100 Subject: [erlang-questions] Here's hoping we get frames or structs in 2009! In-Reply-To: References: Message-ID: <3dbc6d1c0901161508p5be6e108w73d4301d8302272a@mail.gmail.com> 2009/1/12 Christian > > Ponder this approach I implemented: > ... Something like this could be done for a struct/frame but have a special data type. In that case it would look like a record but there the "name" field would be a descriptor showing which fields there are and where in the "tuple" they are. There would be no need to keep anything in an ets table. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From rvirding@REDACTED Sat Jan 17 03:52:11 2009 From: rvirding@REDACTED (Robert Virding) Date: Sat, 17 Jan 2009 03:52:11 +0100 Subject: [erlang-questions] New version of the Erlang Rationale (+ IO System) Message-ID: <3dbc6d1c0901161852y7e47a144sa21d056cba088a47@mail.gmail.com> I have just released a new version of the Erlang Rationale. It contains a number of updates and new stuff which have been discreetly makred with a line in the margin. Also the description of the i/o system has been broken out into a separate document and has had the example extended. Some of the new additions have also been pasted in my blog. Both these documents are in the same zip file and are now in PDF format, which will hopefully gladden my readers. It is available on trapexit at: http://forum.trapexit.org/viewtopic.php?p=44373#44373 Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffm@REDACTED Sat Jan 17 03:54:44 2009 From: jeffm@REDACTED (jm) Date: Sat, 17 Jan 2009 13:54:44 +1100 Subject: [erlang-questions] trapexit.org: lost lost password link Message-ID: <49714874.1090204@ghostgun.com> The FAQ on the site once you've found it says: I've lost my password! Don't panic! While your password cannot be retrieved it can be reset. To do this go to the login page and click I've forgotten my password. Follow the instructions and you should be back online in no time. Help! I've lost the lost password link! Even using a text search on the word "lost" can't find it. Worse, there doesn't seem to be an obvious admin contact for the site. So, my question is, 1) who should I contact in case of a lost/forgotten password on trapexit.org? Jeff. From hayeah@REDACTED Sat Jan 17 07:19:25 2009 From: hayeah@REDACTED (Howard Yeh) Date: Fri, 16 Jan 2009 22:19:25 -0800 Subject: [erlang-questions] New version of the Erlang Rationale (+ IO System) In-Reply-To: <3dbc6d1c0901161852y7e47a144sa21d056cba088a47@mail.gmail.com> References: <3dbc6d1c0901161852y7e47a144sa21d056cba088a47@mail.gmail.com> Message-ID: for the lazy, mr virding's blog, http://rvirding.blogspot.com/ 2009/1/16 Robert Virding : > I have just released a new version of the Erlang Rationale. It contains a > number of updates and new stuff which have been discreetly makred with a > line in the margin. Also the description of the i/o system has been broken > out into a separate document and has had the example extended. Some of the > new additions have also been pasted in my blog. > > Both these documents are in the same zip file and are now in PDF format, > which will hopefully gladden my readers. > > It is available on trapexit at: > > http://forum.trapexit.org/viewtopic.php?p=44373#44373 > > Robert > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From jebenitez@REDACTED Sat Jan 17 08:00:38 2009 From: jebenitez@REDACTED (Jose Enrique Benitez Jimenez) Date: Sat, 17 Jan 2009 02:00:38 -0500 Subject: [erlang-questions] Use module in another path Message-ID: Hello everyone, This may be a simple question but I am new in this, How can I use a module that is in another path ???, I need to know because my application have .yaws files and .beam files and I dont want those two types of files be together. Thank you very much. From pguyot@REDACTED Sat Jan 17 09:49:21 2009 From: pguyot@REDACTED (Paul Guyot) Date: Sat, 17 Jan 2009 09:49:21 +0100 Subject: [erlang-questions] Custom supervisor Message-ID: <4DD33013-11C5-456D-B114-93109F440456@kallisys.net> Hello, We have worker processes that are identified by a key and on each node, a manager that provides the pid of the worker process from the key, spawning a new worker if required. The key is independent from the node. The workers may crash and if they do, they should be restarted, being told they are restarted as a parameter of the init callback function, and when queried, the manager will return the new pid. The workers may also be stopped and started on another node (i.e. migrated). The workers are simple gen_servers. To perform this, we wrote the manager as a gen_server that traps exits and spawn processes and that stores the key/pid mapping in a mnesia table. However, I am wondering if the workers are visible in the OTP supervision tree since they are children of a worker and not of a supervisor. If we declare to the manager's supervisor that the manager is a supervisor (and not a worker), this has consequences I do not fully understand. I figured out that the manager will receive a which_children message during a release update, but that's all I know. We did update the worker's code, but we only needed {load_module, worker} and not {update, worker, {advanced, extra}}, i.e. we did not need to call code_change yet. Still, I guess that Module:code_change is only called when the module is in the supervision tree. Is there a more OTP-way to perform this, i.e. to track the death/ restarts of the children of a supervisor? What are the consequences of having worker or supervisor in the supervisor's child specifications? Paul From erlang@REDACTED Sat Jan 17 10:52:22 2009 From: erlang@REDACTED (Dominic Williams) Date: Sat, 17 Jan 2009 10:52:22 +0100 Subject: [erlang-questions] Custom supervisor In-Reply-To: <4DD33013-11C5-456D-B114-93109F440456@kallisys.net> References: <4DD33013-11C5-456D-B114-93109F440456@kallisys.net> Message-ID: <4971AA56.3060903@dominicwilliams.net> Hi Paul, Paul Guyot a ?crit : > [...] > Is there a more OTP-way to perform this, i.e. to track the death/ > restarts of the children of a supervisor? In the OTP approach, you should not mix supervision with work. Your manager is doing work, so it should not be a supervisor as well. One solution would be for the manager to attach the workers as dynamic childs to its own supervisor. This would be if the number of workers is variable. If the number of workers is fixed, everyone (manager and workers) could be declared as fixed children in the same supervisor. Both of the above approaches are right if the restart strategies are the same for manager and workers, though, which is rarely the case. The "standard" solution in your kind of case is to have a top supervisor that supervises the manager and another supervisor. The sub-supervisor supervises all the workers. You'd probably need to have the workers register themselves with the manager when they start or restart. Hope that helps, Dominic Williams http://dominicwilliams.net ---- From vychodil.hynek@REDACTED Sat Jan 17 11:24:15 2009 From: vychodil.hynek@REDACTED (Hynek Vychodil) Date: Sat, 17 Jan 2009 11:24:15 +0100 Subject: [erlang-questions] Use module in another path In-Reply-To: References: Message-ID: <20090117102416.1635424013@relay.gooddata.com> See http://www.erlang.org/doc/man/code.html#add_path-1 and also http://www.erlang.org/doc/man/erl.html flags -pa -pz On Sat, Jan 17, 2009 at 8:00 AM, Jose Enrique Benitez Jimenez < jebenitez@REDACTED> wrote: > Hello everyone, > This may be a simple question but I am new in this, How can I use a module > that is in another path ???, I need to know because my application have > .yaws files and .beam files and I dont want those two types of files be > together. > > Thank you very much. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero! Try Good Data now for free: www.gooddata.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven.charles.davis@REDACTED Sat Jan 17 11:46:10 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Sat, 17 Jan 2009 02:46:10 -0800 (PST) Subject: [erlang-questions] Real basic binary manipulation question Message-ID: Problem - to decompress a binary where zeros are run-length encoded. The following seems to work but also seems ugly and causes unnecessary overhead. %% Decompress binary where Zeros are Run-Length Encoded decompress(Bin) when is_binary(Bin) -> L = binary_to_list(Bin), F = fun(X, [H|T]) when H =:= expand -> lists:duplicate(X, 0) ++ T; (X, Acc) when X =:= 0 -> [expand] ++ Acc; (X, Acc) -> [X] ++ Acc end, Decompressed = lists:foldl(F, [], L), list_to_binary(lists:reverse(lists:flatten(Decompressed))). Any bids on an improvement? Thanks for any attention. Side note: the erlang bit syntax is *amazing* when you actually get down to doing something with IP packets From pguyot@REDACTED Sat Jan 17 12:27:51 2009 From: pguyot@REDACTED (Paul Guyot) Date: Sat, 17 Jan 2009 12:27:51 +0100 Subject: [erlang-questions] Custom supervisor In-Reply-To: <4971AA56.3060903@dominicwilliams.net> References: <4DD33013-11C5-456D-B114-93109F440456@kallisys.net> <4971AA56.3060903@dominicwilliams.net> Message-ID: <34058B9B-10FF-40DD-B00C-C118D34E6DBA@kallisys.net> Le 17 janv. 09 ? 10:52, Dominic Williams a ?crit : > Hi Paul, > > Paul Guyot a ?crit : > > [...] >> Is there a more OTP-way to perform this, i.e. to track the death/ >> restarts of the children of a supervisor? > > In the OTP approach, you should not mix supervision with work. Your > manager is doing work, so it should not be a supervisor as well. > > One solution would be for the manager to attach the workers as > dynamic childs to its own supervisor. This would be if the number of > workers is variable. > > If the number of workers is fixed, everyone (manager and workers) > could be declared as fixed children in the same supervisor. > > Both of the above approaches are right if the restart strategies are > the same for manager and workers, though, which is rarely the case. > The "standard" solution in your kind of case is to have a top > supervisor that supervises the manager and another supervisor. The > sub-supervisor supervises all the workers. You'd probably need to > have the workers register themselves with the manager when they > start or restart. Hello Dominic, Thank you for your reply. What you describe is what we did at first, i.e. a tree with a manager_sup that has the manager and a worker_sup as its children, the worker_sup having a simple_one_for_one strategy (we have a variable number of workers). We abandoned this approach because the worker needs to know when its started or restarted. Hence the idea of a custom supervisor that would change a parameter to start_link whenever the process is started or restarted. But maybe we outlook the standard supervisor and there is a way to figure out if a worker is started or restarted by the supervisor? I also realize that having a supervisor doing some work is a very bad idea as it implies that the workers are killed if the manager dies, which might not be desirable. Regards, Paul From rvirding@REDACTED Sat Jan 17 12:41:27 2009 From: rvirding@REDACTED (Robert Virding) Date: Sat, 17 Jan 2009 12:41:27 +0100 Subject: [erlang-questions] New version of the Erlang Rationale (+ IO System) In-Reply-To: <3dbc6d1c0901161852y7e47a144sa21d056cba088a47@mail.gmail.com> References: <3dbc6d1c0901161852y7e47a144sa21d056cba088a47@mail.gmail.com> Message-ID: <3dbc6d1c0901170341n6cd88ad2jf3e524ee9af7545b@mail.gmail.com> 2009/1/17 Robert Virding > I have just released a new version of the Erlang Rationale. It contains a > number of updates and new stuff which have been discreetly makred with a > line in the margin. Also the description of the i/o system has been broken > out into a separate document and has had the example extended. I forgot to mention that both these documents are not in their final state and should be considered "work in progress". As before I am open to suggestions and comments. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From rvirding@REDACTED Sat Jan 17 12:44:44 2009 From: rvirding@REDACTED (Robert Virding) Date: Sat, 17 Jan 2009 12:44:44 +0100 Subject: [erlang-questions] Use module in another path In-Reply-To: <20090117102416.1635424013@relay.gooddata.com> References: <20090117102416.1635424013@relay.gooddata.com> Message-ID: <3dbc6d1c0901170344j11f88971rff852749c904697b@mail.gmail.com> You can also use the ERL_LIBS environment variable which is described in the docs for the module 'code'. Robert 2009/1/17 Hynek Vychodil > See > http://www.erlang.org/doc/man/code.html#add_path-1 > and also http://www.erlang.org/doc/man/erl.html flags -pa -pz > > > On Sat, Jan 17, 2009 at 8:00 AM, Jose Enrique Benitez Jimenez < > jebenitez@REDACTED> wrote: > >> Hello everyone, >> This may be a simple question but I am new in this, How can I use a module >> that is in another path ???, I need to know because my application have >> .yaws files and .beam files and I dont want those two types of files be >> together. >> >> Thank you very much. >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions@REDACTED >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > > > > -- > --Hynek (Pichi) Vychodil > > Analyze your data in minutes. Share your insights instantly. Thrill your > boss. Be a data hero! > Try Good Data now for free: www.gooddata.com > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From harveyd@REDACTED Sat Jan 17 14:25:38 2009 From: harveyd@REDACTED (Dale Harvey) Date: Sat, 17 Jan 2009 13:25:38 +0000 Subject: [erlang-questions] trapexit.org: lost lost password link In-Reply-To: <49714874.1090204@ghostgun.com> References: <49714874.1090204@ghostgun.com> Message-ID: its a phpbb forum, so I just went to another phpbb forum, copied the url http://forum.trapexit.org/profile.php?mode=sendpassword 2009/1/17 jm > The FAQ on the site once you've found it says: > > I've lost my password! > Don't panic! While your password cannot be retrieved it can be reset. To > do this go to the login page and click I've forgotten my password. > Follow the instructions and you should be back online in no time. > > > Help! I've lost the lost password link! Even using a text search on the > word "lost" can't find it. Worse, there doesn't seem to be an obvious > admin contact for the site. So, my question is, > > 1) who should I contact in case of a lost/forgotten password on > trapexit.org? > > > Jeff. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From juanjo@REDACTED Sat Jan 17 14:30:31 2009 From: juanjo@REDACTED (Juan Jose Comellas) Date: Sat, 17 Jan 2009 11:30:31 -0200 Subject: [erlang-questions] Real basic binary manipulation question In-Reply-To: References: Message-ID: <1c3be50f0901170530w48d04f8djfdfd637bf219d24a@mail.gmail.com> In your function it wasn't clear to me why you were adding the 'expand' atom to the destination list T. Maybe something like this could do: -module(zrle). -export([decompress/1]). decompress(Bin) when is_binary(Bin) -> decompress(Bin, []). decompress(<<0, Count, Tail/binary>>, Acc) -> decompress(Tail, [<<0:(Count * 8)>> | Acc]); decompress(<>, Acc) -> decompress(Tail, [Head | Acc]); decompress(<<>>, Acc) -> list_to_binary(lists:reverse(Acc)). e.g. 1> zrle:decompress(<<1, 0, 5, 2, 3, 4, 0, 3>>). <<1,0,0,0,0,0,2,3,4,0,0,0>> On Sat, Jan 17, 2009 at 8:46 AM, Steve Davis wrote: > Problem - to decompress a binary where zeros are run-length encoded. > The following seems to work but also seems ugly and causes unnecessary > overhead. > > %% Decompress binary where Zeros are Run-Length Encoded > decompress(Bin) when is_binary(Bin) -> > L = binary_to_list(Bin), > F = fun(X, [H|T]) when H =:= expand -> lists:duplicate(X, 0) ++ T; > (X, Acc) when X =:= 0 -> [expand] ++ Acc; > (X, Acc) -> [X] ++ Acc > end, > Decompressed = lists:foldl(F, [], L), > list_to_binary(lists:reverse(lists:flatten(Decompressed))). > > Any bids on an improvement? > > Thanks for any attention. > > Side note: the erlang bit syntax is *amazing* when you actually get > down to doing something with IP packets > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From erlang@REDACTED Sat Jan 17 15:13:32 2009 From: erlang@REDACTED (Dominic Williams) Date: Sat, 17 Jan 2009 15:13:32 +0100 Subject: [erlang-questions] Custom supervisor In-Reply-To: <34058B9B-10FF-40DD-B00C-C118D34E6DBA@kallisys.net> References: <4DD33013-11C5-456D-B114-93109F440456@kallisys.net> <4971AA56.3060903@dominicwilliams.net> <34058B9B-10FF-40DD-B00C-C118D34E6DBA@kallisys.net> Message-ID: <4971E78C.70409@dominicwilliams.net> Hi Paul, Paul Guyot a ?crit : > But maybe we outlook the standard supervisor and there is > a way to figure out if a worker is started or restarted > by the supervisor? I don't think OTP offers a way. However, needing to know this is a special case of needing some state to survive crashes. Three possibilities: - get the state from another process - mnesia or some other persistence In your case, the key->worker mnesia table can be used to work out whether a worker is restarting or not. Having the worker access the table directly or asking the manager is a matter of taste. > I also realize that having a supervisor doing some work > is a very bad idea as it implies that the workers are > killed if the manager dies, which might not be desirable. Yes. The other reason for separating supervision and work is that you want to make sure that a supervisor is simple and reliable, then you don't want to touch it anymore :) Regards, Dominic Williams http://dominicwilliams.net ---- From per.gustafsson@REDACTED Sat Jan 17 15:30:34 2009 From: per.gustafsson@REDACTED (Per Gustafsson) Date: Sat, 17 Jan 2009 15:30:34 +0100 Subject: [erlang-questions] Real basic binary manipulation question In-Reply-To: <1c3be50f0901170530w48d04f8djfdfd637bf219d24a@mail.gmail.com> References: <1c3be50f0901170530w48d04f8djfdfd637bf219d24a@mail.gmail.com> Message-ID: <4971EB8A.7010705@it.uu.se> Or even more straight-forward: -module(zrle). -export([decompress/1]). decompress(Bin) when is_binary(Bin) -> decompress(Bin, <<>>). decompress(<<0, Count, Tail/binary>>, Acc) -> decompress(Tail, <>); decompress(<>, Acc) -> decompress(Tail, <>); decompress(<<>>, Acc) -> Acc. If you are using at least R12 the performance for this should be ok. Per Juan Jose Comellas wrote: > In your function it wasn't clear to me why you were adding the > 'expand' atom to the destination list T. Maybe something like this > could do: > > > -module(zrle). > -export([decompress/1]). > > decompress(Bin) when is_binary(Bin) -> > decompress(Bin, []). > > decompress(<<0, Count, Tail/binary>>, Acc) -> > decompress(Tail, [<<0:(Count * 8)>> | Acc]); > decompress(<>, Acc) -> > decompress(Tail, [Head | Acc]); > decompress(<<>>, Acc) -> > list_to_binary(lists:reverse(Acc)). > > > e.g. > > 1> zrle:decompress(<<1, 0, 5, 2, 3, 4, 0, 3>>). > <<1,0,0,0,0,0,2,3,4,0,0,0>> > > > > On Sat, Jan 17, 2009 at 8:46 AM, Steve Davis > > wrote: > > Problem - to decompress a binary where zeros are run-length encoded. > The following seems to work but also seems ugly and causes unnecessary > overhead. > > %% Decompress binary where Zeros are Run-Length Encoded > decompress(Bin) when is_binary(Bin) -> > L = binary_to_list(Bin), > F = fun(X, [H|T]) when H =:= expand -> lists:duplicate(X, > 0) ++ T; > (X, Acc) when X =:= 0 -> [expand] ++ Acc; > (X, Acc) -> [X] ++ Acc > end, > Decompressed = lists:foldl(F, [], L), > list_to_binary(lists:reverse(lists:flatten(Decompressed))). > > Any bids on an improvement? > > Thanks for any attention. > > Side note: the erlang bit syntax is *amazing* when you actually get > down to doing something with IP packets > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > > > ------------------------------------------------------------------------ > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From rtrlists@REDACTED Sat Jan 17 16:45:02 2009 From: rtrlists@REDACTED (Robert Raschke) Date: Sat, 17 Jan 2009 15:45:02 +0000 Subject: [erlang-questions] Custom supervisor In-Reply-To: <4DD33013-11C5-456D-B114-93109F440456@kallisys.net> References: <4DD33013-11C5-456D-B114-93109F440456@kallisys.net> Message-ID: <6a3ae47e0901170745j1b76942em9a79a06d09666e04@mail.gmail.com> On Sat, Jan 17, 2009 at 8:49 AM, Paul Guyot wrote: > Hello, > > We have worker processes that are identified by a key and on each > node, a manager that provides the pid of the worker process from the > key, spawning a new worker if required. The key is independent from > the node. The workers may crash and if they do, they should be > restarted, being told they are restarted as a parameter of the init > callback function, and when queried, the manager will return the new > pid. The workers may also be stopped and started on another node (i.e. > migrated). The workers are simple gen_servers. > > To perform this, we wrote the manager as a gen_server that traps exits > and spawn processes and that stores the key/pid mapping in a mnesia > table. However, I am wondering if the workers are visible in the OTP > supervision tree since they are children of a worker and not of a > supervisor. If we declare to the manager's supervisor that the manager > is a supervisor (and not a worker), this has consequences I do not > fully understand. I figured out that the manager will receive a > which_children message during a release update, but that's all I know. > > We did update the worker's code, but we only needed {load_module, > worker} and not {update, worker, {advanced, extra}}, i.e. we did not > need to call code_change yet. Still, I guess that Module:code_change > is only called when the module is in the supervision tree. > > Is there a more OTP-way to perform this, i.e. to track the death/ > restarts of the children of a supervisor? > What are the consequences of having worker or supervisor in the > supervisor's child specifications? > > Paul I've used the approach of a top supervisor with two children, one manager and one worker supervisor. The manager gets requests for creating a new worker and lets the worker supervisor start it. My main supervisor thus starts these two children: {{one-for-all, 1, 60}, [ {manager, {manager, start_link, []}, permanent, 60, worker, [manager]}, {work_super, {work_super, start_link, []}, permanent, infinity, supervisor, [work_super]} ] } And the work supervisor is just {{one_for_one, 5, 60}, []} In my manager, I then add new workers using the work_super: start_child(Id, Args) -> case supervisor:start_child(work_super, {Id, {work, start_link, Args}, transient, 60*1000, worker, [work]}) of {ok, _Child} -> ok; {ok, _Child, _Info} -> ok; {error, {already_started, _Child}} -> ok; Error -> Error end. And I can stop it stop_child(Id) -> case supervisor:terminate_child(work_super, Id) of ok -> supervisor:delete_child(work_super, Id); Error -> Error end. I am not yet 100% sure if I am interpreting the various start_child results correctly. But this works well for me at the moment. Robby From rtrlists@REDACTED Sat Jan 17 16:25:35 2009 From: rtrlists@REDACTED (Robert Raschke) Date: Sat, 17 Jan 2009 15:25:35 +0000 Subject: [erlang-questions] ODBC driver In-Reply-To: References: Message-ID: <6a3ae47e0901170725n4f5825e8i2ad668998844d72a@mail.gmail.com> On Fri, Jan 16, 2009 at 7:11 PM, Jose Enrique Benitez Jimenez wrote: > Hi, > > I want to connect to an SQL database, I receive the follow error > > 7> odbc:start(). > ok > 8> odbc:connect("DNS:localhost",[]). > {error,"No SQL-driver information available. Connection to database failed."} > > > SQL server 2000 is already intalled, Do I need the ODBC driver or SQL server 2000 have it ?, in the first case, how can i get it?? > (I'm using Windows XP) > You have to specifiy an ODBC DSN. Either you have already set up one using Start ->Administrative Tools -> Data Sources (ODBC), in which case to say something along the lines of odbc:connect("DSN=DataSourceName;UID=login;PWD=password", [{scrollable_cursors, off}]). Or you know the driver, server, database, etc, then you can specifiy the DSN as a connection string (see for example http://www.connectionstrings.com/sql-server#7 ) like this: odbc:connect("Driver={SQL Server};Server=localhost;Database=database;UID=login;PWD=password", [{scrollable_cursors, off}]). I always set scrollable cursors off, since so many odbc drivers don't appear to support that feature, Robby From emmiller@REDACTED Sat Jan 17 18:46:40 2009 From: emmiller@REDACTED (Evan Miller) Date: Sat, 17 Jan 2009 11:46:40 -0600 Subject: [erlang-questions] ANNOUNCE: ErlyDTL (public beta) Message-ID: ErlyDTL is an Erlang implementation of the Django Template Language, a web templating language popular in the Python world. ErlyDTL 0.5.1 represents the first public beta. Download: http://erlydtl.googlecode.com/files/erlydtl-0.5.1.tar.gz Project home: http://code.google.com/p/erlydtl/ Mailing list: http://groups.google.com/group/erlydtl ErlyDTL should be fairly stable. Several developers have contributed to the project in the last year, and ErlyDTL has been running in production on several sites. A suite of tests covers almost all its functionality. We've tried to make ErlyDTL easy to plug into existing frameworks and systems. However, there's still some work to be done in this area. For example, it would be nice if a template could incrementally write its output to a socket, but right now it simply returns an iolist of the complete output. Finally, if you're curious about writing a simple compiler for Erlang/OTP, take a look under the hood of ErlyDTL. ErlyDTL is actually a compiler that outputs a BEAM file for each template file. Of course, there's nothing too fancy here-- just judicious use of Leex and the erl_syntax library. Please direct any questions to the ErlyDTL mailing list (above). From steven.charles.davis@REDACTED Sat Jan 17 18:44:59 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Sat, 17 Jan 2009 11:44:59 -0600 Subject: [erlang-questions] Real basic binary manipulation question In-Reply-To: <4971EB8A.7010705@it.uu.se> References: <1c3be50f0901170530w48d04f8djfdfd637bf219d24a@mail.gmail.com> <4971EB8A.7010705@it.uu.se> Message-ID: <4972191B.1030602@gmail.com> Oh wow! I guess I should at least be thankful I'm beginning to spot where my erlang is plain ugly! I can now see many places where I could improve my code using this approach. I feel a big refactor coming on. Thanks, both of you! /s Per Gustafsson wrote: > Or even more straight-forward: > > -module(zrle). > -export([decompress/1]). > > decompress(Bin) when is_binary(Bin) -> > decompress(Bin, <<>>). > > decompress(<<0, Count, Tail/binary>>, Acc) -> > decompress(Tail, <>); > decompress(<>, Acc) -> > decompress(Tail, <>); > decompress(<<>>, Acc) -> > Acc. > > If you are using at least R12 the performance for this should be ok. > > Per > > Juan Jose Comellas wrote: >> In your function it wasn't clear to me why you were adding the >> 'expand' atom to the destination list T. Maybe something like this >> could do: >> >> >> -module(zrle). >> -export([decompress/1]). >> >> decompress(Bin) when is_binary(Bin) -> >> decompress(Bin, []). >> >> decompress(<<0, Count, Tail/binary>>, Acc) -> >> decompress(Tail, [<<0:(Count * 8)>> | Acc]); >> decompress(<>, Acc) -> >> decompress(Tail, [Head | Acc]); >> decompress(<<>>, Acc) -> >> list_to_binary(lists:reverse(Acc)). >> >> >> e.g. >> >> 1> zrle:decompress(<<1, 0, 5, 2, 3, 4, 0, 3>>). >> <<1,0,0,0,0,0,2,3,4,0,0,0>> >> >> >> >> On Sat, Jan 17, 2009 at 8:46 AM, Steve Davis >> > > wrote: >> >> Problem - to decompress a binary where zeros are run-length encoded. >> The following seems to work but also seems ugly and causes >> unnecessary >> overhead. >> >> %% Decompress binary where Zeros are Run-Length Encoded >> decompress(Bin) when is_binary(Bin) -> >> L = binary_to_list(Bin), >> F = fun(X, [H|T]) when H =:= expand -> lists:duplicate(X, >> 0) ++ T; >> (X, Acc) when X =:= 0 -> [expand] ++ Acc; >> (X, Acc) -> [X] ++ Acc >> end, >> Decompressed = lists:foldl(F, [], L), >> list_to_binary(lists:reverse(lists:flatten(Decompressed))). >> >> Any bids on an improvement? >> >> Thanks for any attention. >> >> Side note: the erlang bit syntax is *amazing* when you actually get >> down to doing something with IP packets >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions@REDACTED >> http://www.erlang.org/mailman/listinfo/erlang-questions >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions@REDACTED >> http://www.erlang.org/mailman/listinfo/erlang-questions > > From ad.sergey@REDACTED Sat Jan 17 22:22:43 2009 From: ad.sergey@REDACTED (Sergey S) Date: Sat, 17 Jan 2009 13:22:43 -0800 Subject: [erlang-questions] Why is decode_packet so fast? Message-ID: Hello. While I was reading about binaries and bit syntax, I decided to make analogue of some standard function dealing with binaries. Just to improve my understanding of how to use it right. My choice was erlang:decode_packet/3. At first I wrote my own decoder. But when I compared it with decode_packet based decoder I saw the following: 1> http_decoder:test(). [{660,667},{210,215}] The first tuple is time spent in my (rather unsophisticated) decoder, the second one is time spent in function that uses decode_packet at it's heart. it appears that people who wrote decode_packet, made it really-really fast. I noted how good decode_packet is and then tried to find out the sources. But didn't find the implementation in /usr/lib/erlang/lib/kernel-2.12.5/src/erlang.erl. So my attempt to find out what made decode_packet so fast failed =) Please, tell me where the implementation of decode_packet is placed. -- Sergey From pfisher@REDACTED Sat Jan 17 22:32:20 2009 From: pfisher@REDACTED (Paul Fisher) Date: Sat, 17 Jan 2009 15:32:20 -0600 Subject: [erlang-questions] Why is decode_packet so fast? In-Reply-To: References: Message-ID: <49724E64.9020701@alertlogic.net> Sergey S wrote: > it appears that people who wrote decode_packet, made it really-really > fast. I noted how good decode_packet is and then tried to find out the > sources. But didn't find the implementation in > /usr/lib/erlang/lib/kernel-2.12.5/src/erlang.erl. So my attempt to > find out what made decode_packet so fast failed =) > > Please, tell me where the implementation of decode_packet is placed. I believe that it is implemented as a built-in function. I would also offer that if you have not compiled your version with HiPE enabled, you should give that a try as it has a good chance of improving the performance of binary decoding type of tasks. -- paul From sysop@REDACTED Sat Jan 17 22:39:36 2009 From: sysop@REDACTED (Matt Stancliff) Date: Sat, 17 Jan 2009 13:39:36 -0800 Subject: [erlang-questions] Why is decode_packet so fast? In-Reply-To: References: Message-ID: <1893AF3C-BC5C-4872-AFB6-CE0F6BB25FFA@mindspring.com> On Jan 17, 2009, at 1:22 PM, Sergey S wrote: > Please, tell me where the implementation of decode_packet is placed. erts/emulator/beam/erl_bif_port.c and erts/emulator/beam/packet_parser.c -Matt -- Matt Stancliff San Jose, CA AIM: seijimr iPhone: 678-591-9337 "The best way to predict the future is to invent it." --Alan Kay From ad.sergey@REDACTED Sat Jan 17 23:06:09 2009 From: ad.sergey@REDACTED (Sergey S) Date: Sat, 17 Jan 2009 14:06:09 -0800 Subject: [erlang-questions] Why is decode_packet so fast? In-Reply-To: <49724E64.9020701@alertlogic.net> References: <49724E64.9020701@alertlogic.net> Message-ID: Hello. > I believe that it is implemented as a built-in function. I think, it means that it isn't possible to make your own decoder as fast as decode_packet using bit syntax (I beleive it can be done in different ways, but didn't try all them)? > I would also offer that if you have not compiled your version with HiPE > enabled, you should give that a try as it has a good chance of improving the > performance of binary decoding type of tasks. Thanks! I've tried and new results are: [{330,358},{170,180}] -- Sergey From ad.sergey@REDACTED Sat Jan 17 23:08:41 2009 From: ad.sergey@REDACTED (Sergey S) Date: Sat, 17 Jan 2009 14:08:41 -0800 Subject: [erlang-questions] Why is decode_packet so fast? In-Reply-To: <1893AF3C-BC5C-4872-AFB6-CE0F6BB25FFA@mindspring.com> References: <1893AF3C-BC5C-4872-AFB6-CE0F6BB25FFA@mindspring.com> Message-ID: Hello. > erts/emulator/beam/erl_bif_port.c and erts/emulator/beam/packet_parser.c It looks like I made a bad shot... =) Thanks. -- Sergey. From hpjcon@REDACTED Fri Jan 16 23:11:01 2009 From: hpjcon@REDACTED (Jan Jacobs) Date: Sat, 17 Jan 2009 00:11:01 +0200 Subject: [erlang-questions] ODBC driver In-Reply-To: References: Message-ID: <497105F5.7010204@mweb.co.za> Hi Jose, Windows XP Pro has by default the "SQL Server" driver installed. To locate and test: - Goto "Start->Settings->Control Panel->Administrative Tools->Data Sources (ODBC)". - Select "System DSN" - Click "Add" - Look for "SQL Server" You need to construct a connection string inorder to instruct the odbcserver to connect to the necessary database, see exaples below. Example MS SQL Server 2000: "Driver={SQL Server};Server=JAN03;Database=MaxMan;Uid=maxman;Pwd=maxmanpassword;" Example MS SQL Express 2005: "Driver={SQL Native Client};Server=JAN03\\SQLEXPRESS, 1450;Database=MaxMan;Uid=maxman;Pwd=maxmanpassword;" Example MySQL: "Driver={MySQL ODBC 3.51 Driver};Server=127.0.0.1;Database=maxman;User=maxman;Password=maxmanpassword;Option=;" Example Firebird: "Driver=Firebird/InterBase(r) driver;Uid=SYSDBA;Pwd=masterkey;DbName=127.0.0.1:c:/projects/DeepBlue/app/MaxMan/temp/MAXMAN.FDB;" For more info on connection strings and connection strings for other DB's see: http://www.connectionstrings.com/ Cheers Jan Jose Enrique Benitez Jimenez wrote: > Hi, > > I want to connect to an SQL database, I receive the follow error > > 7> odbc:start(). > ok > 8> odbc:connect("DNS:localhost",[]). > {error,"No SQL-driver information available. Connection to database failed."} > > > SQL server 2000 is already intalled, Do I need the ODBC driver or SQL server 2000 have it ?, in the first case, how can i get it?? > (I'm using Windows XP) > > Thanks. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > ------------------------------------------------------------------------ > > > No virus found in this incoming message. > Checked by AVG - http://www.avg.com > Version: 8.0.176 / Virus Database: 270.10.8/1898 - Release Date: 2009/01/16 03:09 PM > > From vychodil.hynek@REDACTED Sun Jan 18 14:21:27 2009 From: vychodil.hynek@REDACTED (Hynek Vychodil) Date: Sun, 18 Jan 2009 14:21:27 +0100 Subject: [erlang-questions] Here's hoping we get frames or structs in 2009! In-Reply-To: References: Message-ID: <20090118132128.1FF7C24063@relay.gooddata.com> Your approach have many drawbacks by design. Each set operation have O(N) memory complexity and also O(N) time complexity (Your bisec search is O(logN) but you must copy whole assoc tuple which is O(N)). I don't understand why not use some tree representation which have set operation O(logN) memory and time. You haven't any gain from tuple representaion for get because your get is O(logN) which is same as for tree representations. You can idealy balance tree when you have fixed key set and do not cope with tree rebalance. It shoudl be more worth approach. On Mon, Jan 12, 2009 at 7:25 PM, Christian wrote: > On Mon, Jan 12, 2009 at 00:10, James Hague wrote: > > but the code ends up bulky and contrived. Yeah, we've all discussed > > this for years, so here's hoping there's some movement on this front. > > Syntactically, the version I like the most at the moment is the record > > syntax without a record name: > > > > #{width=1280, height=1024, colors=65536} > > Ponder this approach I implemented: > > 1> Assoc = record:list_to_assoc([foo, bar, baz]). > {{bar,3},{baz,4},{foo,2}} > 2> record:in(baz, Assoc). > 4 > > Basically a map from atoms to integers. I choose to perform binary > search. One can then create a tuple where this Assoc takes the place > of the atom tag in a plain record: > > 3> Rec = record:new(Assoc). > {{{bar,3},{baz,4},{foo,2}},[],[],[]} > > And operations use the atom->integer map to implement basic > manipulations on tuples by field name: > > 4> Rec1 = record:set(baz, x, Rec). > {{{bar,3},{baz,4},{foo,2}},[],[],x} > > 5> record:get(baz, Rec1). > x > > The downside in this implementation of Assoc is that there is going to > be lots of repeated references to new copies of same-valued tuples. > Every copy inserted and taken out of ets will create a new one, as > well as when they are sent between processes using the normal memory > model. > > > But would it be ugly to 'intern' this Assoc into a new first-class > type? A reference counted atom() to integer() map type? Each module > could put the assoc objects it needs in the constant pool so they > would not need to intern the assoc object over and over again. > > > Checking that an assoc contains a number of fields or the tuple > element they're mapped to is efficient enough that it is no worser > compared to the existing non-constant-complexity guards and bifs. > > > I actually cant think of any downside to the approach that is a > problem for the intended use. It just looks very difficult to create a > new type and guards for it, requiring changes to both the compiler and > the vm. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero! Try Good Data now for free: www.gooddata.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ad.sergey@REDACTED Sun Jan 18 16:25:05 2009 From: ad.sergey@REDACTED (Sergey S) Date: Sun, 18 Jan 2009 07:25:05 -0800 Subject: [erlang-questions] Real basic binary manipulation question In-Reply-To: References: Message-ID: Hello. Thanks for this discussion (which was very usefull) and especially for the trick with binary used as an accumulator (decompress2). Here is another implementation (just to have as many variants as possible :) using a deep list as an accumulator: decompress3(Bin) when is_binary(Bin) -> decompress3(Bin, []). decompress3(<<0, Count, Tail/binary>>, Acc) -> decompress3(Tail, [Acc, <<0:(Count * 8)>>]); decompress3(<>, Acc) -> decompress3(Tail, [Acc, Head]); decompress3(<<>>, Acc) -> list_to_binary(Acc). It's slower than decompress2 but a bit faster (and more memory consuming) than decompress1: Eshell V5.6.5 (abort with ^G) 1> c(zrle), zrle:bm(). decompress1: 1520 (1525) decompress2: 1110 (1104) decompress3: 1470 (1477) ok 2> c(zrle, [native]), zrle:bm(). decompress1: 1170 (1193) decompress2: 720 (715) decompress3: 1040 (1047) ok % -HERE-IS-THE-SOURCES----------------------------- -module(zrle). -compile(export_all). bm() -> bm(<<1,0,3,0,4,0,10,0,15,0,150>>, 500000). bm(Bin, N) -> statistics(runtime), statistics(wall_clock), repeat(fun() -> decompress(Bin) end, N), {_, R1} = statistics(runtime), {_, W1} = statistics(wall_clock), repeat(fun() -> decompress2(Bin) end, N), {_, R2} = statistics(runtime), {_, W2} = statistics(wall_clock), repeat(fun() -> decompress3(Bin) end, N), {_, R3} = statistics(runtime), {_, W3} = statistics(wall_clock), io:format("decompress1: ~p (~p)~n", [R1, W1]), io:format("decompress2: ~p (~p)~n", [R2, W2]), io:format("decompress3: ~p (~p)~n", [R3, W3]). repeat(_, 0) -> ok; repeat(Fun, N) -> Fun(), repeat(Fun, N - 1). decompress(Bin) when is_binary(Bin) -> decompress(Bin, []). decompress(<<0, Count, Tail/binary>>, Acc) -> decompress(Tail, [<<0:(Count * 8)>> | Acc]); decompress(<>, Acc) -> decompress(Tail, [Head | Acc]); decompress(<<>>, Acc) -> list_to_binary(lists:reverse(Acc)). decompress2(Bin) when is_binary(Bin) -> decompress2(Bin, <<>>). decompress2(<<0, Count, Tail/binary>>, Acc) -> decompress2(Tail, <>); decompress2(<>, Acc) -> decompress2(Tail, <>); decompress2(<<>>, Acc) -> Acc. decompress3(Bin) when is_binary(Bin) -> decompress3(Bin, []). decompress3(<<0, Count, Tail/binary>>, Acc) -> decompress3(Tail, [Acc, <<0:(Count * 8)>>]); decompress3(<>, Acc) -> decompress3(Tail, [Acc, Head]); decompress3(<<>>, Acc) -> list_to_binary(Acc). -- Sergey From mazen.harake@REDACTED Sun Jan 18 16:30:25 2009 From: mazen.harake@REDACTED (Mazen Harake) Date: Sun, 18 Jan 2009 17:30:25 +0200 Subject: [erlang-questions] trapexit.org: lost lost password link In-Reply-To: <49714874.1090204@ghostgun.com> References: <49714874.1090204@ghostgun.com> Message-ID: <49734B11.1080401@erlang-consulting.com> Hmm, it was good that you pointed this out, you are right, it is somewhat of a mission impossible to find the email address. I'll make sure we handle that asap! meanwhile for reference the address for now is trapexit@REDACTED Regards, /Mazen jm wrote: > The FAQ on the site once you've found it says: > > I've lost my password! > Don't panic! While your password cannot be retrieved it can be reset. To > do this go to the login page and click I've forgotten my password. > Follow the instructions and you should be back online in no time. > > > Help! I've lost the lost password link! Even using a text search on the > word "lost" can't find it. Worse, there doesn't seem to be an obvious > admin contact for the site. So, my question is, > > 1) who should I contact in case of a lost/forgotten password on > trapexit.org? > > > Jeff. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From erlang-questions_efine@REDACTED Sun Jan 18 18:30:51 2009 From: erlang-questions_efine@REDACTED (Edwin Fine) Date: Sun, 18 Jan 2009 12:30:51 -0500 Subject: [erlang-questions] variable argument preprocessor macros In-Reply-To: References: <3dbc6d1c0901131840x57fbb638m995ff1d244181927@mail.gmail.com> Message-ID: <6c2563b20901180930i372fb40eo800466ae7ffce7c3@mail.gmail.com> > well, i have been using exactly the aforementioned thing currently. > however, having a bunch of identical (functionality wise) macros, with > different names, didn't seem very nice... > What about using inline functions declared in the header file? You don't have these problems then. Regards, Ed > > > An alternative would be to use LFE which has proper lisp and scheme > macros. > > If you like writing in lisp. :-) > i have been playing around with scheme a bit, but for now i will pass :o) > > thank you > anupam > -- > In the beginning was the lambda, and the lambda was with Emacs, and > Emacs was the lambda. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From erlang-questions_efine@REDACTED Sun Jan 18 18:50:05 2009 From: erlang-questions_efine@REDACTED (Edwin Fine) Date: Sun, 18 Jan 2009 12:50:05 -0500 Subject: [erlang-questions] Custom supervisor In-Reply-To: <6a3ae47e0901170745j1b76942em9a79a06d09666e04@mail.gmail.com> References: <4DD33013-11C5-456D-B114-93109F440456@kallisys.net> <6a3ae47e0901170745j1b76942em9a79a06d09666e04@mail.gmail.com> Message-ID: <6c2563b20901180950u316de6e8ue9201e18518b707e@mail.gmail.com> Just a thought: instead of trying to pattern match all the possible responses from anything that returns {ok, arg0, arg1,...,argN}, how about using element()? e.g. start_child(Id, Args) -> case supervisor:start_child(work_super, {Id, {work, start_link, Args}, transient, 60*1000, worker, [work]}) of T when T =:= ok; element(1, T) =:= ok -> ok; {error, {already_started, _Child}} -> ok; Error -> Error end. > start_child(Id, Args) -> > case supervisor:start_child(work_super, > {Id, {work, start_link, Args}, > transient, 60*1000, worker, [work]}) of > {ok, _Child} -> > ok; > {ok, _Child, _Info} -> > ok; > {error, {already_started, _Child}} -> > ok; > Error -> > Error > end. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kaiduanx@REDACTED Mon Jan 19 03:35:48 2009 From: kaiduanx@REDACTED (Kaiduan Xie) Date: Sun, 18 Jan 2009 21:35:48 -0500 Subject: [erlang-questions] erlang process schedule Message-ID: Hi, Can anyone give a systematic view on how erlang schedules process? Joe's "Programming Erlang" gives details on how fast an erlang process is created/destroyed; unfortunately it does not elaborate how erlang process is scheduled, and how fast is the process switch. (We all konw thread context switch in C/Java is not cheap) Thanks, kaiduan -------------- next part -------------- An HTML attachment was scrubbed... URL: From gotothere00@REDACTED Mon Jan 19 05:29:43 2009 From: gotothere00@REDACTED (simon00) Date: Sun, 18 Jan 2009 20:29:43 -0800 (PST) Subject: [erlang-questions] a question on leex and yacc usage Message-ID: <21536268.post@talk.nabble.com> I am a newbie to erlang, trying to write a parser for an ip list file as my study excercise as follows: 192.168.1.2; 124.123.4.4; The leex file is as follows: ------------------------------------ Definitions. Dig = [0-9] Rules. ({Dig}{Dig}*) : {token, {integer, YYline, list_to_integer(YYtext)}}. \. : {token, {'.', YYline}}. \; : {token, {';', YYline}}. \s : skip_token. \r : skip_token. \t : skip_token. \n : skip_token. ------------------------------------ The yecc file is as follows: ------------------------------------ Nonterminals iplist ipentry ip. Terminals '/' '-' '.' 'atom' ';'. Rootsymbol iplist. iplist -> ipentry ';' : ['$1']. iplist -> ipentry ';' iplist : ['$1', '$3']. ipentry -> ip : {ip, '$1'}. ipentry -> ip '-' ip : {span, '$1', '$2'}. ipentry -> ip '/' 'atom' : {cidr, '$1', '$2'}. ip -> 'atom' '.' 'atom' '.' 'atom' '.' 'atom' : {'$1', '$2', '$3', '$4'}. ----------------------------------- However, the excution always reports an error as follows: ------------------------------------ 22> parser:file("ip.txt"). ** 1 syntax error before: 192 {error,1} ------------------------------------ Could anybody kindly inform me of this problem? I cannot find any documentation on such like problems. Many thanks! -- View this message in context: http://www.nabble.com/a-question-on-leex-and-yacc-usage-tp21536268p21536268.html Sent from the Erlang Questions mailing list archive at Nabble.com. From vladdu55@REDACTED Mon Jan 19 08:53:01 2009 From: vladdu55@REDACTED (Vlad Dumitrescu) Date: Mon, 19 Jan 2009 08:53:01 +0100 Subject: [erlang-questions] a question on leex and yacc usage In-Reply-To: <21536268.post@talk.nabble.com> References: <21536268.post@talk.nabble.com> Message-ID: <95be1d3b0901182353h7cfdbec7o89489bd651ddc036@mail.gmail.com> Hi, On Mon, Jan 19, 2009 at 05:29, simon00 wrote: > The leex file is as follows: > ({Dig}{Dig}*) : {token, {integer, YYline, list_to_integer(YYtext)}}. > > The yecc file is as follows: > Nonterminals iplist ipentry ip. > Terminals '/' '-' '.' 'atom' ';'. Could it be because the lexer returns an 'integer' token and the parser expects an 'atom' one? best regards, Vlad From masse@REDACTED Mon Jan 19 10:10:44 2009 From: masse@REDACTED (mats cronqvist) Date: Mon, 19 Jan 2009 10:10:44 +0100 Subject: [erlang-questions] Here's hoping we get frames or structs in 2009! In-Reply-To: <3dbc6d1c0901161508p5be6e108w73d4301d8302272a@mail.gmail.com> (Robert Virding's message of "Sat\, 17 Jan 2009 00\:08\:16 +0100") References: <3dbc6d1c0901161508p5be6e108w73d4301d8302272a@mail.gmail.com> Message-ID: <874ozvmzjf.fsf@sterlett.hq.kred> Robert Virding writes: > Something like this could be done for a struct/frame but have a special data > type. In that case it would look like a record but there the "name" field > would be a descriptor showing which fields there are and where in the "tuple" > they are. There would be no need to keep anything in an ets table. i've been playing around with a data structure like this. "Anonymous records", tuples where the first element is a fun describing the fields. E.g. {F,"A","B"} where F = fun(a)->2; (b)->3; (1)->a; (2)->b end. Then this; AR#.a would be element((element(1,AR))(a),AR) == "A" and f(AR#{a="A"}) -> would be f(AR) when element((element(1,AR))(a),AR)=="A" -> etc. mats From corticalcomputer@REDACTED Mon Jan 19 14:19:19 2009 From: corticalcomputer@REDACTED (G.S.) Date: Mon, 19 Jan 2009 05:19:19 -0800 Subject: [erlang-questions] Keyword searching+ Message-ID: <2a67d3ff0901190519v44435d1oa567af1741491810@mail.gmail.com> Hello everyone, The site I'm working on needs to display images that area searchable by using keywords (for example something like Cats AND Dogs...). Do you have any suggestions or know how one can do so in erlang? For example, lets say before uploading the image I attach a bunch of key words to it, lets say in the following manner {[Keyword1...Keywordn],Image} Any suggestions or tips would be appreciated, Regards, -Gene -------------- next part -------------- An HTML attachment was scrubbed... URL: From chsu79@REDACTED Mon Jan 19 15:29:48 2009 From: chsu79@REDACTED (Christian) Date: Mon, 19 Jan 2009 15:29:48 +0100 Subject: [erlang-questions] Keyword searching+ In-Reply-To: <2a67d3ff0901190519v44435d1oa567af1741491810@mail.gmail.com> References: <2a67d3ff0901190519v44435d1oa567af1741491810@mail.gmail.com> Message-ID: > The site I'm working on needs to display images that area searchable by > using keywords (for example something like Cats AND Dogs...). Do you have > any suggestions or know how one can do so in erlang? For example, lets say > before uploading the image I attach a bunch of key words to it, lets say in > the following manner > {[Keyword1...Keywordn],Image} > Any suggestions or tips would be appreciated, This is an inverted index. Same thing search engines uses, except you dont extract the search terms from within the documents, but supply them from the "outside". invert({Ks, Image}) -> [{K, Image} || K <- Ks]. %% invert({[a,b,c,d], imageid}) gives you %% [{a,imageid},{b,imageid},{c,imageid},{d,imageid}] If you invert every image to a list like this, then you can build your inverted index from the lists. You probably need to store this on disc because they grow pretty large. I'm going to use a dict though. update_index(KIs, Index0) -> lists:foldl(fun({K, I}, Acc) -> dict:append(K, I, Acc) end, Index0, KIs). And lets say that we want to build up this inverted index from a set of documents that look like this: Docs = [{[feathers,beak,taste_like_chicken],duck}, {[feathers,teeth,extinct],dinosaur}, {[beak,taste_like_chicken],platypus}]. build_index(Docs) -> Index = dict:new(), lists:foldl(fun (Doc, Acc) -> update_index(invert(Doc), Acc) end, Index, Docs). Then we can get this: 4> dict:to_list(index:build_index(Docs)). [{feathers,[duck,dinosaur]}, {extinct,[dinosaur]}, {teeth,[dinosaur]}, {beak,[duck,platypus]}, {taste_like_chicken,[duck,platypus]}] Thus you can get a list of images that have a given keyword associated with it. Set operations allow you to to find intersections such as Images that has Keyword1 & Keyword2, or subtractions as in Keyword1 & not Keyword2. There. Now you too can be google. http://gist.github.com/49008 From vladdu55@REDACTED Mon Jan 19 16:12:35 2009 From: vladdu55@REDACTED (Vlad Dumitrescu) Date: Mon, 19 Jan 2009 16:12:35 +0100 Subject: [erlang-questions] [poll] Test frameworks Message-ID: <95be1d3b0901190712q49619a6eqaada185a275b0be@mail.gmail.com> Hello everybody, I am doing preliminary work on integrating test frameworks with Erlide and I would like to ask for your feedback regarding the usage of the test frameworks in your projects. I am primarily considering unit and module testing. 1) What frameworks do you use? a. Common test b. eUnit c. QuickCheck d. other public framework (please mention which) e. other private framework 2) If you answered "e" above, is this framework using similar concepts to "xUnit" or is it something completely different? Does it support introspection (for example can one ask it which tests will be run, or the dependencies between tests)? Are they based on old versions of a or b? 3) For a, b and c, are you using these frameworks as such, or do you have a wrapper around them, to allow for your specific needs? For example: custom loggers, adapting to other ways to define the tests (like reading configuration from an XML file), mocking functionality, etc. The plan that I have so far is to build a generic test UI in Eclipse and use that to connect to the different frameworks. For this to work, there has to be some level of commonality and I'm trying to find out how high that level is. I might return later with more questions. Thank you in advance for your help, Vlad From adam@REDACTED Mon Jan 19 16:52:17 2009 From: adam@REDACTED (Adam Lindberg) Date: Mon, 19 Jan 2009 15:52:17 +0000 (GMT) Subject: [erlang-questions] [poll] Test frameworks In-Reply-To: <95be1d3b0901190712q49619a6eqaada185a275b0be@mail.gmail.com> Message-ID: <4034696.44241232380337852.JavaMail.root@zimbra> Using vanilla b and c. Just added some small scripts running the tests. Using both by compiling header files with tests into the real module, when debug compiling. Works well so far and I can test private functions easily which is a big goal for me with unit testing and TDD. Cheers, Adam ----- "Vlad Dumitrescu" wrote: > Hello everybody, > > I am doing preliminary work on integrating test frameworks with > Erlide > and I would like to ask for your feedback regarding the usage of the > test frameworks in your projects. I am primarily considering unit and > module testing. > > 1) What frameworks do you use? > a. Common test > b. eUnit > c. QuickCheck > d. other public framework (please mention which) > e. other private framework > > 2) If you answered "e" above, is this framework using similar > concepts > to "xUnit" or is it something completely different? Does it support > introspection (for example can one ask it which tests will be run, or > the dependencies between tests)? Are they based on old versions of a > or b? > > 3) For a, b and c, are you using these frameworks as such, or do you > have a wrapper around them, to allow for your specific needs? For > example: custom loggers, adapting to other ways to define the tests > (like reading configuration from an XML file), mocking functionality, > etc. > > The plan that I have so far is to build a generic test UI in Eclipse > and use that to connect to the different frameworks. For this to > work, > there has to be some level of commonality and I'm trying to find out > how high that level is. I might return later with more questions. > > Thank you in advance for your help, > Vlad > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From adam@REDACTED Mon Jan 19 16:54:35 2009 From: adam@REDACTED (Adam Lindberg) Date: Mon, 19 Jan 2009 15:54:35 +0000 (GMT) Subject: [erlang-questions] Why is decode_packet so fast? In-Reply-To: Message-ID: <16871805.44271232380475402.JavaMail.root@zimbra> Just for the record, a built-in function is a function implemented in C straight in the virtual machine. That is why they are so fast. You can make your own, but that would require patching the VM. Cheers, Adam ----- "Sergey S" wrote: > Hello. > > > erts/emulator/beam/erl_bif_port.c and > erts/emulator/beam/packet_parser.c > > It looks like I made a bad shot... =) > > Thanks. > > -- > Sergey. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From jan@REDACTED Mon Jan 19 16:19:30 2009 From: jan@REDACTED (Jan Lehnardt) Date: Mon, 19 Jan 2009 16:19:30 +0100 Subject: [erlang-questions] erlang process schedule In-Reply-To: References: Message-ID: <6BA300A5-060B-42F2-B865-05DA4DB16C85@apache.org> On 19 Jan 2009, at 03:35, Kaiduan Xie wrote: > Hi, > > Can anyone give a systematic view on how erlang schedules process? > Joe's "Programming Erlang" gives details on how fast an erlang > process is created/destroyed; unfortunately it does not elaborate > how erlang process is scheduled, and how fast is the process switch. > (We all konw thread context switch in C/Java is not cheap) Processes run for a fixed number of "reductions" until they cat stopped and the next one gets executed. This happens round-robin. There is one optimisation that when a process sends a message to another one, the sending process gets stopped and the remaining reductions go to the called process. Switching processes is as fast as increasing a pointer in the array that keeps track of all processes. Cheers Jan -- From mickael.remond@REDACTED Mon Jan 19 17:01:56 2009 From: mickael.remond@REDACTED (=?UTF-8?Q?Micka=C3=ABl_R=C3=A9mond?=) Date: Mon, 19 Jan 2009 17:01:56 +0100 Subject: [erlang-questions] [poll] Test frameworks In-Reply-To: <95be1d3b0901190712q49619a6eqaada185a275b0be@mail.gmail.com> References: <95be1d3b0901190712q49619a6eqaada185a275b0be@mail.gmail.com> Message-ID: Hello Vlad, We use b and c primarily. Le 19 janv. 09 ? 16:12, Vlad Dumitrescu a ?crit : > Hello everybody, > > I am doing preliminary work on integrating test frameworks with Erlide > and I would like to ask for your feedback regarding the usage of the > test frameworks in your projects. I am primarily considering unit and > module testing. > > 1) What frameworks do you use? > a. Common test > b. eUnit > c. QuickCheck > d. other public framework (please mention which) > e. other private framework > > 2) If you answered "e" above, is this framework using similar concepts > to "xUnit" or is it something completely different? Does it support > introspection (for example can one ask it which tests will be run, or > the dependencies between tests)? Are they based on old versions of a > or b? > > 3) For a, b and c, are you using these frameworks as such, or do you > have a wrapper around them, to allow for your specific needs? For > example: custom loggers, adapting to other ways to define the tests > (like reading configuration from an XML file), mocking functionality, > etc. > > The plan that I have so far is to build a generic test UI in Eclipse > and use that to connect to the different frameworks. For this to work, > there has to be some level of commonality and I'm trying to find out > how high that level is. I might return later with more questions. > > Thank you in advance for your help, > Vlad > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- Micka?l R?mond http://www.process-one.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From freza@REDACTED Mon Jan 19 18:23:33 2009 From: freza@REDACTED (Jachym Holecek) Date: Mon, 19 Jan 2009 18:23:33 +0100 Subject: [erlang-questions] Yet Another Web Server In-Reply-To: References: Message-ID: <20090119172333.GA7670@hanele> # Sergey S 2009-01-10: > > I want include a web server to my Erlang application, can I do this with YAWS? > > Maybe it will be better to use mochiweb instead of Yaws? I can confirm mochiweb was extremely pleasant to use as an embedded HTTP server for a simple testing application. Just my two cents. -- Jachym From ad.sergey@REDACTED Tue Jan 20 00:15:08 2009 From: ad.sergey@REDACTED (Sergey S) Date: Mon, 19 Jan 2009 15:15:08 -0800 Subject: [erlang-questions] How to get binaries when using {packet, http} Message-ID: Hello. I discovered that no matter which type of incoming data you choose (binary/list), all the data is delivered as lists. Is there a way to get binaries instead of lists? If not, is this behaviour going to be changed? In other words, will there be a way to get binaries using {packet, http}? Thanks. -- Sergey From japerk@REDACTED Tue Jan 20 00:39:23 2009 From: japerk@REDACTED (Jacob Perkins) Date: Mon, 19 Jan 2009 15:39:23 -0800 Subject: [erlang-questions] erlang-questions Digest, Vol 20, Issue 49 In-Reply-To: References: Message-ID: > The site I'm working on needs to display images that area searchable by > using keywords (for example something like Cats AND Dogs...). Do you have > any suggestions or know how one can do so in erlang? For example, lets say > before uploading the image I attach a bunch of key words to it, lets say in > the following manner > {[Keyword1...Keywordn],Image} Like Christian said, you need an inverted index, where each keywords points to a list of image ids. How you do it really depends on the number of keywords and images you are dealing with. Here's two suggestions. 1) Simple set table with tuples like {keyword, [image_id]} 2) Ordered set table with tuples like {{keyword, image_id}, value} The benefit of #2 is that every record is very small so it can work with a large number of image_ids, and since the table is an ordered_set, you can quickly get all the image_ids for a single keyword. The extra value can be whatever you want: metadata, score/importance, whatever. Once you have a list for each keyword, you can do a set intersection. Here's some wikipedia articles with deeper info. http://en.wikipedia.org/wiki/Index_(search_engine) http://en.wikipedia.org/wiki/Information_retrieval Jacob -------------- next part -------------- An HTML attachment was scrubbed... URL: From dmitriy.kargapolov@REDACTED Tue Jan 20 01:37:46 2009 From: dmitriy.kargapolov@REDACTED (Dmitriy Kargapolov) Date: Mon, 19 Jan 2009 19:37:46 -0500 Subject: [erlang-questions] time-limited mnesia operations Message-ID: <63caf42f0901191637u244f786do13dc9d3124fdcf43@mail.gmail.com> Hi, We have to limit in time heavy set of mnesia updates. If update or load was not completed in scheduled period of time, it just does not make sense to continue database operation, wasting resources. We'd like to break process in that case and make sure database will not be broken (but it may be inconsistent from application point of view), and will be ready for future cleanup and load. I guess this could be easy to implement in transactional context, but I need this to be done in dirty context as well, including dirty_sync. I could come up with something like this: Pid = spawn_link( fun() -> mnesia:dirty_write(Record), ... mnesia:dirty_write(Record) end ), timer:exit_after(Time, Pid, timeout). But I'm not sure how much atomic is mnesia:dirty_write call, wouldn't be mnesia broken on some lower level if process Pid get signal in the middle of write operation. More complex case would be use of mnesia:sync_dirty() call and at least two nodes. Does anybody has experience of safe breaking "hanging" updates? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tony@REDACTED Tue Jan 20 05:35:05 2009 From: tony@REDACTED (Tony Arcieri) Date: Mon, 19 Jan 2009 21:35:05 -0700 Subject: [erlang-questions] Defining a module whose functions are locally available in any scope Message-ID: I have a slightly nonstandard usage of Erlang (i.e. http://reia-lang.org/where I'm trying to implement a set of "main" functions) and would like to define a module whose functions are locally available in any scope, ala the "erlang" module. Is it possible to do this? -- Tony Arcieri medioh.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From corticalcomputer@REDACTED Tue Jan 20 08:31:06 2009 From: corticalcomputer@REDACTED (G.S.) Date: Mon, 19 Jan 2009 23:31:06 -0800 Subject: [erlang-questions] Uploading files to an Erlang website, and Captcha. Message-ID: <2a67d3ff0901192331t535cca95yadea25d8ed5d117@mail.gmail.com> Hello again everyone, My website is built on Erlang, and though right now it's based on Inets, in deployment it will be mochiweb. Anyone here has experience and knows or can suggest how one would use Captcha in Erlang? or/and how I can allow users to upload files to my website if it's built on mochiweb or Inets? Regards, -Gene -------------- next part -------------- An HTML attachment was scrubbed... URL: From mjtruog@REDACTED Tue Jan 20 09:09:14 2009 From: mjtruog@REDACTED (Michael Truog) Date: Tue, 20 Jan 2009 00:09:14 -0800 Subject: [erlang-questions] Uploading files to an Erlang website, and Captcha. In-Reply-To: <2a67d3ff0901192331t535cca95yadea25d8ed5d117@mail.gmail.com> References: <2a67d3ff0901192331t535cca95yadea25d8ed5d117@mail.gmail.com> Message-ID: <497586AA.4090500@gmail.com> It might be easiest to use Imagemagick to create a cache of captcha images. See post here for an example: http://studio.imagemagick.org/pipermail/magick-users/2007-January/018929.html G.S. wrote: > Hello again everyone, > > My website is built on Erlang, and though right now it's based on > Inets, in deployment it will be mochiweb. Anyone here has experience > and knows or can suggest how one would use Captcha in Erlang? or/and > how I can allow users to upload files to my website if it's built on > mochiweb or Inets? > > Regards, > -Gene > ------------------------------------------------------------------------ > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From gijsbert_de_haan@REDACTED Tue Jan 20 09:28:19 2009 From: gijsbert_de_haan@REDACTED (Gijsbert de Haan) Date: Tue, 20 Jan 2009 09:28:19 +0100 Subject: [erlang-questions] Uploading files to an Erlang website, and Captcha. In-Reply-To: <2a67d3ff0901192331t535cca95yadea25d8ed5d117@mail.gmail.com> References: <2a67d3ff0901192331t535cca95yadea25d8ed5d117@mail.gmail.com> Message-ID: <1232440100.5494.1295714457@webmail.messagingengine.com> http://recaptcha.net/ is a very good service that does most of the work for you. You include some html and you get the validity answer back in a form field. Gijsbert On Mon, 19 Jan 2009 23:31:06 -0800, "G.S." said: > Hello again everyone, > > My website is built on Erlang, and though right now it's based on Inets, in > deployment it will be mochiweb. Anyone here has experience and knows or can > suggest how one would use Captcha in Erlang? or/and how I can allow users to > upload files to my website if it's built on mochiweb or Inets? > > Regards, > -Gene From vychodil.hynek@REDACTED Tue Jan 20 10:13:39 2009 From: vychodil.hynek@REDACTED (Hynek Vychodil) Date: Tue, 20 Jan 2009 10:13:39 +0100 Subject: [erlang-questions] Defining a module whose functions are locally available in any scope In-Reply-To: References: Message-ID: <20090120091342.50EEF2406D@relay.gooddata.com> You can use -import() or -include(). .hrl with in-lined functions or its combination and add it in each reia scope/module. P.S.: How you will deal with GC of objects when implementaed as processes? I have same problem with iterators when try implement as J. A. sugest do it as process. 2009/1/20 Tony Arcieri > I have a slightly nonstandard usage of Erlang (i.e. http://reia-lang.org/where I'm trying to implement a set of "main" functions) and would like to > define a module whose functions are locally available in any scope, ala the > "erlang" module. > > Is it possible to do this? > > -- > Tony Arcieri > medioh.com > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero! Try Good Data now for free: www.gooddata.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From corticalcomputer@REDACTED Tue Jan 20 10:34:17 2009 From: corticalcomputer@REDACTED (G.S.) Date: Tue, 20 Jan 2009 01:34:17 -0800 Subject: [erlang-questions] Uploading files to an Erlang website, and Captcha. In-Reply-To: <1232440100.5494.1295714457@webmail.messagingengine.com> References: <2a67d3ff0901192331t535cca95yadea25d8ed5d117@mail.gmail.com> <1232440100.5494.1295714457@webmail.messagingengine.com> Message-ID: <2a67d3ff0901200134p7785cbfk8a475412ae5e7975@mail.gmail.com> Thank you, Both answers will work great, I think I'll go with the first one though, since it's direct, and I can do everything from my own machine rather than rely on another. Any ideas on how I can allow others upload a file to my server, lets say if I'm using Mochiweb or Inets? The idea is to sort of have the same thing as an attachment in Emails, a directory is provided, and the file is uploaded to my server. Regards, -Gene On Tue, Jan 20, 2009 at 12:28 AM, Gijsbert de Haan < gijsbert_de_haan@REDACTED> wrote: > http://recaptcha.net/ is a very good service that does most of the work > for you. > You include some html and you get the validity answer back in a form > field. > > Gijsbert > > On Mon, 19 Jan 2009 23:31:06 -0800, "G.S." > said: > > Hello again everyone, > > > > My website is built on Erlang, and though right now it's based on Inets, > in > > deployment it will be mochiweb. Anyone here has experience and knows or > can > > suggest how one would use Captcha in Erlang? or/and how I can allow users > to > > upload files to my website if it's built on mochiweb or Inets? > > > > Regards, > > -Gene > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sverker@REDACTED Tue Jan 20 11:26:47 2009 From: sverker@REDACTED (Sverker Eriksson) Date: Tue, 20 Jan 2009 11:26:47 +0100 Subject: [erlang-questions] How to get binaries when using {packet, http} In-Reply-To: References: Message-ID: <4975A6E7.10509@erix.ericsson.se> No, there is currently no way to get the "strings" in the http-tuples as binaries instead of lists. The obvious combinations of options to achieve that would be [binary,{packet,http}]. But due to fear of breaking running applications (such as Yaws and Mochiweb) it was not done when {packet, http} was documented and made official. Consider it an invalid combination and do not use it. No decision has been made about introducing http-binaries in this or any other way. /Sverker, Erlang/OTP Ericsson Sergey S wrote: > Hello. > > I discovered that no matter which type of incoming data you choose > (binary/list), all the data is delivered as lists. > > Is there a way to get binaries instead of lists? > > If not, is this behaviour going to be changed? In other words, will > there be a way to get binaries using {packet, http}? > > Thanks. > > -- > Sergey > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > > From hakan@REDACTED Tue Jan 20 14:02:35 2009 From: hakan@REDACTED (Hakan Mattsson) Date: Tue, 20 Jan 2009 14:02:35 +0100 (CET) Subject: [erlang-questions] time-limited mnesia operations In-Reply-To: <63caf42f0901191637u244f786do13dc9d3124fdcf43@mail.gmail.com> References: <63caf42f0901191637u244f786do13dc9d3124fdcf43@mail.gmail.com> Message-ID: On Mon, 19 Jan 2009, Dmitriy Kargapolov wrote: > Hi, > We have to limit in time heavy set of mnesia updates. If update or load was > not completed in scheduled period of time, it just does not make sense to > continue database operation, wasting resources. We'd like to break process > in that case and make sure database will not be broken (but it may be > inconsistent from application point of view), and will be ready for future > cleanup and load. > I guess this could be easy to implement in transactional context, but I need > this to be done in dirty context as well, including dirty_sync. > I could come up with something like this: > Pid = spawn_link( fun() -> > mnesia:dirty_write(Record), > ... > mnesia:dirty_write(Record) > end ), > timer:exit_after(Time, Pid, timeout). > But I'm not sure how much atomic is mnesia:dirty_write call, wouldn't be > mnesia broken on some lower level if process Pid get signal in the middle of > write operation. > More complex case would be use of mnesia:sync_dirty() call and at least two > nodes. > Does anybody has experience of safe breaking "hanging" updates? > Thanks. Dirty updates should be avoided as far as possible as they may leave the database in an inconsistent state. Use transactions if you can afford them. They are safe. If you persist in using dirty updates, you may improve your code example a little by not killing the process in the middle of the dirty update: Ref = make_ref(), Pid = spawn_link( fun() -> mnesia:dirty_write(Record), ... receive {Ref, safe_exit, Reason} -> exit(Reason) end, ... mnesia:dirty_write(Record), ... receive {Ref, safe_exit, Reason} -> exit(Reason) end, ... mnesia:dirty_write(Record) end ), erlang:send_after:exit_after(Time, Pid, {Ref, safe_exit, timeout}). /H?kan --- H?kan Mattsson (uabhams) Erlang/OTP, Ericsson AB From james.hague@REDACTED Tue Jan 20 16:15:42 2009 From: james.hague@REDACTED (James Hague) Date: Tue, 20 Jan 2009 09:15:42 -0600 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch Message-ID: I proposed this several years ago, but now that there seems to be quite a bit of momentum for improving the language and implementation, I'm revising it. It's a library tweak, so no formal EEP. If anyone wants a real EEP, let me know. lists:keysearch/3 is used for searching a list of tuples. It returns two possible values: * 'false' if a tuple containing the desired key is not found * {value, Tuple} if a tuple is found. Wrapping the result in a tagged tuple is not needed. It causes pointless memory allocation and code to check the result. In fact, it's more efficient to check for this pattern: {_, Tuple} than to include the "value" atom. I would like to propose the addition of lists:keyfind/3, which is identical in structure to lists:keysearch/3, except that it returns either 'false' or the found tuple, with no additional wrapping of the result. This can be trivially added to the lists module: keyfind(K, N, L) -> case keysearch(K, N, L) of {_, Tuple} -> Tuple; X -> X end. But ideally it would be a BIF (like lists:keysearch) to avoid construction of the tagged tuple. At the moment, association lists and the "key" functions are one of the best alternatives to lightweight dictionaries. With this proposed change, they'd be even lighter weight and simpler to use. From mog-lists@REDACTED Tue Jan 20 16:21:07 2009 From: mog-lists@REDACTED (Matthew O'Gorman) Date: Tue, 20 Jan 2009 09:21:07 -0600 Subject: [erlang-questions] Uploading files to an Erlang website, and Captcha. In-Reply-To: <2a67d3ff0901200134p7785cbfk8a475412ae5e7975@mail.gmail.com> References: <2a67d3ff0901192331t535cca95yadea25d8ed5d117@mail.gmail.com> <1232440100.5494.1295714457@webmail.messagingengine.com> <2a67d3ff0901200134p7785cbfk8a475412ae5e7975@mail.gmail.com> Message-ID: <550d55060901200721y59e8850ah94c8200099b1c3f3@mail.gmail.com> recaptcha implementation in erlang -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ed_recaptcha.erl Type: text/x-erlang Size: 1430 bytes Desc: not available URL: From mikpe@REDACTED Tue Jan 20 17:11:33 2009 From: mikpe@REDACTED (Mikael Pettersson) Date: Tue, 20 Jan 2009 17:11:33 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: References: Message-ID: <18805.63413.370322.869437@harpo.it.uu.se> James Hague writes: > I proposed this several years ago, but now that there seems to be > quite a bit of momentum for improving the language and implementation, > I'm revising it. It's a library tweak, so no formal EEP. If anyone > wants a real EEP, let me know. > > lists:keysearch/3 is used for searching a list of tuples. It returns > two possible values: > > * 'false' if a tuple containing the desired key is not found > * {value, Tuple} if a tuple is found. > > Wrapping the result in a tagged tuple is not needed. It causes > pointless memory allocation and code to check the result. In fact, > it's more efficient to check for this pattern: > > {_, Tuple} > > than to include the "value" atom. > > I would like to propose the addition of lists:keyfind/3, which is > identical in structure to lists:keysearch/3, except that it returns > either 'false' or the found tuple, with no additional wrapping of the > result. This can be trivially added to the lists module: > > keyfind(K, N, L) -> > case keysearch(K, N, L) of > {_, Tuple} -> Tuple; > X -> X > end. > > But ideally it would be a BIF (like lists:keysearch) to avoid > construction of the tagged tuple. At the moment, association lists > and the "key" functions are one of the best alternatives to > lightweight dictionaries. With this proposed change, they'd be even > lighter weight and simpler to use. I totally agree with this suggestion. From mikael@REDACTED Tue Jan 20 17:26:00 2009 From: mikael@REDACTED (Mikael Lixenstrand) Date: Tue, 20 Jan 2009 17:26:00 +0100 Subject: [erlang-questions] sctp_peer_addr_params Message-ID: I'm trying to change the sack delay in my sctp application {ok,Socket} = gen_sctp:open([{ip, ServerIPAddress}, {port, ServerPort}] ++ [{sctp_peer_addr_params, #sctp_paddrparams{ assoc_id = 0, address = {ServerIPAddress ,ServerPort} ,sackdelay = 400}}, {mode, binary}, {active, false}, {sctp_events,#sctp_event_subscribe{address_event = false, shutdown_event=false}}]), I tried several different approaches but with the same result: Error in process <0.7100.1> on node 'mikael@REDACTED' with exit value: {badarg,[{gen_sctp,open,[[{ip,{10,70,160,17}},{port,3868},{sctp_peer_addr_params,{sctp_paddrparams,0,{{10,70,160,17},3868},200,5,600,400,[]}},{mode,binary},{active,false},{sctp_events,{sctp_event_subscribe,undefined,undefined,false,undefined,undefined... Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From richardc@REDACTED Tue Jan 20 17:36:48 2009 From: richardc@REDACTED (Richard Carlsson) Date: Tue, 20 Jan 2009 17:36:48 +0100 Subject: [erlang-questions] new version of file_monitor.erl - beta testers wanted In-Reply-To: <49692497.7030602@it.uu.se> References: <49692497.7030602@it.uu.se> Message-ID: <4975FDA0.8040601@it.uu.se> The blocking bug that Vlad Dumitrescu found was due to the handling of atime on Windows, so I have redesigned the polling to avoid any dependance on such things. It now ought to work on all platforms, and calls should never block. /Richard Richard Carlsson wrote: > I've been rewriting my file monitor module: it's still polling only, but > now it's a gen_server, supports recursive monitoring, and is documented: > http://svn.process-one.net/contribs/trunk/eunit/doc/file_monitor.html. > > The source code is here (it lives in the eunit project at present): > http://svn.process-one.net/contribs/trunk/eunit/src/file_monitor.erl > > There is also an accompanying eunit test suite module: > http://svn.process-one.net/contribs/trunk/eunit/src/file_monitor_tests.erl > > Any feedback (bugs, usability, performance, documentation) is welcome. > > I'll try to get it into OTP if it seems to be useful enough. The > performance is fairly good; I've tried recursive monitoring on my entire > OTP development tree containing something like 18 thousand files. > > /Richard From tony@REDACTED Tue Jan 20 20:13:34 2009 From: tony@REDACTED (Tony Arcieri) Date: Tue, 20 Jan 2009 12:13:34 -0700 Subject: [erlang-questions] Defining a module whose functions are locally available in any scope In-Reply-To: <20090120091342.49B5C24065@relay.gooddata.com> References: <20090120091342.49B5C24065@relay.gooddata.com> Message-ID: On Tue, Jan 20, 2009 at 2:13 AM, Hynek Vychodil wrote: > You can use -import() or -include(). .hrl with in-lined functions or its > combination and add it in each reia scope/module. > I was hoping for a better solution than that. Specifically I would like to support code change for the "main" module. > P.S.: How you will deal with GC of objects when implementaed as processes? > I have same problem with iterators when try implement as J. A. sugest do it > as process. > Objects aren't automatically garbage collected when they (or rather their pids) go out of scope. Obviously this is a departure from OO languages most people are used to and will require a bit of a paradigm shift on the user's part. -- Tony Arcieri medioh.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From erlang@REDACTED Tue Jan 20 21:15:43 2009 From: erlang@REDACTED (Dominic Williams) Date: Tue, 20 Jan 2009 21:15:43 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <18805.63413.370322.869437@harpo.it.uu.se> References: <18805.63413.370322.869437@harpo.it.uu.se> Message-ID: <497630EF.7080108@dominicwilliams.net> Mikael Pettersson a ?crit : > James Hague writes: > > [???] > >> I would like to propose the addition of >> lists:keyfind/3, which is identical in structure to >> lists:keysearch/3, except that it returns either >> 'false' or the found tuple, with no additional wrapping >> of the result. This can be trivially added to the >> lists module: > > [...] > > I totally agree with this suggestion. +1 Regards, Dominic Williams From vladdu55@REDACTED Tue Jan 20 21:47:43 2009 From: vladdu55@REDACTED (Vlad Dumitrescu) Date: Tue, 20 Jan 2009 21:47:43 +0100 Subject: [erlang-questions] new feature suggestions Message-ID: <95be1d3b0901201247p6155629byedd94ce434d6fbb0@mail.gmail.com> Hi, I wonder if anyone else thinks it might be useful to set up a free account at uservoice.com and gather all the suggestions for improvements and new features there. The idea is that people can suggest features and everyone gets only 10 votes. (Registration is not required) I thing it would be interesting to see all the suggestions in one place and how everybody prioritizes them. I for one don't like to send emails to the list with "+1"s, and maybe there are others that would make their votes heard (pun intended). best regards, Vlad From ad.sergey@REDACTED Wed Jan 21 00:17:34 2009 From: ad.sergey@REDACTED (Sergey S) Date: Tue, 20 Jan 2009 15:17:34 -0800 Subject: [erlang-questions] How to properly declare a special process in supervisor's child specification? Message-ID: Hello. Saying "special process" I mean a process implemented using proc_lib/sys facilities as illustrated in OTP Design Principles. What should I use in "Modules" placeholder of child specification: child_spec() = {_, _, _, _, _, Modules} [Module] or dynamic? erl -man supervisor doesnt' give the answer: -------------------8<------------------- "As a rule of thumb Modules should be a list with one element [Module], where Module is the callback module, if the child process is a >>> supervisor, gen_server or gen_fsm <<<. If the child process is an >>> event manager (gen_event) <<< with a dynamic set of callback modules, Modules should be dynamic." -------------------8<------------------- But my process isn't supervisor, gen_server, gen_fsm nor gen_event. But it's implemented to work like gen_server... OTP Design Principles also says nothing about that (or at least I didn't find anything making this clear) I'm using "dynamic" now, but I'm not sure that it's right. -- Sergey From ad.sergey@REDACTED Wed Jan 21 01:03:27 2009 From: ad.sergey@REDACTED (Sergey S) Date: Tue, 20 Jan 2009 16:03:27 -0800 Subject: [erlang-questions] Finding a way to get function name from local function reference Message-ID: Hello. I'm going to write a simple benchmark utility taking function references and then writing results with corresponding function names. What I'm looking for is the way to get readable function name at runtime. Here is pseudo code: get_name(fun some_mod:some_fun/0) -> some_fun get_name(fun some_fun/0) -> some_fun I took a look at "erl -man erlang" to find out what I can use in this case. erlang:fun_info(Fun, name) seems useful but it works only for exported function references: % erlang:fun_info/2 will return the readable name: {name, some_fun}. That is what I want to get. erlang:fun_info(fun some_module:some_fun/0, name) But it doesn't work for local function references (I've checked): % Note that 'some_module' is omitted. This function will return something like {name,'-test/0-fun-0-'} which is incomprehensible to me erlang:fun_info(fun some_fun/0, name). With local function references I have to use something other... Is there a simple way to get the name of the function? -- Sergey From adrianob@REDACTED Wed Jan 21 04:20:57 2009 From: adrianob@REDACTED (Adriano Bonat) Date: Wed, 21 Jan 2009 01:20:57 -0200 Subject: [erlang-questions] Comet server broadcasting messages to 40k clients Message-ID: <6bb4c8cb0901201920k30d22c78m2458eaa9ce71ec9c@mail.gmail.com> Hi, I implemented a simple Comet server using gen_tcp (code follows below this text), and I'm doing tests with 40k connected clients. With a certain event, a message will be broadcasted to all connected clients, in my current implementation you just have to access the URI "/send". The current problem is that the first connected client will receive the message after ~5s (in my implementation a new client goes in the list's head), and this time is so high compared to a C version of the server. I tried to understand where time is being spent using tools like eprof and fprof, but I'm not that experienced trying to understand their results. This makes me think if I'm doing something wrong, if I can optimize it in some way... or if this is the normal overhead imposed by running on top of a VM... Any ideas? Thanks. -module(myhttpd). -compile(export_all). -define(LISTEN_PORT, 8000). -define(LISTEN_OPTS, [list, {packet, 0}, {keepalive, true}, {active, true}]). start() -> register(router, spawn(fun handle_connections/0)), {ok, Listen} = gen_tcp:listen(?LISTEN_PORT, ?LISTEN_OPTS), spawn(fun() -> accept_connection(Listen) end). accept_connection(Listen) -> {ok, Socket} = gen_tcp:accept(Listen), router ! {accepted, Socket}, gen_tcp:controlling_process(Socket, whereis(router)), accept_connection(Listen). handle_connections() -> handle_connections([]). handle_connections(Sockets) -> receive {accepted, Socket} -> io:format("Just accepted ~p~n", [Socket]), handle_connections([Socket|Sockets]); {tcp, Socket, "GET /send" ++ _T} -> io:format("Sending messages.. ~n", []), TStart = now(), spawn(fun() -> lists:foreach(fun(S) -> send_chunk(S, io_lib:format("(~b usecs) Hello world!
", [timer:now_diff(now(), TStart)])) end, Sockets) end), gen_tcp:send(Socket, "HTTP/1.1 200 OK\r\n\r\nDone."), gen_tcp:close(Socket), handle_connections(Sockets -- [Socket]); {tcp_closed, Socket} -> io:format("Closed connection ~p~n", [Socket]), handle_connections(Sockets -- [Socket]); {tcp, Socket, X} -> io:format("Rcved: ~p~n", [X]), start_response(Socket), handle_connections(Sockets); {numclients} -> io:format("Num clients: ~p~n", [length(Sockets)]), handle_connections(Sockets); Any -> io:format("Just got ~p~n", [Any]), handle_connections(Sockets) end. start_response(Socket) -> gen_tcp:send(Socket, "HTTP/1.1 200 OK\r\nContent-type: text/html;charset=utf-8\r\nTransfer-encoding: chunked\r\n\r\n"). end_response(Socket) -> gen_tcp:send(Socket, "0\r\n\r\n"). send_chunk(Socket, Chunk) -> gen_tcp:send(Socket, io_lib:format("~.16b\r\n~s\r\n", [iolist_size(Chunk), Chunk])). From steven.charles.davis@REDACTED Wed Jan 21 05:07:35 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Tue, 20 Jan 2009 20:07:35 -0800 (PST) Subject: [erlang-questions] Finding a way to get function name from local function reference In-Reply-To: References: Message-ID: <006cb7fc-22f3-455f-95c3-ada2e5725ad1@s1g2000prg.googlegroups.com> Hi Sergey, I think you may find it easiest to use "apply" apply(Module, Function, [Arguments) /s On Jan 20, 6:03?pm, Sergey S wrote: > Hello. > > I'm going to write a simple benchmark utility taking function > references and then writing results with corresponding function names. > > What I'm looking for is the way to get readable function name at runtime. > > Here is pseudo code: > > get_name(fun some_mod:some_fun/0) -> some_fun > get_name(fun some_fun/0) ? ? ? ? ? ? ? ? ?-> some_fun > > I took a look at "erl -man erlang" to find out what I can use in this > case. erlang:fun_info(Fun, name) seems useful but it works only for > exported function references: > > % erlang:fun_info/2 will return the readable name: {name, some_fun}. > That is what I want to get. > erlang:fun_info(fun some_module:some_fun/0, name) > > But it doesn't work for local function references (I've checked): > > % Note that 'some_module' is omitted. This function will return > something like {name,'-test/0-fun-0-'} which is incomprehensible to me > erlang:fun_info(fun some_fun/0, name). > > With local function references I have to use something other... Is > there a simple way to get the name of the function? > > -- > Sergey > _______________________________________________ > erlang-questions mailing list > erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions From bernie@REDACTED Wed Jan 21 05:52:42 2009 From: bernie@REDACTED (Bernard Duggan) Date: Wed, 21 Jan 2009 15:52:42 +1100 Subject: [erlang-questions] Comet server broadcasting messages to 40k clients In-Reply-To: <6bb4c8cb0901201920k30d22c78m2458eaa9ce71ec9c@mail.gmail.com> References: <6bb4c8cb0901201920k30d22c78m2458eaa9ce71ec9c@mail.gmail.com> Message-ID: <4976AA1A.5030501@m5net.com> Hi Adriano, My first suggestion would be to check that you're using kernel polling (do you start erl with "+K true"? You should see the string "[kernel-poll:true]" in the version line). If not, that's probably a significant part of it, since for every packet that comes in the VM will be iterating over all 40k sockets to figure out which one it came from before the message even arrives at your code. Also, be aware that using the -- operator on a big list can be a very expensive operation (there was a thread about it last week, in fact), so using it to remove a single socket from a list that big could be a significant cost. Finally, I'd suggest that, if you haven't already tried it, you spawn a separate thread (process, in erlang parlance) to handle each connection rather than trying to deal with them all in one thread. While I don't think this is going to improve your performance here, it makes your code simpler and easier to follow. Remember, erlang processes are not like C threads - they're cheap, plentiful and carry a much lower switching overhead. This would involve a little more work for your case since you want to broadcast to everyone based on a signal from anyone, but it is more in keeping with "The Erlang Way(tm)". (Actual followers of The Erlang Way are of course free to correct my views...). Cheers, Bernard Adriano Bonat wrote: > Hi, > > I implemented a simple Comet server using gen_tcp (code follows below > this text), and I'm doing tests with 40k connected clients. With a > certain event, a message will be broadcasted to all connected clients, > in my current implementation you just have to access the URI "/send". > > The current problem is that the first connected client will receive > the message after ~5s (in my implementation a new client goes in the > list's head), and this time is so high compared to a C version of the > server. I tried to understand where time is being spent using tools > like eprof and fprof, but I'm not that experienced trying to > understand their results. > > This makes me think if I'm doing something wrong, if I can optimize it > in some way... or if this is the normal overhead imposed by running on > top of a VM... > > Any ideas? > > Thanks. > > > -module(myhttpd). > > -compile(export_all). > > -define(LISTEN_PORT, 8000). > -define(LISTEN_OPTS, [list, {packet, 0}, {keepalive, true}, {active, true}]). > > start() -> > register(router, spawn(fun handle_connections/0)), > > {ok, Listen} = gen_tcp:listen(?LISTEN_PORT, ?LISTEN_OPTS), > spawn(fun() -> accept_connection(Listen) end). > > accept_connection(Listen) -> > {ok, Socket} = gen_tcp:accept(Listen), > router ! {accepted, Socket}, > gen_tcp:controlling_process(Socket, whereis(router)), > accept_connection(Listen). > > handle_connections() -> > handle_connections([]). > > handle_connections(Sockets) -> > receive > {accepted, Socket} -> > io:format("Just accepted ~p~n", [Socket]), > handle_connections([Socket|Sockets]); > {tcp, Socket, "GET /send" ++ _T} -> > io:format("Sending messages.. ~n", []), > TStart = now(), > spawn(fun() -> > lists:foreach(fun(S) -> send_chunk(S, > io_lib:format("(~b usecs) Hello world!
", [timer:now_diff(now(), > TStart)])) end, Sockets) > end), > gen_tcp:send(Socket, "HTTP/1.1 200 OK\r\n\r\nDone."), > gen_tcp:close(Socket), > handle_connections(Sockets -- [Socket]); > {tcp_closed, Socket} -> > io:format("Closed connection ~p~n", [Socket]), > handle_connections(Sockets -- [Socket]); > {tcp, Socket, X} -> > io:format("Rcved: ~p~n", [X]), > start_response(Socket), > handle_connections(Sockets); > {numclients} -> > io:format("Num clients: ~p~n", [length(Sockets)]), > handle_connections(Sockets); > Any -> > io:format("Just got ~p~n", [Any]), > handle_connections(Sockets) > end. > > start_response(Socket) -> > gen_tcp:send(Socket, "HTTP/1.1 200 OK\r\nContent-type: > text/html;charset=utf-8\r\nTransfer-encoding: chunked\r\n\r\n"). > > end_response(Socket) -> > gen_tcp:send(Socket, "0\r\n\r\n"). > > send_chunk(Socket, Chunk) -> > gen_tcp:send(Socket, io_lib:format("~.16b\r\n~s\r\n", > [iolist_size(Chunk), Chunk])). > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From charleswthompsoniii@REDACTED Wed Jan 21 06:40:06 2009 From: charleswthompsoniii@REDACTED (Charles Thompson) Date: Tue, 20 Jan 2009 21:40:06 -0800 Subject: [erlang-questions] Seattle Erlounge Happens in 21 h 38 m Message-ID: <7db028f30901202140o5ce2f401gc57d37fb0af3a526@mail.gmail.com> Dear coffee drinking, flannel shirt wearing, Seattle-based Erlang junkies, In 21 hours and some change, throw some wool socks on, step into your Birkenstocks, then head over to The Garage, a place that's probably too liberal for those suffering from inaugural hangovers. There you will find at least three people sharing the Erlang gospel. If you're interested in Erlang -- get there. If you're Joe Armstrong -- get there. If you haven't programmed since your mom tossed out your Commodore 64 -- it's not too late. Get there. Details at: http://erloungeseattle.org/ Look forward to seeing you all there. -- Charles Thompson (360) 941-1762 charleswthompsoniii@REDACTED From mikael.lixenstrand@REDACTED Wed Jan 21 07:52:56 2009 From: mikael.lixenstrand@REDACTED (Mikael Lixenstrand) Date: Wed, 21 Jan 2009 07:52:56 +0100 Subject: [erlang-questions] sctp_peer_addr_params Message-ID: I'm trying to change the sack delay in gen_sctp {ok,Socket} = gen_sctp:open([{ip, ServerIPAddress}, {port, ServerPort}] ++ [{sctp_peer_addr_params, #sctp_paddrparams{ assoc_id = 0, address = {ServerIPAddress ,ServerPort} ,sackdelay = 400}}, {mode, binary}, {active, false}, {sctp_events,#sctp_event_subscribe{address_event = false, shutdown_event=false}}]), I tried several approaches but with the same result: Error in process <0.7100.1> on node 'mikael@REDACTED' with exit value: {badarg,[{gen_sctp,open,[[{ip,{10,70,160,17}},{port,3868},{sctp_peer_addr_params,{sctp_paddrparams,0,{{10,70,160,17},3868},200,5,600,400,[]}},{mode,binary},{active,false},{sctp_events,{sctp_event_subscribe,undefined,undefined,false,undefined,undefined... I'm running R12B-0 on rhel 5.2 Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From charleswthompsoniii@REDACTED Wed Jan 21 08:02:28 2009 From: charleswthompsoniii@REDACTED (Charles Thompson) Date: Tue, 20 Jan 2009 23:02:28 -0800 Subject: [erlang-questions] Seattle Erlounge Happens in 21 h 38 m Message-ID: <7db028f30901202302t780f6029p88e7cb8d64cb9a76@mail.gmail.com> Dear coffee drinking, flannel shirt wearing, Seattle-based Erlang junkies, In 21 hours and some change, throw some wool socks on, step into your Birkenstocks, then head over to The Garage, a place that's probably too liberal for those suffering from inaugural hangovers. There you will find at least three people sharing the Erlang gospel. If you're interested in Erlang -- get there. If you're Joe Armstrong -- get there. If you haven't programmed since your mom tossed out your Commodore 64 -- it's not too late. Get there. Details at: http://erloungeseattle.org/ Look forward to seeing you all there. -- Charles Thompson (360) 941-1762 charleswthompsoniii@REDACTED -- Charles Thompson (360) 941-1762 charleswthompsoniii@REDACTED From yubao.liu@REDACTED Wed Jan 21 09:21:07 2009 From: yubao.liu@REDACTED (Liu Yubao) Date: Wed, 21 Jan 2009 16:21:07 +0800 Subject: [erlang-questions] What's the recommended template engine for web development with erlang? Message-ID: <4976DAF3.7030301@gmail.com> Hi, Recently I started to learn web development in yaws, I don't like the way to embedded tag into html template file because my editor Vim doesn't support syntax highlight and auto indent for html and erlang at the same time, and I find the {ehtml, ...} expressions are too complicated if the templates are complicated. I googled the web and found these template engine: * template engine contained in erlang-web Pros: erlang-web has many many features; Cons: erlang-web use a customized tag like that html tidy reports error on the templates and it's not friendly to preview the page layout; It's said erlang-web doesn't support mochiweb yet (not serious for me). * erltl in erlyweb I checkout erlyweb from google code and the building crashes, I haven't figure out the reason. Pros: erlyweb has many features; templates are compiled to erlang modules; Cons: seems it's not developed actively any more. * erldtl Pros: The template notation seems good(I hate and <%...%> :-) templates are compiled to erlang modules; Cons: not completed yet. * sgte Pros: The template notation seems good. Cons: It's said the templates are evaluated at runtime, so I'm worry its performance. I hope somebody experienced can give some comments about them, thanks ahead! Best regards, Liu Yubao From nick@REDACTED Wed Jan 21 09:32:50 2009 From: nick@REDACTED (Nick Gerakines) Date: Wed, 21 Jan 2009 00:32:50 -0800 Subject: [erlang-questions] What's the recommended template engine for web development with erlang? In-Reply-To: <4976DAF3.7030301@gmail.com> References: <4976DAF3.7030301@gmail.com> Message-ID: I'm a real fan of Erltl and use it regularly. Erltl and mochiweb is a real win. # Nick Gerakines On Wed, Jan 21, 2009 at 12:21 AM, Liu Yubao wrote: > Hi, > > Recently I started to learn web development in yaws, I don't > like the way to embedded tag into html template file > because my editor Vim doesn't support syntax highlight and auto > indent for html and erlang at the same time, and I find the {ehtml, ...} > expressions are too complicated if the templates are complicated. > > I googled the web and found these template engine: > > * template engine contained in erlang-web > > Pros: erlang-web has many many features; > Cons: erlang-web use a customized tag like that > html tidy reports error on the templates and it's not > friendly to preview the page layout; > It's said erlang-web doesn't support mochiweb yet (not serious for me). > > * erltl in erlyweb > > I checkout erlyweb from google code and the building crashes, I haven't > figure out the reason. > > Pros: erlyweb has many features; > templates are compiled to erlang modules; > Cons: seems it's not developed actively any more. > > * erldtl > > Pros: The template notation seems good(I hate and <%...%> :-) > templates are compiled to erlang modules; > Cons: not completed yet. > > * sgte > > Pros: The template notation seems good. > Cons: It's said the templates are evaluated at runtime, so I'm worry > its performance. > > I hope somebody experienced can give some comments about them, thanks ahead! > > > Best regards, > > Liu Yubao > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From richardc@REDACTED Wed Jan 21 09:39:41 2009 From: richardc@REDACTED (Richard Carlsson) Date: Wed, 21 Jan 2009 09:39:41 +0100 Subject: [erlang-questions] Finding a way to get function name from local function reference In-Reply-To: References: Message-ID: <4976DF4D.9050206@it.uu.se> Sergey S wrote: > What I'm looking for is the way to get readable function name at runtime. > > Here is pseudo code: > > get_name(fun some_mod:some_fun/0) -> some_fun > get_name(fun some_fun/0) -> some_fun > > I took a look at "erl -man erlang" to find out what I can use in this > case. erlang:fun_info(Fun, name) seems useful but it works only for > exported function references: > > % erlang:fun_info/2 will return the readable name: {name, some_fun}. > That is what I want to get. > erlang:fun_info(fun some_module:some_fun/0, name) > > But it doesn't work for local function references (I've checked): > > % Note that 'some_module' is omitted. This function will return > something like {name,'-test/0-fun-0-'} which is incomprehensible to me > erlang:fun_info(fun some_fun/0, name). > > With local function references I have to use something other... Is > there a simple way to get the name of the function? This is due to a compiler implementation detail (broken, imho), where a local function reference "fun foo/N" is actually compiled by rewriting it as "fun (...) -> foo(...) end", which means that the name you get from fun_info() is the generated internal name for the new anonymous function. The name "foo" is hidden and there is nothing you can do to get hold of it. It would be nice if the compiler was changed to generate direct references instead of wrapping them like this. /Richard From vychodil.hynek@REDACTED Wed Jan 21 09:45:23 2009 From: vychodil.hynek@REDACTED (Hynek Vychodil) Date: Wed, 21 Jan 2009 09:45:23 +0100 Subject: [erlang-questions] new feature suggestions In-Reply-To: <95be1d3b0901201247p6155629byedd94ce434d6fbb0@mail.gmail.com> References: <95be1d3b0901201247p6155629byedd94ce434d6fbb0@mail.gmail.com> Message-ID: <20090121084524.E61AE24013@relay.gooddata.com> Isn't it duplicate of next(Erlang) http://moderator.appspot.com/#16/e=bbc4 ? On Tue, Jan 20, 2009 at 9:47 PM, Vlad Dumitrescu wrote: > Hi, > > I wonder if anyone else thinks it might be useful to set up a free > account at uservoice.com and gather all the suggestions for > improvements and new features there. The idea is that people can > suggest features and everyone gets only 10 votes. (Registration is not > required) > > I thing it would be interesting to see all the suggestions in one > place and how everybody prioritizes them. I for one don't like to send > emails to the list with "+1"s, and maybe there are others that would > make their votes heard (pun intended). > > best regards, > Vlad > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero! Try Good Data now for free: www.gooddata.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From chsu79@REDACTED Wed Jan 21 10:01:43 2009 From: chsu79@REDACTED (Christian) Date: Wed, 21 Jan 2009 10:01:43 +0100 Subject: [erlang-questions] What's the recommended template engine for web development with erlang? In-Reply-To: <4976DAF3.7030301@gmail.com> References: <4976DAF3.7030301@gmail.com> Message-ID: > * erldtl > > Pros: The template notation seems good(I hate and <%...%> :-) > templates are compiled to erlang modules; > Cons: not completed yet. What is a show-stopper for you about erlydtl? What is not complete enough for you? The features I use, they work well. I'm about to get annoyed enough with rebuilding all template modules each time i run make that i am ready to add something that only builds the templates that have changed or use dependencies that have changed. But other than that, it works fine. From vladdu55@REDACTED Wed Jan 21 10:09:37 2009 From: vladdu55@REDACTED (Vlad Dumitrescu) Date: Wed, 21 Jan 2009 10:09:37 +0100 Subject: [erlang-questions] new feature suggestions In-Reply-To: <20090121084524.F2B8A24063@relay.gooddata.com> References: <95be1d3b0901201247p6155629byedd94ce434d6fbb0@mail.gmail.com> <20090121084524.F2B8A24063@relay.gooddata.com> Message-ID: <95be1d3b0901210109g251a299am28a446345f451555@mail.gmail.com> On Wed, Jan 21, 2009 at 09:45, Hynek Vychodil wrote: > Isn't it duplicate of next(Erlang) http://moderator.appspot.com/#16/e=bbc4 ? More or less, yes, I forgot about that one. There are differences, but there's no reason enough to change. i rest my case. regards, Vlad From bgustavsson@REDACTED Wed Jan 21 10:24:44 2009 From: bgustavsson@REDACTED (Bjorn Gustavsson) Date: Wed, 21 Jan 2009 10:24:44 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: References: Message-ID: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> On Tue, Jan 20, 2009 at 4:15 PM, James Hague wrote: > > I would like to propose the addition of lists:keyfind/3, which is > identical in structure to lists:keysearch/3, except that it returns > either 'false' or the found tuple, with no additional wrapping of the > result. This can be trivially added to the lists module: > > keyfind(K, N, L) -> > case keysearch(K, N, L) of > {_, Tuple} -> Tuple; > X -> X > end. > Good idea. Unless someone has any good reasons agains this suggestion, we will probably implement it in R13. (lists:keyfind/3 will be a BIF, and lists:keysearch/3 implemented in Erlang.) /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB From erlang@REDACTED Wed Jan 21 10:35:17 2009 From: erlang@REDACTED (Dominic Williams) Date: Wed, 21 Jan 2009 04:35:17 -0500 (EST) Subject: [erlang-questions] How to properly declare a special process in supervisor's child specification? In-Reply-To: References: Message-ID: <852bdec87d75280448dd485e121cf294.squirrel@www.geekisp.com> Hi Sergey, > [Module] or dynamic? > > erl -man supervisor doesnt' give the answer: You will find in the "Child specifications" section of the "Design Principles" chapter that dynamic should only be used when the child is a gen_event. When the child is a supervisor, gen_server or gen_fsm, use [Module]. Regards, Dominic Williams http://dominicwilliams.net ---- From bgustavsson@REDACTED Wed Jan 21 10:35:38 2009 From: bgustavsson@REDACTED (Bjorn Gustavsson) Date: Wed, 21 Jan 2009 10:35:38 +0100 Subject: [erlang-questions] Finding a way to get function name from local function reference In-Reply-To: <4976DF4D.9050206@it.uu.se> References: <4976DF4D.9050206@it.uu.se> Message-ID: <6672d0160901210135g3e614175r7415511e73c50b08@mail.gmail.com> On Wed, Jan 21, 2009 at 9:39 AM, Richard Carlsson wrote: > This is due to a compiler implementation detail (broken, imho), where > a local function reference "fun foo/N" is actually compiled by rewriting > it as "fun (...) -> foo(...) end", which means that the name you get > from fun_info() is the generated internal name for the new anonymous > function. The name "foo" is hidden and there is nothing you can do > to get hold of it. It would be nice if the compiler was changed to > generate direct references instead of wrapping them like this. There is (or used to be) a subtle detail in the run-time systems that makes it necessary to introduce a wrapper function. At the moment I don't remember exactly what the detail is (was), but I'll investigate and see if I can do something about it in R13. /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB From yubao.liu@REDACTED Wed Jan 21 10:50:17 2009 From: yubao.liu@REDACTED (Liu Yubao) Date: Wed, 21 Jan 2009 17:50:17 +0800 Subject: [erlang-questions] What's the recommended template engine for web development with erlang? In-Reply-To: References: <4976DAF3.7030301@gmail.com> Message-ID: <4976EFD9.2030005@gmail.com> Christian wrote: >> * erldtl >> >> Pros: The template notation seems good(I hate and <%...%> :-) >> templates are compiled to erlang modules; >> Cons: not completed yet. > > What is a show-stopper for you about erlydtl? What is not complete > enough for you? In fact, I prefer erlydtl to erltl in erlyweb because I feel erlydtl is cleaner. I *really* don't like to embedd erlang code into html template because it's not editor-friendly enough. > > The features I use, they work well. The author says he has implemented most important template synatexes, I have a glance at the source code, it looks clean and clear, so I believe the author has done a good job and it should be not very difficult to support more syntaxes. Currently I'm testing erlydtl and sgte, erlydtl has more interesting features like autoescape and time formating, I think I'll probably choose erlydtl at last. > > I'm about to get annoyed enough with rebuilding all template modules > each time i run make that i am ready to add something that only builds > the templates that have changed or use dependencies that have changed. > But other than that, it works fine. > Yes, I'm also considering a gen_server to monitor template changes, I'll be very glad if you can send me a copy after you finish the feature. Best regards, Liu Yubao From oscar@REDACTED Wed Jan 21 10:54:31 2009 From: oscar@REDACTED (=?ISO-8859-1?Q?Oscar_Hellstr=F6m?=) Date: Wed, 21 Jan 2009 09:54:31 +0000 Subject: [erlang-questions] How to get binaries when using {packet, http} In-Reply-To: <4975A6E7.10509@erix.ericsson.se> References: <4975A6E7.10509@erix.ericsson.se> Message-ID: <4976F0D7.1030106@erlang-consulting.com> Hi, Doesn't the combination [binary, {packet, http}] mean that if the socket is changed to return raw packets later they will be returned as binaries while if it was opened with [list, {packet, http}] recv or setting it to active will give you list. This is useful when you want to read the http body as a binary rather than a list. Or is there some other way of changing it from a list to a binary later? Sverker Eriksson wrote: > No, there is currently no way to get the "strings" in the http-tuples as > binaries instead of lists. > > The obvious combinations of options to achieve that would be > [binary,{packet,http}]. But due to fear of breaking running applications > (such as Yaws and Mochiweb) it was not done when {packet, http} was > documented and made official. Consider it an invalid combination and do > not use it. > No decision has been made about introducing http-binaries in this or any > other way. > > /Sverker, Erlang/OTP Ericsson > > > Sergey S wrote: > >> Hello. >> >> I discovered that no matter which type of incoming data you choose >> (binary/list), all the data is delivered as lists. >> >> Is there a way to get binaries instead of lists? >> >> If not, is this behaviour going to be changed? In other words, will >> there be a way to get binaries using {packet, http}? >> >> Thanks. >> >> -- >> Sergey >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions@REDACTED >> http://www.erlang.org/mailman/listinfo/erlang-questions >> >> >> > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > Best regards -- Oscar Hellstr?m, oscar@REDACTED Office: +44 20 7655 0337 Mobile: +44 798 45 44 773 Erlang Training and Consulting http://www.erlang-consulting.com/ From richardc@REDACTED Wed Jan 21 10:56:13 2009 From: richardc@REDACTED (Richard Carlsson) Date: Wed, 21 Jan 2009 10:56:13 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> Message-ID: <4976F13D.7000900@it.uu.se> Bjorn Gustavsson wrote: > On Tue, Jan 20, 2009 at 4:15 PM, James Hague wrote: >> I would like to propose the addition of lists:keyfind/3, which is >> identical in structure to lists:keysearch/3, except that it returns >> either 'false' or the found tuple, with no additional wrapping of the >> result. This can be trivially added to the lists module: >> >> keyfind(K, N, L) -> >> case keysearch(K, N, L) of >> {_, Tuple} -> Tuple; >> X -> X >> end. >> > > Good idea. > > Unless someone has any good reasons agains this suggestion, we will probably > implement it in R13. (lists:keyfind/3 will be a BIF, and > lists:keysearch/3 implemented > in Erlang.) Only that I always wince at the mixing of 'false' with {...}. Since this is a new function, I'd prefer 'error' (to pick another atom that is frequently used in Erlang libraries). /Richard (Singing: "Eric the half-a-bool...") From mikpe@REDACTED Wed Jan 21 11:50:32 2009 From: mikpe@REDACTED (Mikael Pettersson) Date: Wed, 21 Jan 2009 11:50:32 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <4976F13D.7000900@it.uu.se> References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> Message-ID: <18806.65016.240131.576703@harpo.it.uu.se> Richard Carlsson writes: > Bjorn Gustavsson wrote: > > On Tue, Jan 20, 2009 at 4:15 PM, James Hague wrote: > >> I would like to propose the addition of lists:keyfind/3, which is > >> identical in structure to lists:keysearch/3, except that it returns > >> either 'false' or the found tuple, with no additional wrapping of the > >> result. This can be trivially added to the lists module: > >> > >> keyfind(K, N, L) -> > >> case keysearch(K, N, L) of > >> {_, Tuple} -> Tuple; > >> X -> X > >> end. > >> > > > > Good idea. > > > > Unless someone has any good reasons agains this suggestion, we will probably > > implement it in R13. (lists:keyfind/3 will be a BIF, and > > lists:keysearch/3 implemented > > in Erlang.) > > Only that I always wince at the mixing of 'false' with {...}. Since this > is a new function, I'd prefer 'error' (to pick another atom that is > frequently used in Erlang libraries). Except that it's not actually an error to ask "search list L for a tuple T with value K in element N and return T, or tell me if none could be found". So I'd argue that 'false' is much more appropriate than 'error'. At least, _I_ don't want that to be an error, since that would require silly coding like: 1. ask if the element is there, but don't return it (query, boolean) 2. if it's there, get it (lookup, throws exn on failure not never here) when what one often wants is: 1. if the element is there, return it, otherwise return 'no' From vychodil.hynek@REDACTED Wed Jan 21 11:52:14 2009 From: vychodil.hynek@REDACTED (Hynek Vychodil) Date: Wed, 21 Jan 2009 11:52:14 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <4976F13D.7000900@it.uu.se> References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> Message-ID: <20090121105215.0ADF62402F@relay.gooddata.com> On Wed, Jan 21, 2009 at 10:56 AM, Richard Carlsson wrote: > Bjorn Gustavsson wrote: > > On Tue, Jan 20, 2009 at 4:15 PM, James Hague > wrote: > >> I would like to propose the addition of lists:keyfind/3, which is > >> identical in structure to lists:keysearch/3, except that it returns > >> either 'false' or the found tuple, with no additional wrapping of the > >> result. This can be trivially added to the lists module: > >> > >> keyfind(K, N, L) -> > >> case keysearch(K, N, L) of > >> {_, Tuple} -> Tuple; > >> X -> X > >> end. > >> > > > > Good idea. > > > > Unless someone has any good reasons agains this suggestion, we will > probably > > implement it in R13. (lists:keyfind/3 will be a BIF, and > > lists:keysearch/3 implemented > > in Erlang.) > > Only that I always wince at the mixing of 'false' with {...}. Since this > is a new function, I'd prefer 'error' (to pick another atom that is > frequently used in Erlang libraries). I don't understand why 'error' is better than 'false'. 'false' is more broadly used than 'error' because it is all conditions result. Anyway when I ask someone to find something I found to get answer 'found' x 'not found' more expected than 'found' x 'error'. 'false' sounds for me as better answer to ask for `find` as 'true' I have found x 'false' I haven't found. Not found is not error, it is false result. > > > /Richard > > > (Singing: "Eric the half-a-bool...") > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero! Try Good Data now for free: www.gooddata.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven.charles.davis@REDACTED Wed Jan 21 11:54:17 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Wed, 21 Jan 2009 02:54:17 -0800 (PST) Subject: [erlang-questions] Finding a way to get function name from local function reference In-Reply-To: <006cb7fc-22f3-455f-95c3-ada2e5725ad1@s1g2000prg.googlegroups.com> References: <006cb7fc-22f3-455f-95c3-ada2e5725ad1@s1g2000prg.googlegroups.com> Message-ID: Yes. I *completely* misread and misunderstood the question . From bengt.kleberg@REDACTED Wed Jan 21 12:12:42 2009 From: bengt.kleberg@REDACTED (Bengt Kleberg) Date: Wed, 21 Jan 2009 12:12:42 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <18806.65016.240131.576703@harpo.it.uu.se> References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> Message-ID: <1232536362.5027.46.camel@seasc1137.dyn.rnd.as.sw.ericsson.se> Greetings, Rickard has my support. I, too, find mixing boolean and none boolean return values surprising. Perhaps {} (empty tuple) is an appropriate return value if nothing is found? bengt On Wed, 2009-01-21 at 11:50 +0100, Mikael Pettersson wrote: > Richard Carlsson writes: > > Bjorn Gustavsson wrote: > > > On Tue, Jan 20, 2009 at 4:15 PM, James Hague wrote: > > >> I would like to propose the addition of lists:keyfind/3, which is > > >> identical in structure to lists:keysearch/3, except that it returns > > >> either 'false' or the found tuple, with no additional wrapping of the > > >> result. This can be trivially added to the lists module: > > >> > > >> keyfind(K, N, L) -> > > >> case keysearch(K, N, L) of > > >> {_, Tuple} -> Tuple; > > >> X -> X > > >> end. > > >> > > > > > > Good idea. > > > > > > Unless someone has any good reasons agains this suggestion, we will probably > > > implement it in R13. (lists:keyfind/3 will be a BIF, and > > > lists:keysearch/3 implemented > > > in Erlang.) > > > > Only that I always wince at the mixing of 'false' with {...}. Since this > > is a new function, I'd prefer 'error' (to pick another atom that is > > frequently used in Erlang libraries). > > Except that it's not actually an error to ask "search list L > for a tuple T with value K in element N and return T, or tell > me if none could be found". So I'd argue that 'false' is much > more appropriate than 'error'. > > At least, _I_ don't want that to be an error, since that would > require silly coding like: > 1. ask if the element is there, but don't return it (query, boolean) > 2. if it's there, get it (lookup, throws exn on failure not never here) > when what one often wants is: > 1. if the element is there, return it, otherwise return 'no' > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From chsu79@REDACTED Wed Jan 21 12:30:55 2009 From: chsu79@REDACTED (Christian) Date: Wed, 21 Jan 2009 12:30:55 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <1232536362.5027.46.camel@seasc1137.dyn.rnd.as.sw.ericsson.se> References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> <1232536362.5027.46.camel@seasc1137.dyn.rnd.as.sw.ericsson.se> Message-ID: On Wed, Jan 21, 2009 at 12:12, Bengt Kleberg wrote: > Greetings, > > Rickard has my support. I, too, find mixing boolean and none boolean > return values surprising. > > Perhaps {} (empty tuple) is an appropriate return value if nothing is > found? The functions proplists:get_value/2,3 are the less-generalized versions of this keyfind-function. So for consistency chose 'undefined'. (and provide a Default-argument keyfind function as well?) From vychodil.hynek@REDACTED Wed Jan 21 12:40:14 2009 From: vychodil.hynek@REDACTED (Hynek Vychodil) Date: Wed, 21 Jan 2009 12:40:14 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <18806.65016.240131.576703@harpo.it.uu.se> References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> Message-ID: <20090121114209.C0B8C24063@relay.gooddata.com> On Wed, Jan 21, 2009 at 11:50 AM, Mikael Pettersson wrote: > Richard Carlsson writes: > > Bjorn Gustavsson wrote: > > > On Tue, Jan 20, 2009 at 4:15 PM, James Hague > wrote: > > >> I would like to propose the addition of lists:keyfind/3, which is > > >> identical in structure to lists:keysearch/3, except that it returns > > >> either 'false' or the found tuple, with no additional wrapping of the > > >> result. This can be trivially added to the lists module: > > >> > > >> keyfind(K, N, L) -> > > >> case keysearch(K, N, L) of > > >> {_, Tuple} -> Tuple; > > >> X -> X > > >> end. > > >> > > > > > > Good idea. > > > > > > Unless someone has any good reasons agains this suggestion, we will > probably > > > implement it in R13. (lists:keyfind/3 will be a BIF, and > > > lists:keysearch/3 implemented > > > in Erlang.) > > > > Only that I always wince at the mixing of 'false' with {...}. Since this > > is a new function, I'd prefer 'error' (to pick another atom that is > > frequently used in Erlang libraries). > > Except that it's not actually an error to ask "search list L > for a tuple T with value K in element N and return T, or tell > me if none could be found". So I'd argue that 'false' is much > more appropriate than 'error'. > > At least, _I_ don't want that to be an error, since that would > require silly coding like: > 1. ask if the element is there, but don't return it (query, boolean) > 2. if it's there, get it (lookup, throws exn on failure not never here) > when what one often wants is: > 1. if the element is there, return it, otherwise return 'no' > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > 'no' sounds good for me. -- --Hynek (Pichi) Vychodil Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero! Try Good Data now for free: www.gooddata.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From richardc@REDACTED Wed Jan 21 12:44:37 2009 From: richardc@REDACTED (Richard Carlsson) Date: Wed, 21 Jan 2009 12:44:37 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <18806.65016.240131.576703@harpo.it.uu.se> References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> Message-ID: <49770AA5.4000502@it.uu.se> Mikael Pettersson wrote: > > Only that I always wince at the mixing of 'false' with {...}. Since this > > is a new function, I'd prefer 'error' (to pick another atom that is > > frequently used in Erlang libraries). > > Except that it's not actually an error to ask "search list L > for a tuple T with value K in element N and return T, or tell > me if none could be found". So I'd argue that 'false' is much > more appropriate than 'error'. I tried to narrow it down to just one alternative suggestion, and {ok,Value}|'error' is the convention used by dict:find. It seems to depend on what you read into the name of the function: if the name is "find" or "keyfind", aren't you expecting it to find the element? You didn't use the "lookforsomethingthatmightnotbethere" function. Anyhow, I wouldn't have suggested 'error' unless there was some precedence for it. I prefer 'none' or 'not_found' for this kind of return value, but consistency is also a good thing (so maybe 'false' is still best). > At least, _I_ don't want that to be an error, since that would > require silly coding like: > 1. ask if the element is there, but don't return it (query, boolean) > 2. if it's there, get it (lookup, throws exn on failure not never here) > when what one often wants is: > 1. if the element is there, return it, otherwise return 'no' Yes, but you don't use 1+2 for dict:find() just because it might return the atom 'error', do you? I didn't suggest that keyfind should throw an exception. /Richard From vychodil.hynek@REDACTED Wed Jan 21 12:47:57 2009 From: vychodil.hynek@REDACTED (Hynek Vychodil) Date: Wed, 21 Jan 2009 12:47:57 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <1232536362.5027.46.camel@seasc1137.dyn.rnd.as.sw.ericsson.se> References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> <1232536362.5027.46.camel@seasc1137.dyn.rnd.as.sw.ericsson.se> Message-ID: <20090121115015.F164B24065@relay.gooddata.com> On Wed, Jan 21, 2009 at 12:12 PM, Bengt Kleberg wrote: > Greetings, > > Rickard has my support. I, too, find mixing boolean and none boolean > return values surprising. > > Perhaps {} (empty tuple) is an appropriate return value if nothing is > found? > Erlang is not C thus we don't must return same type as for example -1 in C used to error result. Erlang have atoms (and works as well as -1 in C) thus just use it. Empty list [] sounds good for function which returns list of results but empty tuple {} is not empty variant for tuple. Tuple is not collection it is just tuple. Tuple with different sizes are different types. List with different amount of members are same types. There is big semantic shift. > > > bengt > > On Wed, 2009-01-21 at 11:50 +0100, Mikael Pettersson wrote: > > Richard Carlsson writes: > > > Bjorn Gustavsson wrote: > > > > On Tue, Jan 20, 2009 at 4:15 PM, James Hague > wrote: > > > >> I would like to propose the addition of lists:keyfind/3, which is > > > >> identical in structure to lists:keysearch/3, except that it returns > > > >> either 'false' or the found tuple, with no additional wrapping of > the > > > >> result. This can be trivially added to the lists module: > > > >> > > > >> keyfind(K, N, L) -> > > > >> case keysearch(K, N, L) of > > > >> {_, Tuple} -> Tuple; > > > >> X -> X > > > >> end. > > > >> > > > > > > > > Good idea. > > > > > > > > Unless someone has any good reasons agains this suggestion, we will > probably > > > > implement it in R13. (lists:keyfind/3 will be a BIF, and > > > > lists:keysearch/3 implemented > > > > in Erlang.) > > > > > > Only that I always wince at the mixing of 'false' with {...}. Since > this > > > is a new function, I'd prefer 'error' (to pick another atom that is > > > frequently used in Erlang libraries). > > > > Except that it's not actually an error to ask "search list L > > for a tuple T with value K in element N and return T, or tell > > me if none could be found". So I'd argue that 'false' is much > > more appropriate than 'error'. > > > > At least, _I_ don't want that to be an error, since that would > > require silly coding like: > > 1. ask if the element is there, but don't return it (query, boolean) > > 2. if it's there, get it (lookup, throws exn on failure not never here) > > when what one often wants is: > > 1. if the element is there, return it, otherwise return 'no' > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions@REDACTED > > http://www.erlang.org/mailman/listinfo/erlang-questions > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero! Try Good Data now for free: www.gooddata.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From mazen.harake@REDACTED Wed Jan 21 12:52:55 2009 From: mazen.harake@REDACTED (Mazen Harake) Date: Wed, 21 Jan 2009 13:52:55 +0200 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <49770AA5.4000502@it.uu.se> References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> <49770AA5.4000502@it.uu.se> Message-ID: <49770C97.2090306@erlang-consulting.com> IF this function is going to be implemented then +1 for 'not_found' imho false implies an "is" function and error means that there was an error with the function. not_found is more logical. /M Richard Carlsson wrote: > Mikael Pettersson wrote: > > >> > Only that I always wince at the mixing of 'false' with {...}. Since this >> > is a new function, I'd prefer 'error' (to pick another atom that is >> > frequently used in Erlang libraries). >> >> Except that it's not actually an error to ask "search list L >> for a tuple T with value K in element N and return T, or tell >> me if none could be found". So I'd argue that 'false' is much >> more appropriate than 'error'. >> > > I tried to narrow it down to just one alternative suggestion, and > {ok,Value}|'error' is the convention used by dict:find. It seems > to depend on what you read into the name of the function: if the > name is "find" or "keyfind", aren't you expecting it to find the > element? You didn't use the "lookforsomethingthatmightnotbethere" > function. Anyhow, I wouldn't have suggested 'error' unless there > was some precedence for it. I prefer 'none' or 'not_found' for > this kind of return value, but consistency is also a good thing > (so maybe 'false' is still best). > > >> At least, _I_ don't want that to be an error, since that would >> require silly coding like: >> 1. ask if the element is there, but don't return it (query, boolean) >> 2. if it's there, get it (lookup, throws exn on failure not never here) >> when what one often wants is: >> 1. if the element is there, return it, otherwise return 'no' >> > > Yes, but you don't use 1+2 for dict:find() just because it might > return the atom 'error', do you? I didn't suggest that keyfind > should throw an exception. > > /Richard > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From mikpe@REDACTED Wed Jan 21 13:02:07 2009 From: mikpe@REDACTED (Mikael Pettersson) Date: Wed, 21 Jan 2009 13:02:07 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <49770AA5.4000502@it.uu.se> References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> <49770AA5.4000502@it.uu.se> Message-ID: <18807.3775.551864.945055@harpo.it.uu.se> Richard Carlsson writes: > Mikael Pettersson wrote: > > > > Only that I always wince at the mixing of 'false' with {...}. Since this > > > is a new function, I'd prefer 'error' (to pick another atom that is > > > frequently used in Erlang libraries). > > > > Except that it's not actually an error to ask "search list L > > for a tuple T with value K in element N and return T, or tell > > me if none could be found". So I'd argue that 'false' is much > > more appropriate than 'error'. > > I tried to narrow it down to just one alternative suggestion, and > {ok,Value}|'error' is the convention used by dict:find. It seems > to depend on what you read into the name of the function: if the > name is "find" or "keyfind", aren't you expecting it to find the > element? You didn't use the "lookforsomethingthatmightnotbethere" keyfind is the lighter-weight keysearch-done-right, and keysearch returns false so keyfind should too. > function. Anyhow, I wouldn't have suggested 'error' unless there > was some precedence for it. I prefer 'none' or 'not_found' for > this kind of return value, but consistency is also a good thing > (so maybe 'false' is still best). The problem with that is that while technically sound it leads to a plethora of function-specific 'no' values. So for programmer sanity agreeing on a common 'no' value, e.g. 'false', is beneficial. > > At least, _I_ don't want that to be an error, since that would > > require silly coding like: > > 1. ask if the element is there, but don't return it (query, boolean) > > 2. if it's there, get it (lookup, throws exn on failure not never here) > > when what one often wants is: > > 1. if the element is there, return it, otherwise return 'no' > > Yes, but you don't use 1+2 for dict:find() just because it might > return the atom 'error', do you? I didn't suggest that keyfind > should throw an exception. My point is that 'no' is a normal operating condition for this function (it combines query with lookup in a non-faulting way), and thus 'error' is highly inappropriate. (And yes my example was a bit off.) As an old Lisp afficionado I don't mind using [] (NIL) as the out-of-bands token, but I realize most Erlang programmers prefer atoms instead, and in that domain 'false' seems appropriate. From bgustavsson@REDACTED Wed Jan 21 14:22:40 2009 From: bgustavsson@REDACTED (Bjorn Gustavsson) Date: Wed, 21 Jan 2009 14:22:40 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <49770AA5.4000502@it.uu.se> References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> <49770AA5.4000502@it.uu.se> Message-ID: <6672d0160901210522s24335ce9j3c25f8bfd5807b72@mail.gmail.com> On Wed, Jan 21, 2009 at 12:44 PM, Richard Carlsson wrote: > > I tried to narrow it down to just one alternative suggestion, and > {ok,Value}|'error' is the convention used by dict:find. It seems > to depend on what you read into the name of the function: if the > name is "find" or "keyfind", aren't you expecting it to find the > element? You didn't use the "lookforsomethingthatmightnotbethere" > function. Anyhow, I wouldn't have suggested 'error' unless there > was some precedence for it. I prefer 'none' or 'not_found' for > this kind of return value, but consistency is also a good thing > (so maybe 'false' is still best). > For consistency with the rest of the lists module (and in particular the keysearch/3 function) I think that 'false' is the best value. (In general, I agree that "half booleans" should be avoided in new code.) /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB From nem@REDACTED Wed Jan 21 14:23:09 2009 From: nem@REDACTED (Geoff Cant) Date: Wed, 21 Jan 2009 14:23:09 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: (Christian's message of "Wed, 21 Jan 2009 12:30:55 +0100") References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> <1232536362.5027.46.camel@seasc1137.dyn.rnd.as.sw.ericsson.se> Message-ID: Christian writes: > On Wed, Jan 21, 2009 at 12:12, Bengt Kleberg wrote: >> Greetings, >> >> Rickard has my support. I, too, find mixing boolean and none boolean >> return values surprising. >> >> Perhaps {} (empty tuple) is an appropriate return value if nothing is >> found? > > The functions proplists:get_value/2,3 are the less-generalized > versions of this keyfind-function. So for consistency chose > 'undefined'. (and provide a Default-argument keyfind function as > well?) I heartily second this suggestion - being able to choose the not_found/undefined/false/error value is a big win. You can choose a value that makes sense in context: lists:keyfind(interface, 3, NetConfig, no_interfaces). Another bonus is that if you are going to replace the not_found result with some default, being able to supply the default saves you a four line case statement to do the replacement yourself. It saves you from writing: case lists:keyfind(interface, 3, NetConfig) of false -> no_interfaces; Value -> Value end It would be easy enough to supply a lists:keyfind/4 BIF and a lists:keyfind/3 function that wraps keyfind/4 with the 'false' argument. Cheers, --Geoff Cant From bgustavsson@REDACTED Wed Jan 21 14:37:35 2009 From: bgustavsson@REDACTED (Bjorn Gustavsson) Date: Wed, 21 Jan 2009 14:37:35 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: References: Message-ID: <6672d0160901210537t30ba242elf8032d0b1e53e559@mail.gmail.com> On Tue, Jan 20, 2009 at 4:15 PM, James Hague wrote: > I would like to propose the addition of lists:keyfind/3, which is > identical in structure to lists:keysearch/3, except that it returns > either 'false' or the found tuple, with no additional wrapping of the > result. This can be trivially added to the lists module: > > keyfind(K, N, L) -> > case keysearch(K, N, L) of > {_, Tuple} -> Tuple; > X -> X > end. > I have now done a prototype implementation of keyfind/3 as BIF. I did on small change to the semantics. I implemented it to be equivalent to keyfind1(Key, N, [H|T]) when element(N, H) =:= Key -> H; keyfind1(Key, N, [H|T]) -> keyfind1(Key, N, T); keyfind1(Key, N, []) -> false. rather than keyfind2(Key, N, [H|T]) when element(N, H) == Key -> H; keyfind2(Key, N, [H|T]) -> keyfind2(Key, N, T); keyfind2(Key, N, []) -> false. (keyfind1/3 uses '=:=', keyfind2/3 uses '=='). They give the same result in most cases expect when integers is compared to floats as in: 3> t:keyfind1(42, 1, [{42.0,a}]). false 4> t:keyfind2(42, 1, [{42.0,a}]). {42.0,a} I think that it was a historical accident that lists:keysearch/3 and lists:keymember/3 use '==' rather than '=:=' and that we should not repeat that mistake lists:keyfind/3. /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB From adrianob@REDACTED Wed Jan 21 14:38:18 2009 From: adrianob@REDACTED (Adriano Bonat) Date: Wed, 21 Jan 2009 11:38:18 -0200 Subject: [erlang-questions] Comet server broadcasting messages to 40k clients In-Reply-To: <4976AA1A.5030501@m5net.com> References: <6bb4c8cb0901201920k30d22c78m2458eaa9ce71ec9c@mail.gmail.com> <4976AA1A.5030501@m5net.com> Message-ID: <6bb4c8cb0901210538m5a2d42ei26ae0494176572d2@mail.gmail.com> Hi Bernard, On Wed, Jan 21, 2009 at 2:52 AM, Bernard Duggan wrote: > My first suggestion would be to check that you're using kernel polling > (do you start erl with "+K true"? You should see the string > "[kernel-poll:true]" in the version line). If not, that's probably a > significant part of it, since for every packet that comes in the VM will > be iterating over all 40k sockets to figure out which one it came from > before the message even arrives at your code. Yes, I ran the tests using kernel polling. > Also, be aware that using the -- operator on a big list can be a very > expensive operation (there was a thread about it last week, in fact), so > using it to remove a single socket from a list that big could be a > significant cost. That's one of the Joe's advices on his book :) But the latency for the message is not caused by that point... > Finally, I'd suggest that, if you haven't already tried it, you spawn a > separate thread (process, in erlang parlance) to handle each connection > rather than trying to deal with them all in one thread. While I don't > think this is going to improve your performance here, it makes your code > simpler and easier to follow. Remember, erlang processes are not like C > threads - they're cheap, plentiful and carry a much lower switching > overhead. This would involve a little more work for your case since you > want to broadcast to everyone based on a signal from anyone, but it is > more in keeping with "The Erlang Way(tm)". (Actual followers of The > Erlang Way are of course free to correct my views...). Yes, that would go with the Erlang's way, but I wanted a way that works faster. Before I implemented my own http server, I was using mochiweb, and it uses a thread per connection and has the same performance problem as using a single thread holding several connections. Any other ideas are welcome, and thanks for you reply :) Regards. From masse@REDACTED Wed Jan 21 14:46:58 2009 From: masse@REDACTED (mats cronqvist) Date: Wed, 21 Jan 2009 14:46:58 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <6672d0160901210522s24335ce9j3c25f8bfd5807b72@mail.gmail.com> (Bjorn Gustavsson's message of "Wed\, 21 Jan 2009 14\:22\:40 +0100") References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> <49770AA5.4000502@it.uu.se> <6672d0160901210522s24335ce9j3c25f8bfd5807b72@mail.gmail.com> Message-ID: <87r62wlqjx.fsf@sterlett.hq.kred> Bjorn Gustavsson writes: > > For consistency with the rest of the lists module (and in particular > the keysearch/3 function) I think that 'false' is the best value. > > (In general, I agree that "half booleans" should be avoided > in new code.) so doing it Right(tm), i.e. returning the value if found or exit(), is out of the question? seems i've written this function at least a thousand times; keyfind(Key,N,List) -> {value,{Key,Val} = lists:keysearch(Key,N,List), Val. mats From thomasl_erlang@REDACTED Wed Jan 21 13:54:14 2009 From: thomasl_erlang@REDACTED (Thomas Lindgren) Date: Wed, 21 Jan 2009 04:54:14 -0800 (PST) Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <1232536362.5027.46.camel@seasc1137.dyn.rnd.as.sw.ericsson.se> Message-ID: <312218.98172.qm@web111405.mail.gq1.yahoo.com> --- On Wed, 1/21/09, Bengt Kleberg wrote: > Rickard has my support. I, too, find mixing boolean and > none boolean > return values surprising. > > Perhaps {} (empty tuple) is an appropriate return value if > nothing is > found? > Personally, I nearly always wrap lookup return values as {found, Value} | not_found Which has served me quite well so far. (And not that it really matters for this discussion, but returning an empty tuple allocates a tuple header on the heap :-) Best, Thomas From sverker@REDACTED Wed Jan 21 16:11:18 2009 From: sverker@REDACTED (Sverker Eriksson) Date: Wed, 21 Jan 2009 16:11:18 +0100 Subject: [erlang-questions] How to get binaries when using {packet, http} In-Reply-To: <4976F0D7.1030106@erlang-consulting.com> References: <4975A6E7.10509@erix.ericsson.se> <4976F0D7.1030106@erlang-consulting.com> Message-ID: <49773B16.9000607@erix.ericsson.se> Oscar Hellstr?m wrote: > Doesn't the combination [binary, {packet, http}] mean that if the socket > is changed to return raw packets later they will be returned as binaries [...] > Yes, you are right. Which means that if binary strings are introduced in http-packets it will most probably be done with some other option, like {packet, http_bin}. /Sverker, Erlang/OTP Ericsson From zambal@REDACTED Wed Jan 21 16:15:11 2009 From: zambal@REDACTED (zambal) Date: Wed, 21 Jan 2009 07:15:11 -0800 (PST) Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <87r62wlqjx.fsf@sterlett.hq.kred> References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> <49770AA5.4000502@it.uu.se> <6672d0160901210522s24335ce9j3c25f8bfd5807b72@mail.gmail.com> <87r62wlqjx.fsf@sterlett.hq.kred> Message-ID: <9b80cca8-ea6c-403f-ae53-4cb9d4edbda8@r37g2000prr.googlegroups.com> On 21 jan, 14:46, mats cronqvist wrote: > Bjorn Gustavsson writes: > > > For consistency with the rest of the lists module (and in particular > > the keysearch/3 function) I think that 'false' is the best value. > > > (In general, I agree that "half booleans" should be avoided > > in new code.) > > ? so doing it Right(tm), i.e. returning the value if found or exit(), > ? is out of the question? > ? seems i've written this function at least a thousand times; > > keyfind(Key,N,List) -> > ? {value,{Key,Val} = lists:keysearch(Key,N,List), > ? Val. > > ? mats > _______________________________________________ > erlang-questions mailing list > erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions As a lightweight dictionary alternative, I like Mats' suggestion best: give back the value, otherwise crash. Best, Vincent From bgustavsson@REDACTED Wed Jan 21 16:28:02 2009 From: bgustavsson@REDACTED (Bjorn Gustavsson) Date: Wed, 21 Jan 2009 16:28:02 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <87r62wlqjx.fsf@sterlett.hq.kred> References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> <49770AA5.4000502@it.uu.se> <6672d0160901210522s24335ce9j3c25f8bfd5807b72@mail.gmail.com> <87r62wlqjx.fsf@sterlett.hq.kred> Message-ID: <6672d0160901210728t43598e6ep11a738a4c014a76b@mail.gmail.com> On Wed, Jan 21, 2009 at 2:46 PM, mats cronqvist wrote: > so doing it Right(tm), i.e. returning the value if found or exit(), > is out of the question? Yes. :-) > seems i've written this function at least a thousand times; > > keyfind(Key,N,List) -> > {value,{Key,Val} = lists:keysearch(Key,N,List), > Val. This version only works for tuples of size 2. /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB From masse@REDACTED Wed Jan 21 16:40:32 2009 From: masse@REDACTED (mats cronqvist) Date: Wed, 21 Jan 2009 16:40:32 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <6672d0160901210728t43598e6ep11a738a4c014a76b@mail.gmail.com> (Bjorn Gustavsson's message of "Wed\, 21 Jan 2009 16\:28\:02 +0100") References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> <49770AA5.4000502@it.uu.se> <6672d0160901210522s24335ce9j3c25f8bfd5807b72@mail.gmail.com> <87r62wlqjx.fsf@sterlett.hq.kred> <6672d0160901210728t43598e6ep11a738a4c014a76b@mail.gmail.com> Message-ID: <87mydkllan.fsf@sterlett.hq.kred> Bjorn Gustavsson writes: > On Wed, Jan 21, 2009 at 2:46 PM, mats cronqvist wrote: >> so doing it Right(tm), i.e. returning the value if found or exit(), >> is out of the question? > > Yes. :-) damn. i guess i'll have to fork OTP then. >> seems i've written this function at least a thousand times; >> >> keyfind(Key,N,List) -> >> {value,{Key,Val} = lists:keysearch(Key,N,List), >> Val. > > This version only works for tuples of size 2. it was meant as an example, not an implementation proposal. i didn't balance the braces either :< mats From als@REDACTED Wed Jan 21 15:16:40 2009 From: als@REDACTED (Anthony Shipman) Date: Thu, 22 Jan 2009 01:16:40 +1100 Subject: [erlang-questions] What's the recommended template engine for web development with erlang? In-Reply-To: <4976EFD9.2030005@gmail.com> References: <4976DAF3.7030301@gmail.com> <4976EFD9.2030005@gmail.com> Message-ID: <200901220116.40668.als@iinet.net.au> On Wed, 21 Jan 2009 08:50:17 pm Liu Yubao wrote: > Christian wrote: > >> * erldtl > >> > >> ?Pros: The template notation seems good(I hate and <%...%> :-) > >> ? ? ? ?templates are compiled to erlang modules; > >> ?Cons: not completed yet. > > > > What is a show-stopper for you about erlydtl? What is not complete > > enough for you? > > In fact, I prefer erlydtl to erltl in erlyweb because I feel erlydtl > is cleaner. I *really* don't like to embedd erlang code into html template > because it's not editor-friendly enough. You don't have to embed any more than a function call to a utility module. -- Anthony Shipman Mamas don't let your babies als@REDACTED grow up to be outsourced. From bgustavsson@REDACTED Wed Jan 21 16:49:24 2009 From: bgustavsson@REDACTED (Bjorn Gustavsson) Date: Wed, 21 Jan 2009 16:49:24 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <87mydkllan.fsf@sterlett.hq.kred> References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> <49770AA5.4000502@it.uu.se> <6672d0160901210522s24335ce9j3c25f8bfd5807b72@mail.gmail.com> <87r62wlqjx.fsf@sterlett.hq.kred> <6672d0160901210728t43598e6ep11a738a4c014a76b@mail.gmail.com> <87mydkllan.fsf@sterlett.hq.kred> Message-ID: <6672d0160901210749t1284eba1ma8fdc24e47b39aed@mail.gmail.com> On Wed, Jan 21, 2009 at 4:40 PM, mats cronqvist wrote: > Bjorn Gustavsson writes: > >>> seems i've written this function at least a thousand times; >>> >>> keyfind(Key,N,List) -> >>> {value,{Key,Val} = lists:keysearch(Key,N,List), >>> Val. >> >> This version only works for tuples of size 2. > > it was meant as an example, not an implementation proposal. i didn't > balance the braces either :< Yes, but if the tuple has more than two elements, how do you know which field the caller is interested in? Do you assume that it always the element after the key? What is the caller is interested in several fields of the tuple? /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB From rvirding@REDACTED Wed Jan 21 17:20:42 2009 From: rvirding@REDACTED (Robert Virding) Date: Wed, 21 Jan 2009 17:20:42 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <6672d0160901210749t1284eba1ma8fdc24e47b39aed@mail.gmail.com> References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> <49770AA5.4000502@it.uu.se> <6672d0160901210522s24335ce9j3c25f8bfd5807b72@mail.gmail.com> <87r62wlqjx.fsf@sterlett.hq.kred> <6672d0160901210728t43598e6ep11a738a4c014a76b@mail.gmail.com> <87mydkllan.fsf@sterlett.hq.kred> <6672d0160901210749t1284eba1ma8fdc24e47b39aed@mail.gmail.com> Message-ID: <3dbc6d1c0901210820y31e1a0bbo880ab7228a6019d6@mail.gmail.com> 2009/1/21 Bjorn Gustavsson > On Wed, Jan 21, 2009 at 4:40 PM, mats cronqvist wrote: > > Bjorn Gustavsson writes: > > > >>> seems i've written this function at least a thousand times; > >>> > >>> keyfind(Key,N,List) -> > >>> {value,{Key,Val} = lists:keysearch(Key,N,List), > >>> Val. > >> > >> This version only works for tuples of size 2. > > > > it was meant as an example, not an implementation proposal. i didn't > > balance the braces either :< > > Yes, but if the tuple has more than two elements, how do you know > which field the caller is interested in? Do you assume that it always > the element after the key? What is the caller is interested in several > fields of the tuple? I am sorry, but I think that returning something "half-tagged" like ValueTuple | false (/not_found/error/...) is horrendous and should be avoided like the plague. I think the Right Way is to tag both return values as is done with keyserach, but I agree that using {value,Val} | false is bad. If we are going to "fix" it then I would suggest two functions like in dict, find/2 to find a value if it exists and one which assumes it exists and errors otherwise. I also agree that returning 'error' is not the best as it may very well not be an error, with 20/20 hindsight I would prefer a maybe(value) so: keyfind(Key, N, List) -> {yes,Value} | no. keyfetch(Key, N, List) -> Value (or exception) If you want to be more consistent with existing modules like dict then use {ok,Value} | error instead. Just because lisp has a convention of returning value or nil, this is not something we should really copy as they also have the convention that (car ()) => () and (cdr ()) => () which are used together with functions returning nil for not found. In erlang terms that would mean hd([]) => [], tl([]) => [] and [] matches [[]]. Now this would help make LFE more lisp-like but I don't advocate it. If you are going to tag return values then you must tag them all, otherwise you will be bitten. And the extra cost *is* neglible. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob@REDACTED Wed Jan 21 17:39:58 2009 From: bob@REDACTED (Bob Ippolito) Date: Wed, 21 Jan 2009 08:39:58 -0800 Subject: [erlang-questions] Comet server broadcasting messages to 40k clients In-Reply-To: <6bb4c8cb0901210538m5a2d42ei26ae0494176572d2@mail.gmail.com> References: <6bb4c8cb0901201920k30d22c78m2458eaa9ce71ec9c@mail.gmail.com> <4976AA1A.5030501@m5net.com> <6bb4c8cb0901210538m5a2d42ei26ae0494176572d2@mail.gmail.com> Message-ID: <6a36e7290901210839s15763b99ld90545b0e9745b49@mail.gmail.com> On Wed, Jan 21, 2009 at 5:38 AM, Adriano Bonat wrote: > Hi Bernard, > > On Wed, Jan 21, 2009 at 2:52 AM, Bernard Duggan wrote: > >> My first suggestion would be to check that you're using kernel polling >> (do you start erl with "+K true"? You should see the string >> "[kernel-poll:true]" in the version line). If not, that's probably a >> significant part of it, since for every packet that comes in the VM will >> be iterating over all 40k sockets to figure out which one it came from >> before the message even arrives at your code. > > Yes, I ran the tests using kernel polling. > >> Also, be aware that using the -- operator on a big list can be a very >> expensive operation (there was a thread about it last week, in fact), so >> using it to remove a single socket from a list that big could be a >> significant cost. > > That's one of the Joe's advices on his book :) > But the latency for the message is not caused by that point... > >> Finally, I'd suggest that, if you haven't already tried it, you spawn a >> separate thread (process, in erlang parlance) to handle each connection >> rather than trying to deal with them all in one thread. While I don't >> think this is going to improve your performance here, it makes your code >> simpler and easier to follow. Remember, erlang processes are not like C >> threads - they're cheap, plentiful and carry a much lower switching >> overhead. This would involve a little more work for your case since you >> want to broadcast to everyone based on a signal from anyone, but it is >> more in keeping with "The Erlang Way(tm)". (Actual followers of The >> Erlang Way are of course free to correct my views...). > > Yes, that would go with the Erlang's way, but I wanted a way that > works faster. Before I implemented my own http server, I was using > mochiweb, and it uses a thread per connection and has the same > performance problem as using a single thread holding several > connections. > > Any other ideas are welcome, and thanks for you reply :) Maybe it's a problem with your platform? What version of Erlang and which OS/distro are you running? I haven't seen anything like 5 sec latency with mochiweb even with a lot of sockets connected. -bob From masse@REDACTED Wed Jan 21 17:58:53 2009 From: masse@REDACTED (mats cronqvist) Date: Wed, 21 Jan 2009 17:58:53 +0100 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: <6672d0160901210749t1284eba1ma8fdc24e47b39aed@mail.gmail.com> (Bjorn Gustavsson's message of "Wed\, 21 Jan 2009 16\:49\:24 +0100") References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> <49770AA5.4000502@it.uu.se> <6672d0160901210522s24335ce9j3c25f8bfd5807b72@mail.gmail.com> <87r62wlqjx.fsf@sterlett.hq.kred> <6672d0160901210728t43598e6ep11a738a4c014a76b@mail.gmail.com> <87mydkllan.fsf@sterlett.hq.kred> <6672d0160901210749t1284eba1ma8fdc24e47b39aed@mail.gmail.com> Message-ID: <87iqo8lho2.fsf@sterlett.hq.kred> Bjorn Gustavsson writes: > On Wed, Jan 21, 2009 at 4:40 PM, mats cronqvist wrote: >> Bjorn Gustavsson writes: >> >>>> seems i've written this function at least a thousand times; >>>> >>>> keyfind(Key,N,List) -> >>>> {value,{Key,Val} = lists:keysearch(Key,N,List), >>>> Val. >>> >>> This version only works for tuples of size 2. >> >> it was meant as an example, not an implementation proposal. i didn't >> balance the braces either :< > > Yes, but if the tuple has more than two elements, how do you know > which field the caller is interested in? Do you assume that it always > the element after the key? What is the caller is interested in several > fields of the tuple? my point (if there was one) was that i write this function keyfind(Key,List) -> {value,{Key,Val}} = lists:keysearch(Key,List), Val. again and again because a keyfind function should return a value of exit. if the tuple arity is > 2, it'll obviously have to return the whole yuple on success, but it should still exit on failure. alas, my example was both poorly chosen and buggy. mats From tali.wang@REDACTED Wed Jan 21 18:20:10 2009 From: tali.wang@REDACTED (Linan Wang) Date: Wed, 21 Jan 2009 17:20:10 +0000 Subject: [erlang-questions] Comet server broadcasting messages to 40k clients In-Reply-To: <6bb4c8cb0901210538m5a2d42ei26ae0494176572d2@mail.gmail.com> References: <6bb4c8cb0901201920k30d22c78m2458eaa9ce71ec9c@mail.gmail.com> <4976AA1A.5030501@m5net.com> <6bb4c8cb0901210538m5a2d42ei26ae0494176572d2@mail.gmail.com> Message-ID: how about spawn process for each send_chunk? ... TStart = now(), lists:foreach(fun(S) -> spawn(fun() -> send_chunk(S, io_lib:format("(~b usecs) Hello world!
", [timer:now_diff(now(), TStart)])) end), Sockets), (sorry to bob, clicked the wrong button :)) On Wed, Jan 21, 2009 at 1:38 PM, Adriano Bonat wrote: > Hi Bernard, > > On Wed, Jan 21, 2009 at 2:52 AM, Bernard Duggan wrote: > > > My first suggestion would be to check that you're using kernel polling > > (do you start erl with "+K true"? You should see the string > > "[kernel-poll:true]" in the version line). If not, that's probably a > > significant part of it, since for every packet that comes in the VM will > > be iterating over all 40k sockets to figure out which one it came from > > before the message even arrives at your code. > > Yes, I ran the tests using kernel polling. > > > Also, be aware that using the -- operator on a big list can be a very > > expensive operation (there was a thread about it last week, in fact), so > > using it to remove a single socket from a list that big could be a > > significant cost. > > That's one of the Joe's advices on his book :) > But the latency for the message is not caused by that point... > > > Finally, I'd suggest that, if you haven't already tried it, you spawn a > > separate thread (process, in erlang parlance) to handle each connection > > rather than trying to deal with them all in one thread. While I don't > > think this is going to improve your performance here, it makes your code > > simpler and easier to follow. Remember, erlang processes are not like C > > threads - they're cheap, plentiful and carry a much lower switching > > overhead. This would involve a little more work for your case since you > > want to broadcast to everyone based on a signal from anyone, but it is > > more in keeping with "The Erlang Way(tm)". (Actual followers of The > > Erlang Way are of course free to correct my views...). > > Yes, that would go with the Erlang's way, but I wanted a way that > works faster. Before I implemented my own http server, I was using > mochiweb, and it uses a thread per connection and has the same > performance problem as using a single thread holding several > connections. > > Any other ideas are welcome, and thanks for you reply :) > > Regards. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- Best regards Linan Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: From adrianob@REDACTED Wed Jan 21 18:30:54 2009 From: adrianob@REDACTED (Adriano Bonat) Date: Wed, 21 Jan 2009 15:30:54 -0200 Subject: [erlang-questions] Comet server broadcasting messages to 40k clients In-Reply-To: <6a36e7290901210839s15763b99ld90545b0e9745b49@mail.gmail.com> References: <6bb4c8cb0901201920k30d22c78m2458eaa9ce71ec9c@mail.gmail.com> <4976AA1A.5030501@m5net.com> <6bb4c8cb0901210538m5a2d42ei26ae0494176572d2@mail.gmail.com> <6a36e7290901210839s15763b99ld90545b0e9745b49@mail.gmail.com> Message-ID: <6bb4c8cb0901210930m5368f4fbn68edf58741da9b1a@mail.gmail.com> On Wed, Jan 21, 2009 at 2:39 PM, Bob Ippolito wrote: > > Maybe it's a problem with your platform? What version of Erlang and > which OS/distro are you running? I think no. I'm using Linux 2.6.27/Ubuntu Intrepid, and about Erlang: adriano@REDACTED:~$ erl +V Erlang (SMP,ASYNC_THREADS) (BEAM) emulator version 5.6.3 adriano@REDACTED:~$ erl +K true Erlang (BEAM) emulator version 5.6.3 [source] [smp:2] [async-threads:0] [kernel-poll:true] > I haven't seen anything like 5 sec latency with mochiweb even with a > lot of sockets connected. 5s of latency when broadcasting a message to all connected users, I'm running tests with 40k connected clients. Regards. From adrianob@REDACTED Wed Jan 21 18:33:53 2009 From: adrianob@REDACTED (Adriano Bonat) Date: Wed, 21 Jan 2009 15:33:53 -0200 Subject: [erlang-questions] Comet server broadcasting messages to 40kclients In-Reply-To: <49775958.0a0db80a.7639.ffffd192SMTPIN_ADDED@mx.google.com> References: <49775958.0a0db80a.7639.ffffd192SMTPIN_ADDED@mx.google.com> Message-ID: <6bb4c8cb0901210933h489ac8f3q689f56393d64ff6b@mail.gmail.com> On Wed, Jan 21, 2009 at 3:09 PM, wde wrote: > does the latency increase with the number of connected users ? Yes, I did tests with 100, 1000, 10k, 30k, 40k and 50k, I don't have the results here, but it seems that it grows linearly. Regards. From wde@REDACTED Wed Jan 21 18:09:39 2009 From: wde@REDACTED (wde) Date: Wed, 21 Jan 2009 18:09:39 +0100 Subject: [erlang-questions] Comet server broadcasting messages to 40kclients Message-ID: <200901211744.n0LHim3P029499@morgoth.cslab.ericsson.net> does the latency increase with the number of connected users ? How the latency increase with the number of users ? linearly ? wde ======= le 21/01/2009, 17:39:58 vous ?criviez: ======= >On Wed, Jan 21, 2009 at 5:38 AM, Adriano Bonat wrote: >> Hi Bernard, >> >> On Wed, Jan 21, 2009 at 2:52 AM, Bernard Duggan wrote: >> >>> My first suggestion would be to check that you're using kernel polling >>> (do you start erl with "+K true"? You should see the string >>> "[kernel-poll:true]" in the version line). If not, that's probably a >>> significant part of it, since for every packet that comes in the VM will >>> be iterating over all 40k sockets to figure out which one it came from >>> before the message even arrives at your code. >> >> Yes, I ran the tests using kernel polling. >> >>> Also, be aware that using the -- operator on a big list can be a very >>> expensive operation (there was a thread about it last week, in fact), so >>> using it to remove a single socket from a list that big could be a >>> significant cost. >> >> That's one of the Joe's advices on his book :) >> But the latency for the message is not caused by that point... >> >>> Finally, I'd suggest that, if you haven't already tried it, you spawn a >>> separate thread (process, in erlang parlance) to handle each connection >>> rather than trying to deal with them all in one thread. While I don't >>> think this is going to improve your performance here, it makes your code >>> simpler and easier to follow. Remember, erlang processes are not like C >>> threads - they're cheap, plentiful and carry a much lower switching >>> overhead. This would involve a little more work for your case since you >>> want to broadcast to everyone based on a signal from anyone, but it is >>> more in keeping with "The Erlang Way(tm)". (Actual followers of The >>> Erlang Way are of course free to correct my views...). >> >> Yes, that would go with the Erlang's way, but I wanted a way that >> works faster. Before I implemented my own http server, I was using >> mochiweb, and it uses a thread per connection and has the same >> performance problem as using a single thread holding several >> connections. >> >> Any other ideas are welcome, and thanks for you reply :) > >Maybe it's a problem with your platform? What version of Erlang and >which OS/distro are you running? > >I haven't seen anything like 5 sec latency with mochiweb even with a >lot of sockets connected. > >-bob >_______________________________________________ >erlang-questions mailing list >erlang-questions@REDACTED >http://www.erlang.org/mailman/listinfo/erlang-questions > = = = = = = = = = ========= = = = = = = = = = = wde wde@REDACTED 21/01/2009 From ad.sergey@REDACTED Wed Jan 21 23:09:28 2009 From: ad.sergey@REDACTED (Sergey S) Date: Wed, 21 Jan 2009 14:09:28 -0800 Subject: [erlang-questions] How to properly declare a special process in supervisor's child specification? In-Reply-To: <852bdec87d75280448dd485e121cf294.squirrel@www.geekisp.com> References: <852bdec87d75280448dd485e121cf294.squirrel@www.geekisp.com> Message-ID: Hello. > You will find in the "Child specifications" section of the "Design > Principles" chapter that dynamic should only be used when the child is a > gen_event. When the child is a supervisor, gen_server or gen_fsm, use > [Module]. OK, I understand. The rule is "for anything other that gen_event always use [Module]". -- Sergey From bernie@REDACTED Wed Jan 21 23:36:46 2009 From: bernie@REDACTED (Bernard Duggan) Date: Thu, 22 Jan 2009 09:36:46 +1100 Subject: [erlang-questions] Deleting from a duplicate_bag ets table Message-ID: <4977A37E.3010600@m5net.com> Hi list, This is probably a really stupid question, but I'm damned if I can figure it out: If I have an ets table of type duplicate_bag, and I put two of the same item in it, how do I delete just one of them? In code: T = ets:new(t, [duplicate_bag]), ets:insert(T, {1, 2}), ets:insert(T, {1, 2}), At this point T contains two elements, both {1, 2}. I now want to delete one of them. The options for deleting from an ets table seem to be: ets:delete/2 - Deletes /all/ objects with the supplied key. ets:delete_object/2 - Deletes /all/ copies of the supplied object. ets:match_delete/2 - Deletes /all/ objects that match the pattern ets:select_delete/2 - I'm not aware of any way to limit the number of returns in a MatchSpec (and the presence of ets:select/3 where you can supply a limit seems to support this), so unless I'm missing something that one won't work either. ...And now I'm out of ideas :) The only option I can see left is to remove all N copies of the object and re-insert N-1 of them. Any suggestions will be gratefully received. If the answer is "you can't do it", might I suggest adding a select_delete/3, in the same style as select/3? Cheers, Bernard From cureadvocate@REDACTED Wed Jan 21 23:46:13 2009 From: cureadvocate@REDACTED (Steven Edwards) Date: Wed, 21 Jan 2009 17:46:13 -0500 Subject: [erlang-questions] I'm not worthy (anthropomorphism ahead) Message-ID: For background, I'm developing what amounts to a photo-sharing site that will allow some simple image processing. I stumbled upon Erlang and YAWS* late last month while searching for a light web server (other than Lighttpd and Nginx) that could scale and developed a slight crush on the language. I never thought we would move beyond the whole awkward friendship stage, but--after our last date--I am now ready to propose. We spent about ten minutes together and she was ready (and willing!) to serve images. Her only condition: a properly formatted RPC message. Wow! (If I ask real nice, I bet I can get her to speak gzip for me.) I think I'm in love. :D Steven * I still haven't decided whether to use YAWS or Mochiweb, but that's irrelevant: this message was just meant to praise Erlang. My only question: which Ericsson office is the Mecca of Erlang? I need to know which direction to pray. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From ad.sergey@REDACTED Thu Jan 22 00:21:15 2009 From: ad.sergey@REDACTED (Sergey S) Date: Wed, 21 Jan 2009 15:21:15 -0800 Subject: [erlang-questions] Finding a way to get function name from local function reference In-Reply-To: References: <006cb7fc-22f3-455f-95c3-ada2e5725ad1@s1g2000prg.googlegroups.com> Message-ID: Hello. > Yes. I *completely* misread and misunderstood the question . Hm... Your suggestion was helpful to me. I've rewritten the module for testing out performace of fuctions using apply as you suggested. Thanks. Sources of the module itself and sample.erl illustrating how to use it can be found here: http://gist.github.com/50240 bm:funs/4 takes module name, list of function names (or name prefix which all functions to test begin with), arguments to pass and number of iterates. Then it tests them and fine prints sorted results: 1> sample:bm(). decompress_2..........1130 (1134) ms. decompress_1..........1500 (1531) ms. decompress_3..........1530 (1525) ms. Of cource, it would be much better to have the possibility of using function references, but it looks like there is no way to get the names of them at runtime (in the general case). -- Sergey From vances@REDACTED Thu Jan 22 00:24:50 2009 From: vances@REDACTED (Vance Shipley) Date: Wed, 21 Jan 2009 18:24:50 -0500 Subject: [erlang-questions] I'm not worthy (anthropomorphism ahead) In-Reply-To: References: Message-ID: <20090121232450.GL2497@h216-235-12-171.host.egate.net> http://www.erlang.se/contact/alvsjo.shtml On Wed, Jan 21, 2009 at 05:46:13PM -0500, Steven Edwards wrote: } which Ericsson office is the Mecca of Erlang? I need to know which } direction to pray. :) From cureadvocate@REDACTED Thu Jan 22 00:30:29 2009 From: cureadvocate@REDACTED (Steven Edwards) Date: Wed, 21 Jan 2009 18:30:29 -0500 Subject: [erlang-questions] I'm not worthy (anthropomorphism ahead) In-Reply-To: <20090121232450.GL2497@h216-235-12-171.host.egate.net> References: <20090121232450.GL2497@h216-235-12-171.host.egate.net> Message-ID: Hah! Thanks! On Wed, Jan 21, 2009 at 6:24 PM, Vance Shipley wrote: > http://www.erlang.se/contact/alvsjo.shtml > > On Wed, Jan 21, 2009 at 05:46:13PM -0500, Steven Edwards wrote: > } which Ericsson office is the Mecca of Erlang? I need to know which > } direction to pray. :) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drcabana@REDACTED Thu Jan 22 04:51:46 2009 From: drcabana@REDACTED (David Cabana) Date: Wed, 21 Jan 2009 22:51:46 -0500 Subject: [erlang-questions] question re parallel map code on pg 366 of "Programming Erlang" Message-ID: <44ed5e0f0901211951i33280b69h7b95b3303f8d154c@mail.gmail.com> I have a question re Joe's parallel map code on page 366 of Programming Erlang. Here's the code, modulo a couple of variable name changes. pmap(F, Arglist) -> S = self(), TaskID = make_ref(), Workers = lists:map( fun(X) -> spawn( fun() -> do_F(S, TaskID, F, X ) end) end, Arglist), gather(Workers, TaskID). do_F(Caller, TaskID, F, X) -> Caller ! {self(), TaskID, catch(F(X))}. gather([W|R], TaskID) -> receive {W, TaskID, Val}-> [Val | gather(R, TaskID)] end; gather([], _) -> []. My question concerns the use of catch inside the do_F function. Here's what Joe says on page 367: "In pmap we use catch(F(H)) when we map the function over the list. In map we just use F(H). This is because we want to make sure pmap terminates correctly in the case where the computation of F(H) raises an exception." I don't get it. If the computation of F(H) raises an exception, presumably it would do so whether F was called by map or by pmap. Why catch the exception in the one case but not the other? Why is it important that pmap terminate normally, but not so that map terminate normally? Thanks, drc From hayeah@REDACTED Thu Jan 22 05:08:07 2009 From: hayeah@REDACTED (Howard Yeh) Date: Wed, 21 Jan 2009 20:08:07 -0800 Subject: [erlang-questions] question re parallel map code on pg 366 of "Programming Erlang" In-Reply-To: <44ed5e0f0901211951i33280b69h7b95b3303f8d154c@mail.gmail.com> References: <44ed5e0f0901211951i33280b69h7b95b3303f8d154c@mail.gmail.com> Message-ID: On Wed, Jan 21, 2009 at 7:51 PM, David Cabana wrote: > I have a question re Joe's parallel map code on page 366 of Programming Erlang. > Here's the code, modulo a couple of variable name changes. > > pmap(F, Arglist) -> > S = self(), > TaskID = make_ref(), > Workers = lists:map( fun(X) -> > spawn( fun() -> do_F(S, TaskID, F, X ) end) > end, Arglist), > gather(Workers, TaskID). > > do_F(Caller, TaskID, F, X) -> > Caller ! {self(), TaskID, catch(F(X))}. > > gather([W|R], TaskID) -> > receive > {W, TaskID, Val}-> > [Val | gather(R, TaskID)] > end; > > gather([], _) -> > []. > > My question concerns the use of catch inside the do_F function. Here's what Joe > says on page 367: > > "In pmap we use catch(F(H)) when we map the function over the list. In > map we just > use F(H). This is because we want to make sure pmap terminates > correctly in the case > where the computation of F(H) raises an exception." > > I don't get it. > > If the computation of F(H) raises an exception, presumably it would do > so whether F was called by > map or by pmap. Why catch the exception in the one case but not the other? > Why is it important that pmap terminate normally, but not so that map > terminate normally? > i think the difference is cultural. This example demonstrates a simple mapreducesque thing. pmap (mapreduce) prefers to skip over a few instances of errors so long as everything else is ok. map is more programming-in-the-small, so it would make sense to raise (just as you would in a loop). so pmap and map has the same semantic, but different pragmatics. > Thanks, > drc > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From bgustavsson@REDACTED Thu Jan 22 07:27:17 2009 From: bgustavsson@REDACTED (Bjorn Gustavsson) Date: Thu, 22 Jan 2009 07:27:17 +0100 Subject: [erlang-questions] question re parallel map code on pg 366 of "Programming Erlang" In-Reply-To: <44ed5e0f0901211951i33280b69h7b95b3303f8d154c@mail.gmail.com> References: <44ed5e0f0901211951i33280b69h7b95b3303f8d154c@mail.gmail.com> Message-ID: <6672d0160901212227n1010b17em6685fec18e645389@mail.gmail.com> On Thu, Jan 22, 2009 at 4:51 AM, David Cabana wrote: > If the computation of F(H) raises an exception, presumably it would do > so whether F was called by > map or by pmap. Why catch the exception in the one case but not the other? > Why is it important that pmap terminate normally, but not so that map > terminate normally? Because the exception happens in another process. If one of the worker processes dies and does not deliver a result, the main process (the one calling pmap/2) would hang forever in the gather/2 function. /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB From raimo+erlang-questions@REDACTED Thu Jan 22 08:53:51 2009 From: raimo+erlang-questions@REDACTED (Raimo Niskanen) Date: Thu, 22 Jan 2009 08:53:51 +0100 Subject: [erlang-questions] sctp_peer_addr_params In-Reply-To: References: Message-ID: <20090122075351.GA622@erix.ericsson.se> On Wed, Jan 21, 2009 at 07:52:56AM +0100, Mikael Lixenstrand wrote: > I'm trying to change the sack delay in gen_sctp > > {ok,Socket} = gen_sctp:open([{ip, ServerIPAddress}, {port, ServerPort}] > ++ [{sctp_peer_addr_params, #sctp_paddrparams{ assoc_id = 0, address = > {ServerIPAddress ,ServerPort} ,sackdelay = 400}}, > {mode, binary}, > {active, false}, > {sctp_events,#sctp_event_subscribe{address_event = false, > shutdown_event=false}}]), > > I tried several approaches but with the same result: > > Error in process <0.7100.1> on node 'mikael@REDACTED' with exit value: > {badarg,[{gen_sctp,open,[[{ip,{10,70,160,17}},{port,3868},{sctp_peer_addr_params,{sctp_paddrparams,0,{{10,70,160,17},3868},200,5,600,400,[]}},{mode,binary},{active,false},{sctp_events,{sctp_event_subscribe,undefined,undefined,false,undefined,undefined... > > I'm running R12B-0 on rhel 5.2 > Congratulations, you have found a bug! You have dived down to the untested parts of the SCTP code. It is still something we have left to do to write thorough test cases for gen_sctp. Unfortunately there are a _lot_ of options and functionality to test so it is a big task. Nevertheless.. The decoding in the inet driver for #sctp_paddrparams{address={IP,P}} is wrong; it does not expect the address family byte that it gets and detects a parameter length mismatch. I had a small patch yesterday, but I could not set default sctp_peer_addr_params for future associations, so I started to read the spec, and indeed it should be possible. So yesterdays 2 character patch of inet_drv.c now is a patch for erts/configure.in, inet_drv.c and prim_inet.erl. I will do some more testing and post a patch hopefully during the day. > Thanks > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions -- / Raimo Niskanen, Erlang/OTP, Ericsson AB From raimo+erlang-questions@REDACTED Thu Jan 22 09:22:24 2009 From: raimo+erlang-questions@REDACTED (Raimo Niskanen) Date: Thu, 22 Jan 2009 09:22:24 +0100 Subject: [erlang-questions] : lists:keyfind as an alternative to lists:keysearch In-Reply-To: <3dbc6d1c0901210820y31e1a0bbo880ab7228a6019d6@mail.gmail.com> References: <6672d0160901210124s1b97ced9wc614f27432e4612b@mail.gmail.com> <4976F13D.7000900@it.uu.se> <18806.65016.240131.576703@harpo.it.uu.se> <49770AA5.4000502@it.uu.se> <6672d0160901210522s24335ce9j3c25f8bfd5807b72@mail.gmail.com> <87r62wlqjx.fsf@sterlett.hq.kred> <6672d0160901210728t43598e6ep11a738a4c014a76b@mail.gmail.com> <87mydkllan.fsf@sterlett.hq.kred> <6672d0160901210749t1284eba1ma8fdc24e47b39aed@mail.gmail.com> <3dbc6d1c0901210820y31e1a0bbo880ab7228a6019d6@mail.gmail.com> Message-ID: <20090122082224.GB622@erix.ericsson.se> On Wed, Jan 21, 2009 at 05:20:42PM +0100, Robert Virding wrote: > 2009/1/21 Bjorn Gustavsson > > > On Wed, Jan 21, 2009 at 4:40 PM, mats cronqvist wrote: > > > Bjorn Gustavsson writes: > > > > > >>> seems i've written this function at least a thousand times; > > >>> > > >>> keyfind(Key,N,List) -> > > >>> {value,{Key,Val} = lists:keysearch(Key,N,List), > > >>> Val. > > >> > > >> This version only works for tuples of size 2. > > > > > > it was meant as an example, not an implementation proposal. i didn't > > > balance the braces either :< > > > > Yes, but if the tuple has more than two elements, how do you know > > which field the caller is interested in? Do you assume that it always > > the element after the key? What is the caller is interested in several > > fields of the tuple? > > > I am sorry, but I think that returning something "half-tagged" like > ValueTuple | false (/not_found/error/...) is horrendous and should be > avoided like the plague. I think the Right Way is to tag both return values > as is done with keyserach, but I agree that using {value,Val} | false is In the everlasting battle between efficiency and beauty, I think in this case the fact that anything found will have to be a tuple should be exploited for the sake of efficiency. That is; I vote for keyfind/3 -> Tuple | false. Otherwise the demand for a more efficient keyfind/3 function will eventually come. Anyone willing to sacrifice efficienty can write their own wrapper. The other way around is not possible. For a general lookup function i think the suggested arity 4 function is very handy. If you are able to choose your "not found" value, you can always use a ref() and thus build both a "crash when not found" function, or a "always tagged return value". But for an efficient general lookup API there should exist a "crash when not found" function _and_ a "always tagged return value" function. For lists:keyfind/3 or any *:*key* function this is not necessary. > bad. If we are going to "fix" it then I would suggest two functions like in > dict, find/2 to find a value if it exists and one which assumes it exists > and errors otherwise. I also agree that returning 'error' is not the best as > it may very well not be an error, with 20/20 hindsight I would prefer a > maybe(value) so: > > keyfind(Key, N, List) -> {yes,Value} | no. > keyfetch(Key, N, List) -> Value (or exception) > > If you want to be more consistent with existing modules like dict then use > {ok,Value} | error instead. > > Just because lisp has a convention of returning value or nil, this is not > something we should really copy as they also have the convention that (car > ()) => () and (cdr ()) => () which are used together with functions > returning nil for not found. In erlang terms that would mean hd([]) => [], > tl([]) => [] and [] matches [[]]. > > Now this would help make LFE more lisp-like but I don't advocate it. > > If you are going to tag return values then you must tag them all, otherwise > you will be bitten. And the extra cost *is* neglible. > > Robert > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions -- / Raimo Niskanen, Erlang/OTP, Ericsson AB From gunilla.arendt@REDACTED Thu Jan 22 09:41:14 2009 From: gunilla.arendt@REDACTED (Gunilla Arendt) Date: Thu, 22 Jan 2009 09:41:14 +0100 Subject: [erlang-questions] How to properly declare a special process insupervisor's child specification? In-Reply-To: References: Message-ID: <63E39ADA42BF8B49BEAE3666683A2484081E34A4@esealmw107.eemea.ericsson.se> Hi, As it says in the man page for supervisor, 'Modules' is used by the release handler to determine which processes are using a certain module during code replacement. This means that if the value of 'Modules' is [foo,bar] the release handler will suspend your special process and tell it to upgrade before a new version of the foo or the bar module is loaded. And normally, you would want to suspend/upgrade your process before loading a new version of its callback module. So normally, 'Modules' would be a list containing the name(s) of the callback module(s). You can read more about this in OTP Design Principles, chapter 11.4.2 (Release Handling/Release Handling Instructions/update). If you don't use release handling/OTP code replacement the value of 'Modules' is not important as it is never used. Best regards, Gunilla -----Original Message----- From: erlang-questions-bounces@REDACTED [mailto:erlang-questions-bounces@REDACTED] On Behalf Of Sergey S Sent: den 21 januari 2009 00:18 To: erlang-questions@REDACTED Subject: [erlang-questions] How to properly declare a special process insupervisor's child specification? Hello. Saying "special process" I mean a process implemented using proc_lib/sys facilities as illustrated in OTP Design Principles. What should I use in "Modules" placeholder of child specification: child_spec() = {_, _, _, _, _, Modules} [Module] or dynamic? erl -man supervisor doesnt' give the answer: -------------------8<------------------- "As a rule of thumb Modules should be a list with one element [Module], where Module is the callback module, if the child process is a >>> supervisor, gen_server or gen_fsm <<<. If the child process is an >>> event manager (gen_event) <<< with a dynamic set of callback modules, Modules should be dynamic." -------------------8<------------------- But my process isn't supervisor, gen_server, gen_fsm nor gen_event. But it's implemented to work like gen_server... OTP Design Principles also says nothing about that (or at least I didn't find anything making this clear) I'm using "dynamic" now, but I'm not sure that it's right. -- Sergey _______________________________________________ erlang-questions mailing list erlang-questions@REDACTED http://www.erlang.org/mailman/listinfo/erlang-questions From steven.charles.davis@REDACTED Thu Jan 22 10:19:03 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Thu, 22 Jan 2009 03:19:03 -0600 Subject: [erlang-questions] Finding a way to get function name from local function reference In-Reply-To: References: <006cb7fc-22f3-455f-95c3-ada2e5725ad1@s1g2000prg.googlegroups.com> Message-ID: <49783A07.50608@gmail.com> Hi Sergey, Then... I am pleased to have helped :) Coming from Java I too was used to a large measure of reflection support. I think that perhaps it's inherent in the compilation/bytecode of erlang that there's limits on this. e.g. to get full debugging info in erlang you must have a compiler switch set that saves abstract code with the Beam format. For most purposes this "limitation" will be of no conseqence, of course, and I actually view this as an advantage, since it means that there is greater commercial protection for redistributed, compiled code (You can even protect the abstract code you save in the beam (the compile:file encrypt_debug_info option). This, of course, is one rather small advantage amongst a veritable universe of advantages that Erlang has over Java et al. /s Sergey S wrote: > Hello. > >> Yes. I *completely* misread and misunderstood the question . > > Hm... Your suggestion was helpful to me. I've rewritten the module for > testing out performace of fuctions using apply as you suggested. > Thanks. > > Sources of the module itself and sample.erl illustrating how to use it > can be found here: http://gist.github.com/50240 > > bm:funs/4 takes module name, list of function names (or name prefix > which all functions to test begin with), arguments to pass and number > of iterates. Then it tests them and fine prints sorted results: > > 1> sample:bm(). > decompress_2..........1130 (1134) ms. > decompress_1..........1500 (1531) ms. > decompress_3..........1530 (1525) ms. > > Of cource, it would be much better to have the possibility of using > function references, but it looks like there is no way to get the > names of them at runtime (in the general case). > > -- > Sergey > From torben.lehoff@REDACTED Thu Jan 22 11:04:43 2009 From: torben.lehoff@REDACTED (Torben Hoffmann) Date: Thu, 22 Jan 2009 11:04:43 +0100 Subject: [erlang-questions] Registering a process with multiple names Message-ID: Hi, I have implemented a protocol stack and the current implementation has a coordinator process that keeps track of the processes that are spawned to handle the individual calls (very telcom protocol). The reason for this is that I have two types of call identifies: one at the top of the stack that represents my connection to our legacy system and one at the bottom of the stack that represents the protocol's call. When I get a message from our legacy system my coordinator process looks up in its list of spawned processes and finds the process for that message based on the legacy call identifier. Likewise when I get a message from the protocol: the call identifier is used by the coordinator to find the process to send the message to. In my ideal world I would like to register the call process with two names: one for the legacy call identificator and on for the protocol's call identificator. Then my coordinator could look up if a process has been spawned for a call identificator (legacy or protocol) and then forward the message. If there hasn't been spawned a process for the call the coordinator spawns a new one and registers it. The problem is that erlang:register/2 barfs if you try to register a process more than once. Surely I am not the first to run into this type of problem so I am hoping that the someone has some ideas for me! Thanks in advance, Torben -------------- next part -------------- An HTML attachment was scrubbed... URL: From vladdu55@REDACTED Thu Jan 22 11:40:00 2009 From: vladdu55@REDACTED (Vlad Dumitrescu) Date: Thu, 22 Jan 2009 11:40:00 +0100 Subject: [erlang-questions] Registering a process with multiple names In-Reply-To: References: Message-ID: <95be1d3b0901220240p437b4f5fj913f69d6bfba08ed@mail.gmail.com> Hi! 2009/1/22 Torben Hoffmann : > In my ideal world I would like to register the call process with two names: > one for the legacy call identificator and on for the protocol's call > identificator. > > The problem is that erlang:register/2 barfs if you try to register a process > more than once. You could use your own registry, that would keep track of both names and map them to either a registered name or a pid. If your process names are dynamically generated, you might want to avoid using atoms (i.e. erlang:register/2) for them. Your registry could use any term as name. regards, Vlad From raimo+erlang-questions@REDACTED Thu Jan 22 11:58:16 2009 From: raimo+erlang-questions@REDACTED (Raimo Niskanen) Date: Thu, 22 Jan 2009 11:58:16 +0100 Subject: [erlang-questions] : sctp_peer_addr_params In-Reply-To: <20090122075351.GA622@erix.ericsson.se> References: <20090122075351.GA622@erix.ericsson.se> Message-ID: <20090122105816.GA5043@erix.ericsson.se> On Thu, Jan 22, 2009 at 08:53:51AM +0100, Raimo Niskanen wrote: > On Wed, Jan 21, 2009 at 07:52:56AM +0100, Mikael Lixenstrand wrote: > > I'm trying to change the sack delay in gen_sctp > > > > {ok,Socket} = gen_sctp:open([{ip, ServerIPAddress}, {port, ServerPort}] > > ++ [{sctp_peer_addr_params, #sctp_paddrparams{ assoc_id = 0, address = > > {ServerIPAddress ,ServerPort} ,sackdelay = 400}}, > > {mode, binary}, > > {active, false}, > > {sctp_events,#sctp_event_subscribe{address_event = false, > > shutdown_event=false}}]), > > > > I tried several approaches but with the same result: > > > > Error in process <0.7100.1> on node 'mikael@REDACTED' with exit value: > > {badarg,[{gen_sctp,open,[[{ip,{10,70,160,17}},{port,3868},{sctp_peer_addr_params,{sctp_paddrparams,0,{{10,70,160,17},3868},200,5,600,400,[]}},{mode,binary},{active,false},{sctp_events,{sctp_event_subscribe,undefined,undefined,false,undefined,undefined... > > > > I'm running R12B-0 on rhel 5.2 > > > > Congratulations, you have found a bug! > > You have dived down to the untested parts of the SCTP code. > It is still something we have left to do to write thorough > test cases for gen_sctp. Unfortunately there are a _lot_ > of options and functionality to test so it is a big task. > > Nevertheless.. > > The decoding in the inet driver for #sctp_paddrparams{address={IP,P}} > is wrong; it does not expect the address family byte that it gets > and detects a parameter length mismatch. > > I had a small patch yesterday, but I could not set default > sctp_peer_addr_params for future associations, so I started > to read the spec, and indeed it should be possible. > > So yesterdays 2 character patch of inet_drv.c now is a patch > for erts/configure.in, inet_drv.c and prim_inet.erl. I will > do some more testing and post a patch hopefully during the day. Here is the patch. Unfortunately it is a minimal path for the current development branch so it will not be applied cleanly to R12B-5 or any other released source. But applying it manually should be no problem for the initiated user. erts/configure.in: Spelling error `ssh_data' -> `ssf_data' To do this manually to its autoconf result erts/configure change all occurences of `ssh_data' to `ssf_data' while preserving case. I have searched and there are no false occurences. erts/emulator/drivers/common/inet_drv.c: Two changes of inet_set_address -> inet_set_faddress. A few changes of HAVE_SCTP_* -> HAVE_STRUCT_SCTP_*. Use the patch to find the places. erts/preloaded/src/prim_inet.erl: This file has moved in our development branch; I think it was in lib/kernerl/src in R12B-5. With these patches it appears to work. Note that it is the peers address and port you use in the option! To set it on future associations you must not specify the peer address or association id. This is now possible thanks to the prim_inet.erl patch. Without that patch you could use address={{0,0,0,0},0} and assoc_id=0. See http://tools.ietf.org/html/draft-ietf-tsvwg-sctpsocket-13#section-7 just before section 7.1, and http://tools.ietf.org/html/draft-ietf-tsvwg-sctpsocket-13#section-7.1.13 In one erlang shell: Erlang R13A (erts-5.7) [64-bit] [smp:4] [async-threads:0] [kernel-poll:false] Eshell V5.7 (abort with ^G) 1> gen_sctp:open([{ip,loopback}]). {ok,#Port<0.444>} 2> {ok,S} = v(-1). {ok,#Port<0.444>} 3> gen_sctp:listen(S, true). ok 4> inet:port(S). {ok,32850} And then the action in another erlang shell: Erlang R13A (erts-5.7) [64-bit] [smp:4] [async-threads:0] [kernel-poll:false] Eshell V5.7 (abort with ^G) 1> rr(inet). [connect_opts,hostent,listen_opts,sctp_adaptation_event, sctp_assoc_change,sctp_assoc_value,sctp_assocparams, sctp_event_subscribe,sctp_initmsg,sctp_opts, sctp_paddr_change,sctp_paddrinfo,sctp_paddrparams, sctp_pdapi_event,sctp_prim,sctp_remote_error,sctp_rtoinfo, sctp_send_failed,sctp_setadaptation,sctp_setpeerprim, sctp_shutdown_event,sctp_sndrcvinfo,sctp_status,udp_opts] 2> {ok,S} = gen_sctp:open([{sctp_peer_addr_params, #sctp_paddrparams{sackdelay=400,flags=[sackdelay_enable]}}]). {ok,#Port<0.456>} 3> gen_sctp:connect(S, localhost, 32850, []). {ok,#sctp_assoc_change{state = comm_up,error = 0, outbound_streams = 10,inbound_streams = 10, assoc_id = 1}} 4> inet:setopts(S, [{sctp_peer_addr_params, #sctp_paddrparams{sackdelay=500,flags=[sackdelay_enable],assoc_id=1,address={loopback,32850}}}]). ok 5> inet:getopts(S, [sctp_peer_addr_params]). {ok,[{sctp_peer_addr_params, #sctp_paddrparams{ assoc_id = 0, address = {{0,0,0,0},0}, hbinterval = 30000,pathmaxrxt = 5,pathmtu = 0, sackdelay = 400, flags = [hb_enable,pmtud_enable,sackdelay_enable]}}]} 6> inet:getopts(S, [{sctp_peer_addr_params, #sctp_paddrparams{assoc_id=1,address={loopback,32850}}}]). {ok,[{sctp_peer_addr_params, #sctp_paddrparams{ assoc_id = 1, address = {{127,0,0,1},32850}, hbinterval = 30000,pathmaxrxt = 5,pathmtu = 16436, sackdelay = 500, flags = [hb_enable,pmtud_enable,sackdelay_enable]}}]} > > > Thanks > > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions@REDACTED > > http://www.erlang.org/mailman/listinfo/erlang-questions > > -- > > / Raimo Niskanen, Erlang/OTP, Ericsson AB > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions -- / Raimo Niskanen, Erlang/OTP, Ericsson AB -------------- next part -------------- A non-text attachment was scrubbed... Name: configure.in.patch Type: text/x-patch Size: 915 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: inet_drv.in.patch Type: text/x-patch Size: 4927 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: prim_inet.erl.patch Type: text/x-patch Size: 1890 bytes Desc: not available URL: From C.Grasl@REDACTED Thu Jan 22 12:24:45 2009 From: C.Grasl@REDACTED (Grasl Christoph) Date: Thu, 22 Jan 2009 12:24:45 +0100 Subject: [erlang-questions] snmp vacm.conf erronous behaviour Message-ID: <94C5430AA547F24AA801BA5706F29D2E25CE56@srvkeyx01.KEYTRONIX.local> hi OTP-team! erronous behaviour report: If 'any' is used for the 'SecModel' in the 'vacm.conf' in the 'vacmSecurityToGroup' declaration the snmp framework returns a error with the reason 'noGroupName'. It seems to be that there's a conflict with the 'SecName' when the agent is only configured for v1 and v2c and 'any' is used as value for 'SecModel'. EXAMPLE: [community.conf] {"1", "public", "secName", "", ""}. {"2", "all-rights", "all-rights", "", ""}. {"3", "standard trap", "initial", "", ""}. [vacm.conf] doesn't work: {vacmSecurityToGroup, any, "secName", "group1"}. {vacmSecurityToGroup, any, "secName", "group2"}. {vacmAccess, "group1", "", any, noAuthNoPriv, exact, "sys", "sys", "sys"}. {vacmAccess, "group2", "", any, noAuthNoPriv, exact, "sys", "sys", "sys"}. {vacmViewTreeFamily, "sys", [1,3,6,1,2,1,1], included, null}. does work: {vacmSecurityToGroup, v1, "secName", "group1"}. {vacmSecurityToGroup, v2c, "secName", "group1"}. {vacmSecurityToGroup, v1, "all-rights", "group2"}. {vacmSecurityToGroup, v2c, "all-rights", "group2"}. {vacmAccess, "group1", "", any, noAuthNoPriv, exact, "sys", "sys", "sys"}. {vacmAccess, "group2", "", any, noAuthNoPriv, exact, "sys", "sys", "sys"}. {vacmViewTreeFamily, "sys", [1,3,6,1,2,1,1], included, null}. also: The documentation under http://erlang.org/doc/apps/snmp/snmp_agent_config_files.html#vacm states that the value for 'ViewIndex' in the 'vacmViewTreeFamily' declaration is an integer. Is this a documentation error (the 'vacmViewTreeFamily' declaration could never match the 'VIEWs' this way) or does the mentioned data-type relate to the internal representation in the db? EXAMPLE (with an obvious result..): [vacm.conf] %% {vacmSecurityToGroup, SecModel, SecurityName, GroupName}. %% {vacmAccess, GroupName, Prefix, SecModel, SecLevel, Match, ReadView, WriteView, NotifyView}. %% {vacmViewTreeFamily, ViewIndex, ViewSubtree, ViewStatus, ViewMask}. {vacmSecurityToGroup, v1, "secName", "group_1"}. {vacmSecurityToGroup, v2c, "secName", "group_1"}. {vacmSecurityToGroup, v1, "all-rights", "group_1"}. {vacmSecurityToGroup, v2c, "all-rights", "group_1"}. {vacmAccess, "group_1", "", any, noAuthNoPriv, exact, "sys", "sys", "sys"}. {vacmViewTreeFamily, 23, [1,3,6,1,2,1,1], included, null}. RESULT: =ERROR REPORT==== 22-Jan-2009::12:09:02 === ** Configuration error: [VIEW-BASED-ACM-MIB]: reconfigure failed: {failed_check, "/opt/app/data/snmp/vacm.conf", 25,26, {invalid_string, 23}} 02.637'751 "."** exception exit: {noproc, {gen_server,call, [snmp_master_agent, {load_mibs, ["/opt/app/data/snmp/KEYTRONIX-CHRONOS-MIB"]}, infinity]}} in function gen_server:call/3 in call from snmp_handler:start/1 does work: {vacmSecurityToGroup, v1, "secName", "group_1"}. {vacmSecurityToGroup, v2c, "secName", "group_1"}. {vacmSecurityToGroup, v1, "all-rights", "group_1"}. {vacmSecurityToGroup, v2c, "all-rights", "group_1"}. {vacmAccess, "group_1", "", any, noAuthNoPriv, exact, "sys", "sys", "sys"}. {vacmViewTreeFamily,"sys", [1,3,6,1,2,1,1], included, null}. all the best, Christoph Grasl Embedded Software Entwickler KEYTRONIX Gesellschaft f?r industrielle Elektronik und Informationstechnologie mbH Ungargasse 64-66/1/109 A-1030 WIEN E-Mail: c.grasl@REDACTED Tel.: +43 (1) 718 06 60 - 323 Mobil: +43 (664) 8556456 WWW: http://www.keytronix.com HG Wien FN 261131t Confidentiality Notice: This message may contain privileged and confidential information. If you think, for any reason, that this message may have been addressed to you in error, you must not disseminate, copy or take any action in reliance on it, and we would ask you to notify us immediately by return email. If 'any' is used for the 'SecModel' in the 'vacm.conf' in the 'vacmSecurityToGroup' declaration the snmp framework returns a error with the reason 'noGroupName'. It seems to be that there's a conflict with the 'SecName' when the agent is only configured for v1 and v2c and 'any' is used as value for 'SecModel'. EXAMPLE: [community.conf] {"1", "public", "secName", "", ""}. {"2", "all-rights", "all-rights", "", ""}. {"3", "standard trap", "initial", "", ""}. [vacm.conf] doesn't work: {vacmSecurityToGroup, any, "secName", "group1"}. {vacmSecurityToGroup, any, "secName", "group2"}. {vacmAccess, "group1", "", any, noAuthNoPriv, exact, "sys", "sys", "sys"}. {vacmAccess, "group2", "", any, noAuthNoPriv, exact, "sys", "sys", "sys"}. {vacmViewTreeFamily, "sys", [1,3,6,1,2,1,1], included, null}. does work: {vacmSecurityToGroup, v1, "secName", "group1"}. {vacmSecurityToGroup, v2c, "secName", "group1"}. {vacmSecurityToGroup, v1, "all-rights", "group2"}. {vacmSecurityToGroup, v2c, "all-rights", "group2"}. {vacmAccess, "group1", "", any, noAuthNoPriv, exact, "sys", "sys", "sys"}. {vacmAccess, "group2", "", any, noAuthNoPriv, exact, "sys", "sys", "sys"}. {vacmViewTreeFamily, "sys", [1,3,6,1,2,1,1], included, null}. also: The documentation under http://erlang.org/doc/apps/snmp/snmp_agent_config_files.html#vacm states that the value for 'ViewIndex' in the 'vacmViewTreeFamily' declaration is an integer. Is this a documentation error (the 'vacmViewTreeFamily' declaration could never match the 'VIEWs' this way) or does the mentioned data-type relate to the internal representation in the db? EXAMPLE (with an obvious result..): [vacm.conf] %% {vacmSecurityToGroup, SecModel, SecurityName, GroupName}. %% {vacmAccess, GroupName, Prefix, SecModel, SecLevel, Match, ReadView, WriteView, NotifyView}. %% {vacmViewTreeFamily, ViewIndex, ViewSubtree, ViewStatus, ViewMask}. {vacmSecurityToGroup, v1, "secName", "group_1"}. {vacmSecurityToGroup, v2c, "secName", "group_1"}. {vacmSecurityToGroup, v1, "all-rights", "group_1"}. {vacmSecurityToGroup, v2c, "all-rights", "group_1"}. {vacmAccess, "group_1", "", any, noAuthNoPriv, exact, "sys", "sys", "sys"}. {vacmViewTreeFamily, 23, [1,3,6,1,2,1,1], included, null}. RESULT: =ERROR REPORT==== 22-Jan-2009::12:09:02 === ** Configuration error: [VIEW-BASED-ACM-MIB]: reconfigure failed: {failed_check, "/opt/app/data/snmp/vacm.conf", 25,26, {invalid_string, 23}} 02.637'751 "."** exception exit: {noproc, {gen_server,call, [snmp_master_agent, {load_mibs, ["/opt/app/data/snmp/KEYTRONIX-CHRONOS-MIB"]}, infinity]}} in function gen_server:call/3 in call from snmp_handler:start/1 does work: {vacmSecurityToGroup, v1, "secName", "group_1"}. {vacmSecurityToGroup, v2c, "secName", "group_1"}. {vacmSecurityToGroup, v1, "all-rights", "group_1"}. {vacmSecurityToGroup, v2c, "all-rights", "group_1"}. {vacmAccess, "group_1", "", any, noAuthNoPriv, exact, "sys", "sys", "sys"}. {vacmViewTreeFamily,"sys", [1,3,6,1,2,1,1], included, null}. all the best, Christoph Grasl Embedded Software Entwickler KEYTRONIX Gesellschaft f?r industrielle Elektronik und Informationstechnologie mbH Ungargasse 64-66/1/109 A-1030 WIEN E-Mail: c.grasl@REDACTED Tel.: +43 (1) 718 06 60 - 323 Mobil: +43 (664) 8556456 WWW: http://www.keytronix.com HG Wien FN 261131t Confidentiality Notice: This message may contain privileged and confidential information. If you think, for any reason, that this message may have been addressed to you in error, you must not disseminate, copy or take any action in reliance on it, and we would ask you to notify us immediately by return email. -------------- next part -------------- An HTML attachment was scrubbed... URL: From erlang@REDACTED Thu Jan 22 12:46:19 2009 From: erlang@REDACTED (Joe Armstrong) Date: Thu, 22 Jan 2009 12:46:19 +0100 Subject: [erlang-questions] question re parallel map code on pg 366 of "Programming Erlang" In-Reply-To: <44ed5e0f0901211951i33280b69h7b95b3303f8d154c@mail.gmail.com> References: <44ed5e0f0901211951i33280b69h7b95b3303f8d154c@mail.gmail.com> Message-ID: <9b08084c0901220346j129e0abblef48381d8f0feadc@mail.gmail.com> It's because I wanted pmap to always terminate - and the order of the results to be the same as the order in a regular map. The point of the example was to show how to parallelise a map - not to take care of all possible error cases. I could have done this without a catch but then pmap would sometimes fail. One meta-principle of the book is "only confuse the reader with one thing at a time - I broke the principle here - possibly an example without the catch might be better - but then it would fail sometimes and people would wonder why. pmap is actually quite useful - I've run it on a multi-core to parse a bundle of files in parallel - works great /Joe On Thu, Jan 22, 2009 at 4:51 AM, David Cabana wrote: > I have a question re Joe's parallel map code on page 366 of Programming Erlang. > Here's the code, modulo a couple of variable name changes. > > pmap(F, Arglist) -> > S = self(), > TaskID = make_ref(), > Workers = lists:map( fun(X) -> > spawn( fun() -> do_F(S, TaskID, F, X ) end) > end, Arglist), > gather(Workers, TaskID). > > do_F(Caller, TaskID, F, X) -> > Caller ! {self(), TaskID, catch(F(X))}. > > gather([W|R], TaskID) -> > receive > {W, TaskID, Val}-> > [Val | gather(R, TaskID)] > end; > > gather([], _) -> > []. > > My question concerns the use of catch inside the do_F function. Here's what Joe > says on page 367: > > "In pmap we use catch(F(H)) when we map the function over the list. In > map we just > use F(H). This is because we want to make sure pmap terminates > correctly in the case > where the computation of F(H) raises an exception." > > I don't get it. > > If the computation of F(H) raises an exception, presumably it would do > so whether F was called by > map or by pmap. Why catch the exception in the one case but not the other? > Why is it important that pmap terminate normally, but not so that map > terminate normally? > > Thanks, > drc > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From kostis@REDACTED Thu Jan 22 12:58:14 2009 From: kostis@REDACTED (Kostis Sagonas) Date: Thu, 22 Jan 2009 13:58:14 +0200 Subject: [erlang-questions] lists:keyfind as an alternative to lists:keysearch In-Reply-To: References: Message-ID: <49785F56.7010901@cs.ntua.gr> James Hague wrote: > I proposed this several years ago, but now that there seems to be > quite a bit of momentum for improving the language and implementation, > I'm revising it. It's a library tweak, so no formal EEP. If anyone > wants a real EEP, let me know. > > lists:keysearch/3 is used for searching a list of tuples. Slightly unrelated to the above discussion but strictly speaking the above statement is not true. lists:keysearch/3 nowhere insists that its third argument is a list of tuples. Consequently, what lists:keysearch/3 does is to search for a tuple with a given key in a list of Erlang terms that may or may not contain tuples of size at least as big as the integer in its second argument. For example, the following happily returns 'false' instead of throwing an exception (as many, perhaps naively, would expect it to). 42> lists:keysearch(foo, 1, [3.14, gazonk]). false Also, the list does not have to be proper. 43> lists:keysearch(foo, 1, [3.14, {foo,bar} | gazonk]). {value,{foo,bar}} Similarly, the function nowhere checks whether the element index is within the tuple bounds: 44> lists:keysearch(foo, 42, [{foo,bar}]). false Bottom line: it's a useful but not particularly kosher function. Kostis From koops.j@REDACTED Thu Jan 22 13:00:45 2009 From: koops.j@REDACTED (Jeroen Koops) Date: Thu, 22 Jan 2009 13:00:45 +0100 Subject: [erlang-questions] Out of memory and garbage collection Message-ID: <331a9abb0901220400x72745ccdp519f1b28653aa272@mail.gmail.com> Hi, I have a simple question: In Java, it is guaranteed that, before an OutOfMemoryException it thrown, all possible garbage collection has been done. So, out of memory really means out of memory. Does a similar guarantee hold for Erlang as well? Or is it possible for the system to terminate with an out of memory error while garbage collection could have freed more memory? Thanks, Jeroen -------------- next part -------------- An HTML attachment was scrubbed... URL: From chsu79@REDACTED Thu Jan 22 13:33:58 2009 From: chsu79@REDACTED (Christian) Date: Thu, 22 Jan 2009 13:33:58 +0100 Subject: [erlang-questions] Out of memory and garbage collection In-Reply-To: <331a9abb0901220400x72745ccdp519f1b28653aa272@mail.gmail.com> References: <331a9abb0901220400x72745ccdp519f1b28653aa272@mail.gmail.com> Message-ID: 2009/1/22 Jeroen Koops : > Hi, > > I have a simple question: In Java, it is guaranteed that, before an > OutOfMemoryException it thrown, all possible garbage collection has been > done. So, out of memory really means out of memory. > > Does a similar guarantee hold for Erlang as well? Or is it possible for the > system to terminate with an out of memory error while garbage collection > could have freed more memory? The later. This article could probably be worth to read: http://www.lshift.net/blog/2008/10/31/erlangs-gc-only-runs-when-youre-running This led to the strategy: "This sounds reasonable - let's try hibernating after every message and see what happens." in this article: http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-2/ Garbage collection is per-process in the default memory model. As a strategy, long running processes should probably do only little work so they can be hibernated, and frequent work should probably be done in short lived processes so all resources are freed instantly when they die. From koops.j@REDACTED Thu Jan 22 13:49:09 2009 From: koops.j@REDACTED (Jeroen Koops) Date: Thu, 22 Jan 2009 13:49:09 +0100 Subject: [erlang-questions] Out of memory and garbage collection In-Reply-To: References: <331a9abb0901220400x72745ccdp519f1b28653aa272@mail.gmail.com> Message-ID: <331a9abb0901220449o200c6485gc2885914ae42269e@mail.gmail.com> Interesting, and consistent with what I'm seeing. I have an application that spawns a few thousand gen_servers. Each server instance initializes itself with a couple of mnesia queries, which may produce a lot of temporary data. The data that is eventually used as the gen_server's state is very limited, however. In my test-setup, after initialization, the gen_server's just sit idle, and indeed seem to hang on to all heap-memory needed during initialization, leading to an out-of-memory error after creating only a few hundred processes. This is solved by forcing a garbage collection right after initialization, and probably also by using the fullsweep_after spawn option (which I still have to look into). Thanks! On Thu, Jan 22, 2009 at 1:33 PM, Christian wrote: > 2009/1/22 Jeroen Koops : > > Hi, > > > > I have a simple question: In Java, it is guaranteed that, before an > > OutOfMemoryException it thrown, all possible garbage collection has been > > done. So, out of memory really means out of memory. > > > > Does a similar guarantee hold for Erlang as well? Or is it possible for > the > > system to terminate with an out of memory error while garbage collection > > could have freed more memory? > > The later. This article could probably be worth to read: > > > http://www.lshift.net/blog/2008/10/31/erlangs-gc-only-runs-when-youre-running > > This led to the strategy: "This sounds reasonable - let's try > hibernating after every message and see what happens." in this > article: > > > http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-2/ > > Garbage collection is per-process in the default memory model. As a > strategy, long running processes should probably do only little work > so they can be hibernated, and frequent work should probably be done > in short lived processes so all resources are freed instantly when > they die. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From chsu79@REDACTED Thu Jan 22 14:02:11 2009 From: chsu79@REDACTED (Christian) Date: Thu, 22 Jan 2009 14:02:11 +0100 Subject: [erlang-questions] Out of memory and garbage collection In-Reply-To: <331a9abb0901220449o200c6485gc2885914ae42269e@mail.gmail.com> References: <331a9abb0901220400x72745ccdp519f1b28653aa272@mail.gmail.com> <331a9abb0901220449o200c6485gc2885914ae42269e@mail.gmail.com> Message-ID: Notice how gen_server allows init to return this form of tuple: {ok,State,hibernate} And handle_call has:{reply,Reply,NewState,hibernate} And the other callbacks have similar forms as well. 2009/1/22 Jeroen Koops : > Interesting, and consistent with what I'm seeing. I have an application that > spawns a few thousand gen_servers. Each server instance initializes itself > with a couple of mnesia queries, which may produce a lot of temporary data. > The data that is eventually used as the gen_server's state is very limited, > however. > > In my test-setup, after initialization, the gen_server's just sit idle, and > indeed seem to hang on to all heap-memory needed during initialization, > leading to an out-of-memory error after creating only a few hundred > processes. This is solved by forcing a garbage collection right after > initialization, and probably also by using the fullsweep_after spawn option > (which I still have to look into). > > Thanks! > > On Thu, Jan 22, 2009 at 1:33 PM, Christian wrote: >> >> 2009/1/22 Jeroen Koops : >> > Hi, >> > >> > I have a simple question: In Java, it is guaranteed that, before an >> > OutOfMemoryException it thrown, all possible garbage collection has been >> > done. So, out of memory really means out of memory. >> > >> > Does a similar guarantee hold for Erlang as well? Or is it possible for >> > the >> > system to terminate with an out of memory error while garbage collection >> > could have freed more memory? >> >> The later. This article could probably be worth to read: >> >> >> http://www.lshift.net/blog/2008/10/31/erlangs-gc-only-runs-when-youre-running >> >> This led to the strategy: "This sounds reasonable - let's try >> hibernating after every message and see what happens." in this >> article: >> >> >> http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-2/ >> >> Garbage collection is per-process in the default memory model. As a >> strategy, long running processes should probably do only little work >> so they can be hibernated, and frequent work should probably be done >> in short lived processes so all resources are freed instantly when >> they die. > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From cbenac@REDACTED Thu Jan 22 16:14:33 2009 From: cbenac@REDACTED (Clara Benac Earle) Date: Thu, 22 Jan 2009 16:14:33 +0100 Subject: [erlang-questions] CFP Erlang Workshop 2009 Message-ID: <49788D59.9090307@fi.upm.es> Eighth ACM SIGPLAN Erlang Workshop CALL FOR PAPERS Edinburgh, Scotland, September 3, 2009 http://www.erlang.org/workshop/2009/ Satellite event of the 14th ACM SIGPLAN International Conference on Functional Programming, August 31 - September 2 , 2009 Erlang is a concurrent, distributed functional programming language aimed at systems with requirements on massive concurrency, soft real time response, fault tolerance, and high availability. It has been available as open source for several years creating a community that actively contributes to its already existing rich set of libraries and applications. Originally created for telecom applications, its usage has spread to other domains including e-commerce, banking, and computer telephony. Erlang programs are today among the largest applications written in any functional programming language. These applications offer new opportunities to evaluate functional programming and functional programming methods on a very large scale and suggest new problems for the research community to solve. This workshop will bring together the open source, academic, and industrial programming communities of Erlang. It will enable participants to familiarize themselves with recent developments on new techniques and tools tailored to Erlang, novel applications, draw lessons from users' experiences and identify research problems and common areas relevant to the practice of Erlang and functional programming. Workshop Chair ? Clara Benac Earle, Technical University of Madrid, Spain. Program Chair ? Simon Thompson, University of Kent, Canterbury, UK. Program Committee ? Laura M. Castro, University of A Coru?a, Spain. ? Francesco Cesarini, Erlang Training and Consulting, London, UK. ? Torben Hoffman, Motorola, Denmark. ? Zolt?n Horv?th, E?tv?s Lor?nd University, Budapest, Hungary. ? Jan Lehnardt, Freisatz, M?nster, Germany. ? Daniel Luna, Kreditor, Stockholm, Sweden. ? Kenneth Lundin, Ericsson, Stockholm, Sweden. ? Rex Page, University of Oklahoma, USA. ? Corrado Santoro, University of Catania, Italy. ? Tee Teoh, Canadian Bank Note, Ottawa, Canada. ? Phil Trinder, Heriot-Watt University, Edinburgh, UK. Important Dates ? Submission deadline: May 8, 2009. ? Author notification: May 30, 2009. ? Final submission: June 17, 2009. Instructions to authors ? Submissions are via EasyChair and the page is now open for submissions. ? The workshop will have printed proceedings which will be distributed to the participants at the time of the workshop. Subsequently, the papers will be included in the ACM Digital Library. ? Please see the Instructions for authors on the call for papers of the ACM conference. ? Please see also the authors' instruction page from last year's workshop. Venue ? The workshop will take place at the Royal College of Physicians, a historic building in the centre of Edinburgh. Registration Details ? For registration, please see the ICFP web site. Related Links ? EasyChair https://www.easychair.org/login.cgi?conf=ew09 ? ICFP 2009 web site http://www.cs.nott.ac.uk/~gmh/icfp09.html. ? Past ACM SIGPLAN Erlang workshops http://www.erlang.se/workshop. ? Open Source Erlang http://www.erlang.org/. From mrad-direct-erlang@REDACTED Thu Jan 22 20:24:32 2009 From: mrad-direct-erlang@REDACTED (Michael Radford) Date: Thu, 22 Jan 2009 11:24:32 -0800 Subject: [erlang-questions] Multiple dialyzer PLTs? Message-ID: <20090122192431.GA31994@herbie> I'm wondering how difficult (or even possible) it would be for dialyzer to support either reading multiple PLT files at startup, or a way to merge multiple PLT files that were produced separately. We make debian packages containing compiled .beam files, and it would be great if these could ship with corresponding PLT files for people compiling other packages that depend on them. Currently it takes about half an hour just to build a PLT for kernel, stdlib, and mnesia, so we're shipping a prebuilt PLT for those in a package. But that means lots of unknown functions and missed checks when compiling an application that has lots of other dependencies. I'd be grateful for any other suggestions on how to achieve this too. The next best thing seems to be using --add_to_plt and --output_plt to build incrementally, but we'd prefer a more packaging-friendly approach that doesn't make everyone wait for the same analysis over and over. Thanks, Mike From ulf@REDACTED Thu Jan 22 21:06:55 2009 From: ulf@REDACTED (Ulf Wiger) Date: Thu, 22 Jan 2009 21:06:55 +0100 Subject: [erlang-questions] Registering a process with multiple names In-Reply-To: References: Message-ID: <8209f740901221206k6b063276p3c519e31fe524d7e@mail.gmail.com> Take a look at gproc (google for gproc and Wiger). It does what you want. A simpler version can also be found in jungerl (called proc or proc_reg - I can't recall). BR, Ulf W (via cell phone) 2009/1/22, Torben Hoffmann : > Hi, > > I have implemented a protocol stack and the current implementation has a > coordinator process that keeps track of the processes that are spawned to > handle the individual calls (very telcom protocol). > > The reason for this is that I have two types of call identifies: one at the > top of the stack that represents my connection to our legacy system and one > at the bottom of the stack that represents the protocol's call. > > When I get a message from our legacy system my coordinator process looks up > in its list of spawned processes and finds the process for that message > based on the legacy call identifier. > > Likewise when I get a message from the protocol: the call identifier is used > by the coordinator to find the process to send the message to. > > In my ideal world I would like to register the call process with two names: > one for the legacy call identificator and on for the protocol's call > identificator. > Then my coordinator could look up if a process has been spawned for a call > identificator (legacy or protocol) and then forward the message. > If there hasn't been spawned a process for the call the coordinator spawns a > new one and registers it. > > The problem is that erlang:register/2 barfs if you try to register a process > more than once. > > Surely I am not the first to run into this type of problem so I am hoping > that the someone has some ideas for me! > > Thanks in advance, > Torben > From kostis@REDACTED Thu Jan 22 23:10:47 2009 From: kostis@REDACTED (Kostis Sagonas) Date: Fri, 23 Jan 2009 00:10:47 +0200 Subject: [erlang-questions] Multiple dialyzer PLTs? In-Reply-To: <20090122192431.GA31994@herbie> References: <20090122192431.GA31994@herbie> Message-ID: <4978EEE7.2030501@cs.ntua.gr> Michael Radford wrote: > I'm wondering how difficult (or even possible) it would be for dialyzer > to support either reading multiple PLT files at startup, or a way to > merge multiple PLT files that were produced separately. Reading multiple PLT files at startup and merging the information in them is possible, but the end result is not as good as you would expect it to be whenever there are dependencies between functions in the different PLTs. To do a good job one needs to essentially re-analyze the code of these functions/modules. > We make debian packages containing compiled .beam files, and it would be > great if these could ship with corresponding PLT files for people > compiling other packages that depend on them. > > I'd be grateful for any other suggestions on how to achieve this too. > The next best thing seems to be using --add_to_plt and --output_plt to > build incrementally, but we'd prefer a more packaging-friendly approach > that doesn't make everyone wait for the same analysis over and over. Currently, the --add_to_plt option is the only available alternative to what you want to do. In case there are no mutual dependencies between the stuff that is already in the PLT and the new application, the analysis takes as much time as it takes to analyze the new application. Kostis From mrad-direct-erlang@REDACTED Thu Jan 22 23:34:25 2009 From: mrad-direct-erlang@REDACTED (Michael Radford) Date: Thu, 22 Jan 2009 14:34:25 -0800 Subject: [erlang-questions] Multiple dialyzer PLTs? In-Reply-To: <4978EEE7.2030501@cs.ntua.gr> References: <20090122192431.GA31994@herbie> <4978EEE7.2030501@cs.ntua.gr> Message-ID: <20090122223425.GB31994@herbie> Kostis Sagonas writes: > Michael Radford wrote: > >I'm wondering how difficult (or even possible) it would be for dialyzer > >to support either reading multiple PLT files at startup, or a way to > >merge multiple PLT files that were produced separately. > > Reading multiple PLT files at startup and merging the information in > them is possible, but the end result is not as good as you would expect > it to be whenever there are dependencies between functions in the > different PLTs. To do a good job one needs to essentially re-analyze > the code of these functions/modules. That's pretty much what I figured; but even an incomplete analysis that included other libraries would be an improvement over our current situation where we ignore them. Of course I understand that from a correctness standpoint, it would be even better to analyze the entire codebase together. But with many libraries that are constantly being upgraded, I don't think it will fly to require all the developers to wait for dialyzer to run after every package installation. Could you offer any pointers on where to start if I were to try to implement reading multiple PLT files? Thanks for your help (and for a great tool), Mike From jeffm@REDACTED Thu Jan 22 23:54:24 2009 From: jeffm@REDACTED (jm) Date: Fri, 23 Jan 2009 09:54:24 +1100 Subject: [erlang-questions] I'm not worthy (anthropomorphism ahead) In-Reply-To: <20090121232450.GL2497@h216-235-12-171.host.egate.net> References: <20090121232450.GL2497@h216-235-12-171.host.egate.net> Message-ID: <4978F920.80304@ghostgun.com> As an aside on the page you link to ( http://www.erlang.se/contact/alvsjo.shtml ) there is a link to http://www.stockholm.se/english/index.htm which gives a 404. It appears that the new page is http://www.stockholm.se/-/English/ Who ever maintains this page may wish to update to the new link. Having spotted one broken link I thought I'd better continue and check the rest. There appears to be two more: This text "Gula Sidorna" which links to http://www.gulasidorna.se/?lang=en/ also doesn't seem to go where it's intended. And, http://www.flygbussarna.com/ seems to be a parked or squatted domain. Jeff. Vance Shipley wrote: > http://www.erlang.se/contact/alvsjo.shtml > > On Wed, Jan 21, 2009 at 05:46:13PM -0500, Steven Edwards wrote: > } which Ericsson office is the Mecca of Erlang? I need to know which > } direction to pray. :) > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From fritchie@REDACTED Thu Jan 22 23:50:52 2009 From: fritchie@REDACTED (Scott Lystig Fritchie) Date: Thu, 22 Jan 2009 16:50:52 -0600 Subject: [erlang-questions] Comet server broadcasting messages to 40k clients In-Reply-To: Message of "Wed, 21 Jan 2009 11:38:18 -0200." <6bb4c8cb0901210538m5a2d42ei26ae0494176572d2@mail.gmail.com> Message-ID: <16501.1232664652@snookles.snookles.com> Adriano Bonat wrote: ab> Any other ideas are welcome, and thanks for you reply :) Have you tried profiling? Without actually doing so, I can only guess that with 40K sockets, 40K calls to io_lib:format() are going to use more than 8 nanoseconds of CPU time ... and the real culrpit may be quite obvious. -Scott From yoursurrogategod@REDACTED Fri Jan 23 01:50:24 2009 From: yoursurrogategod@REDACTED (Yves S. Garret) Date: Thu, 22 Jan 2009 16:50:24 -0800 (PST) Subject: [erlang-questions] Odd error messages when compiling R12-B5 Message-ID: Hi. I'm trying to get R12-B5 to compile on my machine (Linux foo 2.6.24-22-generic #1 SMP Mon Nov 24 18:32:42 UTC 2008 i686 GNU/Linux). These are the input values that I put into the configure script: ./configure --with-ssl=/usr/lib/ssl All of the crypto goodies are hidden there. Here's what happens when a certain line is reached during the compile process: make[4]: Entering directory `/R12B5/otp_src_R12B-5/lib/crypto/c_src' /usr/bin/install -c -d ../priv/obj/i686-pc-linux-gnu gcc -c -o ../priv/obj/i686-pc-linux-gnu/crypto_drv.o -g -O2 -I/R12B5/ otp_src_R12B-5/erts/i686-pc-linux-gnu -D_LARGEFILE_SOURCE - D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -DUSE_THREADS -D_THREAD_SAFE - D_REENTRANT -D_POSIX_THREAD_SAFE_FUNCTIONS -fPIC -I/usr/lib/ssl/ include -I/usr/include -I/R12B5/otp_src_R12B-5/erts/emulator/beam -I/ R12B5/otp_src_R12B-5/erts/emulator/sys/unix crypto_drv.c crypto_drv.c:34:33: error: openssl/opensslconf.h: No such file or directory crypto_drv.c:37:6: warning: #warning No thread support by openssl. Driver will use coarse grain locking. crypto_drv.c:41:28: error: openssl/crypto.h: No such file or directory crypto_drv.c:42:25: error: openssl/des.h: No such file or directory crypto_drv.c:44:25: error: openssl/dsa.h: No such file or directory crypto_drv.c:45:25: error: openssl/rsa.h: No such file or directory crypto_drv.c:46:25: error: openssl/aes.h: No such file or directory crypto_drv.c:47:25: error: openssl/md5.h: No such file or directory crypto_drv.c:48:25: error: openssl/md4.h: No such file or directory crypto_drv.c:49:25: error: openssl/sha.h: No such file or directory crypto_drv.c:50:24: error: openssl/bn.h: No such file or directory crypto_drv.c:51:29: error: openssl/objects.h: No such file or directory crypto_drv.c:52:25: error: openssl/rc4.h: No such file or directory crypto_drv.c:53:25: error: openssl/rc2.h: No such file or directory crypto_drv.c: In function ?control?: crypto_drv.c:330: error: ?const_DES_cblock? undeclared (first use in this function) crypto_drv.c:330: error: (Each undeclared identifier is reported only once crypto_drv.c:330: error: for each function it appears in.) crypto_drv.c:330: error: ?des_key? undeclared (first use in this function) crypto_drv.c:330: error: ?des_key2? undeclared (first use in this function) crypto_drv.c:330: error: ?des_key3? undeclared (first use in this function) crypto_drv.c:332: error: ?BIGNUM? undeclared (first use in this function) crypto_drv.c:332: error: ?bn_from? undeclared (first use in this function) crypto_drv.c:332: error: ?bn_to? undeclared (first use in this function) crypto_drv.c:332: error: ?bn_rand? undeclared (first use in this function) crypto_drv.c:332: error: ?bn_result? undeclared (first use in this function) crypto_drv.c:333: error: ?bn_base? undeclared (first use in this function) crypto_drv.c:333: error: ?bn_exponent? undeclared (first use in this function) crypto_drv.c:333: error: ?bn_modulo? undeclared (first use in this function) crypto_drv.c:334: error: ?dsa_p? undeclared (first use in this function) crypto_drv.c:334: error: ?dsa_q? undeclared (first use in this function) crypto_drv.c:334: error: ?dsa_r? undeclared (first use in this function) crypto_drv.c:334: error: ?dsa_g? undeclared (first use in this function) crypto_drv.c:334: error: ?dsa_y? undeclared (first use in this function) crypto_drv.c:335: error: ?rsa_n? undeclared (first use in this function) crypto_drv.c:335: error: ?rsa_e? undeclared (first use in this function) crypto_drv.c:335: error: ?rsa_d? undeclared (first use in this function) crypto_drv.c:336: error: ?dh_p? undeclared (first use in this function) crypto_drv.c:336: error: ?dh_g? undeclared (first use in this function) crypto_drv.c:336: error: ?privkey? undeclared (first use in this function) crypto_drv.c:336: error: ?pubkey? undeclared (first use in this function) crypto_drv.c:337: error: ?DES_cblock? undeclared (first use in this function) crypto_drv.c:337: error: ?des_ivec? undeclared (first use in this function) crypto_drv.c:339: error: ?DES_key_schedule? undeclared (first use in this function) crypto_drv.c:339: error: expected ?;? before ?schedule? crypto_drv.c:340: error: ?DH? undeclared (first use in this function) crypto_drv.c:340: error: ?dh_params? undeclared (first use in this function) crypto_drv.c:342: error: ?SHA_DIGEST_LENGTH? undeclared (first use in this function) crypto_drv.c:349: error: ?MD5_CTX? undeclared (first use in this function) crypto_drv.c:349: error: expected ?;? before ?md5_ctx? crypto_drv.c:350: error: ?MD4_CTX? undeclared (first use in this function) crypto_drv.c:350: error: expected ?;? before ?md4_ctx? crypto_drv.c:351: error: ?SHA_CTX? undeclared (first use in this function) crypto_drv.c:351: error: expected ?;? before ?sha_ctx? crypto_drv.c:353: error: ?BN_CTX? undeclared (first use in this function) crypto_drv.c:353: error: ?bn_ctx? undeclared (first use in this function) crypto_drv.c:354: error: ?DSA? undeclared (first use in this function) crypto_drv.c:354: error: ?dsa? undeclared (first use in this function) crypto_drv.c:355: error: ?RSA? undeclared (first use in this function) crypto_drv.c:355: error: ?rsa? undeclared (first use in this function) crypto_drv.c:356: error: ?AES_KEY? undeclared (first use in this function) crypto_drv.c:356: error: expected ?;? before ?aes_key? crypto_drv.c:357: error: ?RC4_KEY? undeclared (first use in this function) crypto_drv.c:357: error: expected ?;? before ?rc4_key? crypto_drv.c:358: error: ?RC2_KEY? undeclared (first use in this function) crypto_drv.c:358: error: expected ?;? before ?rc2_key? crypto_drv.c:380: error: expected expression before ?)? token crypto_drv.c:390: error: expected expression before ?)? token crypto_drv.c:398: error: ?md5_ctx? undeclared (first use in this function) crypto_drv.c:415: error: expected expression before ?)? token crypto_drv.c:425: error: expected expression before ?)? token crypto_drv.c:433: error: ?sha_ctx? undeclared (first use in this function) crypto_drv.c:478: error: expected expression before ?)? token crypto_drv.c:479: error: expected expression before ?)? token crypto_drv.c:483: error: ?schedule? undeclared (first use in this function) crypto_drv.c:516: error: ?rc2_key? undeclared (first use in this function) crypto_drv.c:527: error: expected expression before ?)? token crypto_drv.c:528: error: expected expression before ?)? token crypto_drv.c:529: error: expected expression before ?)? token crypto_drv.c:530: error: expected expression before ?)? token crypto_drv.c:535: error: ?schedule2? undeclared (first use in this function) crypto_drv.c:536: error: ?schedule3? undeclared (first use in this function) crypto_drv.c:551: error: ?aes_key? undeclared (first use in this function) crypto_drv.c:565: error: ?rc4_key? undeclared (first use in this function) crypto_drv.c:808: error: ?NID_sha1? undeclared (first use in this function) crypto_drv.c:863: error: ?NID_md5? undeclared (first use in this function) crypto_drv.c:863: error: ?MD5_DIGEST_LENGTH? undeclared (first use in this function) crypto_drv.c:988: error: ?RSA_NO_PADDING? undeclared (first use in this function) crypto_drv.c:991: error: ?RSA_PKCS1_PADDING? undeclared (first use in this function) crypto_drv.c:994: error: ?RSA_PKCS1_OAEP_PADDING? undeclared (first use in this function) crypto_drv.c:997: error: ?RSA_SSLV23_PADDING? undeclared (first use in this function) crypto_drv.c:1139: error: ?AES_ENCRYPT? undeclared (first use in this function) crypto_drv.c:1142: error: ?AES_DECRYPT? undeclared (first use in this function) crypto_drv.c:1370: error: expected expression before ?)? token crypto_drv.c:1379: error: expected expression before ?)? token crypto_drv.c:1386: error: ?md4_ctx? undeclared (first use in this function) crypto_drv.c:1460: error: ?SSLEAY_VERSION? undeclared (first use in this function) crypto_drv.c:1460: warning: initialization makes pointer from integer without a cast crypto_drv.c: In function ?hmac_md5?: crypto_drv.c:1540: error: ?MD5_CTX? undeclared (first use in this function) crypto_drv.c:1540: error: expected ?;? before ?ctx? crypto_drv.c:1548: error: expected ?;? before ?kctx? crypto_drv.c:1550: error: ?kctx? undeclared (first use in this function) crypto_drv.c:1568: error: ?ctx? undeclared (first use in this function) crypto_drv.c: In function ?hmac_sha1?: crypto_drv.c:1582: error: ?SHA_CTX? undeclared (first use in this function) crypto_drv.c:1582: error: expected ?;? before ?ctx? crypto_drv.c:1590: error: expected ?;? before ?kctx? crypto_drv.c:1592: error: ?kctx? undeclared (first use in this function) crypto_drv.c:1610: error: ?ctx? undeclared (first use in this function) make[4]: *** [../priv/obj/i686-pc-linux-gnu/crypto_drv.o] Error 1 make[4]: Leaving directory `/R12B5/otp_src_R12B-5/lib/crypto/c_src' make[3]: *** [opt] Error 2 make[3]: Leaving directory `/R12B5/otp_src_R12B-5/lib/crypto/c_src' make[2]: *** [opt] Error 2 make[2]: Leaving directory `/R12B5/otp_src_R12B-5/lib/crypto' make[1]: *** [opt] Error 2 make[1]: Leaving directory `/R12B5/otp_src_R12B-5/lib' make: *** [libs] Error 2 I'm not sure what else I could have not installed for openssl. I checked in synaptic to make sure that I had the package openssl there and I do. What am I missing? Also, as the compile process was going on, I was getting these errors: gcc -g -O2 -fPIC -Wall -Wstrict-prototypes -Wmissing-prototypes - Wmissing-declarations -Wnested-externs -Winline -fno-strict-aliasing - I. -I../include -Iconnect -Iencode -Idecode -Imisc -Iepmd -Iregistry - Ii686-pc-linux-gnu -D_REENTRANT -D_THREAD_SAFE -DPOSIX_THREADS -c legacy/erl_format.c -o /R12B5/otp_src_R12B-5/lib/erl_interface/obj.mt/ i686-pc-linux-gnu/erl_format.o legacy/erl_format.c: In function ?find_lvar?: legacy/erl_format.c:81: warning: pointer targets in passing argument 1 of ?strlen? differ in signedness legacy/erl_format.c:81: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:81: warning: pointer targets in passing argument 1 of ?strlen? differ in signedness legacy/erl_format.c:81: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:81: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:81: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c: In function ?ematch?: legacy/erl_format.c:574: warning: pointer targets in passing argument 1 of ?strlen? differ in signedness legacy/erl_format.c:574: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:574: warning: pointer targets in passing argument 1 of ?strlen? differ in signedness legacy/erl_format.c:574: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:574: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:574: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:576: warning: pointer targets in passing argument 1 of ?find_lvar? differ in signedness legacy/erl_format.c:602: warning: pointer targets in passing argument 1 of ?strlen? differ in signedness legacy/erl_format.c:602: warning: pointer targets in passing argument 1 of ?strlen? differ in signedness legacy/erl_format.c:602: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:602: warning: pointer targets in passing argument 2 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:602: warning: pointer targets in passing argument 1 of ?strlen? differ in signedness legacy/erl_format.c:602: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:602: warning: pointer targets in passing argument 2 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:602: warning: pointer targets in passing argument 1 of ?strlen? differ in signedness legacy/erl_format.c:602: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:602: warning: pointer targets in passing argument 2 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:602: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:602: warning: pointer targets in passing argument 2 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:612: warning: pointer targets in passing argument 1 of ?strlen? differ in signedness legacy/erl_format.c:612: warning: pointer targets in passing argument 1 of ?strlen? differ in signedness legacy/erl_format.c:612: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:612: warning: pointer targets in passing argument 2 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:612: warning: pointer targets in passing argument 1 of ?strlen? differ in signedness legacy/erl_format.c:612: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:612: warning: pointer targets in passing argument 2 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:612: warning: pointer targets in passing argument 1 of ?strlen? differ in signedness legacy/erl_format.c:612: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:612: warning: pointer targets in passing argument 2 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:612: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:612: warning: pointer targets in passing argument 2 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:623: warning: pointer targets in passing argument 1 of ?strlen? differ in signedness legacy/erl_format.c:623: warning: pointer targets in passing argument 1 of ?strlen? differ in signedness legacy/erl_format.c:623: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:623: warning: pointer targets in passing argument 2 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:623: warning: pointer targets in passing argument 1 of ?strlen? differ in signedness legacy/erl_format.c:623: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:623: warning: pointer targets in passing argument 2 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:623: warning: pointer targets in passing argument 1 of ?strlen? differ in signedness legacy/erl_format.c:623: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:623: warning: pointer targets in passing argument 2 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:623: warning: pointer targets in passing argument 1 of ?__builtin_strcmp? differ in signedness legacy/erl_format.c:623: warning: pointer targets in passing argument 2 of ?__builtin_strcmp? differ in signedness Why so many? Seems strange. Your input is appreciated. From ok@REDACTED Fri Jan 23 03:54:35 2009 From: ok@REDACTED (Richard O'Keefe) Date: Fri, 23 Jan 2009 15:54:35 +1300 Subject: [erlang-questions] The If expression In-Reply-To: References: Message-ID: <3A9F40FC-0F61-4327-905D-B9331AF83D8C@cs.otago.ac.nz> On 2 Jan 2009, at 9:14 am, Fredrik Svahn wrote: > In addition to the above (which is kept for backwards compatibility) I > suggest adding an alternative form with the following syntax: > > if Expression -> Body else -> ElseBody end > > which should act as syntactical sugar for the more clumsy and > unintuitive: > > case Expression of > true -> Body; > _Else -> ElseBody > end > I'm sorry for the late reply, but December/January is the long holiday in New Zealand, and I only got back yesterday. This is a very bad idea because - It would give us two very *different* conditional structures with the *same* keyword, where it is hard to tell which one was intended until several lines later. - 'if' isn't actually all that rare. In some code I wrote last year, I find one 'if' for every four 'case's. The OTP sources have 1 if/10 case, which is less common, but not _that_ rare. If the old sense of 'if' were rare, we could probably live with the confusion. - The new syntax is not consistent with Erlang "style", which expects multiple arms as a matter of routine (like the Fortran, Ada, Eiffel, Algol 68 "block if" constructs, but without an "else"). - As a result the new syntax is rather inconvenient. The majority of my existing uses of 'if' have more than one arm, so would need nested new-'if's. It's hard to see that as an improvement. > My hope is that with this improvement 'if'-statements would be the > recommended choice for expressions evaluating to a bool() It would not be an improvement. Such expressions should be avoided, not canonised. > The proposal would address two of the problems with the current > syntax: > > 1. Today only guards are allowed, not full expressions. For instance, > today it is NOT ok to write: > > if erlang:system_info(smp_support) -> init_smp(); > true -> init() > end. > > which many believe is a rather serious limitation of the usefulness. And many don't. In fact this is an excellent example of what's wrong with Boolean functions. The interface *should* have been something like case erlang:system_info(smp) of not_supported -> ... ; supported -> ... end and other values are imaginable: smp support might have been compiled in, but not actually useful because only one core is available. So maybe the interface should have been case erlang:system_info(smp) of not_supported -> ... ; interfaces_supported -> ... ; functional_and_useful -> ... end Indeed, if I wanted to know whether to set up for SMP, I would probably use system_info(multi_scheduling) instead: case erlang:system_info(multi_scheduling) of disabled -> no SMP or only one scheduler ; blocked -> there are multiple schedulers and all but one of them are blocked ; enabled -> multiple schedulers are really available end About 40 years ago when enumeration types were introduced it was pointed out that people over-used Boolean. I've been guilty of that myself. In Erlang, our aim is to write reliable and maintainable software. We shouldn't regard it as a PROBLEM that Boolean expressions are hard to use, we should regard it as a heaven-sent OPPORTUNITY to critically, and I really do mean SERIOUSLY critically review all uses of Boolean to see whether they are really appropriate. My own experience is that in the majority of cases they are not. (My use of 'if' is almost entirely arithmetic comparisons.) > 2. At least of of the guards have to evaluate to true, otherwise a > runtime error will occur. This leads to unintuitive constructs like: > > if Bool -> do_true(); > true -> do_false() end. > > Which could be replaced by a more intuitive: > > if Bool -> do_true() else -> do_false() end. It may be more FAMILIAR, but that doesn't mean 'else' is a good thing. I know that writing '; true ->' is a very easy way to get 'else' in Erlang, but we have a couple of decades of psychology- of-programming results to show that it's a bad idea. I have started to replace by if X > Y -> a() if X > Y -> a() ; true -> b() ; X =< Y -> b() end end if X > Y -> a() if X > Y -> a() ; X < Y -> b() ; X < Y -> b() ; true -> c() ; X ==Y -> c() end end which I find mildly annoying when _writing_ the code but enormously helpful when _reading_ it. This is one reason why I regard a proposal to add 'else' to Erlang as a bad idea. > An open question is if it should also be allowed to have expressions > without an 'else' clause, as proposed by Damien Katz, i.e.: > > if Expression -> Body end Obviously not, because if Guard -> Body end is already legal Erlang syntax. > Which might be useful in some cases, e.g. > > if Logging -> log:write("Aiee") end, Dijkstra's "A Discipline of Programming" gives arguments against using one-armed ifs in imperative code. In a mostly functional language it's even worse. Erlang gets this *right*: if you don't say what to do in some case, then a situation has arisen that your program does not handle, and the right answer is an exception. > In this particular case returning false might seem like a good idea, > but in other cases e.g. an empty list might be just as natural. I am > just not sure how to apply the rule of least surprise to this... The rule of least surprise has a corollary: if there ISN'T a least surprising result, there is no result (that is, there is an exception). From saleyn@REDACTED Fri Jan 23 04:45:27 2009 From: saleyn@REDACTED (Serge Aleynikov) Date: Thu, 22 Jan 2009 22:45:27 -0500 Subject: [erlang-questions] mnesia:clear_table/1 and local_content: bug or feature? Message-ID: <49793D57.6060504@gmail.com> Hi, Not quite sure if this is a bug or a feature. Documentation is not defining this behavior, but it seems like a bug. If you create replicas of a mnesia table on different nodes with {local_content, true}, calling mnesia:clear_table/1 on some node clears the content of the table on all nodes. This seems a bit surprising as local_content means that the content of each table is managed by each node independently. Serge From tobias.lindahl@REDACTED Fri Jan 23 09:04:30 2009 From: tobias.lindahl@REDACTED (Tobias Lindahl) Date: Fri, 23 Jan 2009 09:04:30 +0100 Subject: [erlang-questions] Multiple dialyzer PLTs? In-Reply-To: <20090122223425.GB31994@herbie> References: <20090122192431.GA31994@herbie> <4978EEE7.2030501@cs.ntua.gr> <20090122223425.GB31994@herbie> Message-ID: <49797A0E.8030501@kreditor.se> Michael Radford wrote: > Kostis Sagonas writes: >> Michael Radford wrote: >>> I'm wondering how difficult (or even possible) it would be for dialyzer >>> to support either reading multiple PLT files at startup, or a way to >>> merge multiple PLT files that were produced separately. >> Reading multiple PLT files at startup and merging the information in >> them is possible, but the end result is not as good as you would expect >> it to be whenever there are dependencies between functions in the >> different PLTs. To do a good job one needs to essentially re-analyze >> the code of these functions/modules. > > That's pretty much what I figured; but even an incomplete analysis that > included other libraries would be an improvement over our current > situation where we ignore them. > > Of course I understand that from a correctness standpoint, it would be > even better to analyze the entire codebase together. But with many > libraries that are constantly being upgraded, I don't think it will fly > to require all the developers to wait for dialyzer to run after every > package installation. > > Could you offer any pointers on where to start if I were to try to > implement reading multiple PLT files? Most of the ptl handling is done in dialyzer_plt.erl and it interacts with dialyzer_cl.erl in order to find out what needs to be reanalyzed. You might also want to have a look at dialyzer_succ_typings.erl and its interaction with dialyzer_contract.erl, but start out with the first two modules. It shouldn't be too hard to make this happen, at least as long as the plts are non-overlapping, or when the overlapping information is identical (e.g., the plts was built from the same otp-plt). The main reason we haven't done this is that it is the points Kostis made about the information. Happy hacking! Tobias > > Thanks for your help (and for a great tool), > > Mike > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From dgud@REDACTED Fri Jan 23 09:12:26 2009 From: dgud@REDACTED (Dan Gudmundsson) Date: Fri, 23 Jan 2009 09:12:26 +0100 Subject: [erlang-questions] mnesia:clear_table/1 and local_content: bug or feature? In-Reply-To: <49793D57.6060504@gmail.com> References: <49793D57.6060504@gmail.com> Message-ID: <49797BEA.5040704@erix.ericsson.se> That sounds like a bug to me. Will fix in the next release. /Dan Serge Aleynikov wrote: > Hi, > > Not quite sure if this is a bug or a feature. Documentation is not > defining this behavior, but it seems like a bug. > > If you create replicas of a mnesia table on different nodes with > {local_content, true}, calling mnesia:clear_table/1 on some node clears > the content of the table on all nodes. This seems a bit surprising as > local_content means that the content of each table is managed by each > node independently. > > Serge > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From adam@REDACTED Fri Jan 23 09:23:50 2009 From: adam@REDACTED (Adam Lindberg) Date: Fri, 23 Jan 2009 08:23:50 +0000 (GMT) Subject: [erlang-questions] -spec notation for unexported functions? In-Reply-To: <7128951.49961232698950412.JavaMail.root@zimbra> Message-ID: <2770765.49981232699030612.JavaMail.root@zimbra> Hi, When using Dialyzer and augmenting the code with -spec specifications, what is the preferred level of brevity? For ALL functions in a module or only for the exported interface functions? Which way gives a more correct analysis? It is also a readability issue, the spec's are nice, but too many of them are a bit hard to read. Cheers, Adam From harveyd@REDACTED Fri Jan 23 09:34:52 2009 From: harveyd@REDACTED (Dale Harvey) Date: Fri, 23 Jan 2009 08:34:52 +0000 Subject: [erlang-questions] -spec notation for unexported functions? In-Reply-To: <2770765.49981232699030612.JavaMail.root@zimbra> References: <7128951.49961232698950412.JavaMail.root@zimbra> <2770765.49981232699030612.JavaMail.root@zimbra> Message-ID: Somewhat of a feature request but I had the same problem with type specs and readability I tried getting the erlang mode for emacs to highlight them as comments, or close to, but didnt get it working 2009/1/23 Adam Lindberg > Hi, > > When using Dialyzer and augmenting the code with -spec specifications, what > is the preferred level of brevity? For ALL functions in a module or only for > the exported interface functions? Which way gives a more correct analysis? > > It is also a readability issue, the spec's are nice, but too many of them > are a bit hard to read. > > Cheers, > Adam > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thijsterlouw@REDACTED Fri Jan 23 09:46:01 2009 From: thijsterlouw@REDACTED (Thijs Terlouw) Date: Fri, 23 Jan 2009 16:46:01 +0800 Subject: [erlang-questions] gen_tcp:transfer_ownership of socket to another node? Message-ID: <4183f4b90901230046p409e7d2fo66fc8f447ad3c73e@mail.gmail.com> What happens when I accept a new TCP connection (in processA) and then transfer the ownership of that socket from processA to processB which is running on another Erlang node(B)? I assume that Beam then keeps 'something' running on the original node(A) to keep the connection open, even if processA is killed? That way i would be able to send data to the socket from processB after processA is killed? The data would then be copied from one VM to another VM (because the socket cannot move of course)? Is this correct? Thijs Terlouw - China -------------- next part -------------- An HTML attachment was scrubbed... URL: From bengt.kleberg@REDACTED Fri Jan 23 09:46:33 2009 From: bengt.kleberg@REDACTED (Bengt Kleberg) Date: Fri, 23 Jan 2009 09:46:33 +0100 Subject: [erlang-questions] beginner: How do I get a unix shell trap handler in escript? Message-ID: <1232700393.6251.11.camel@seasc1137.dyn.rnd.as.sw.ericsson.se> Greetings, A unix shell(*) can trap signals. How do I do the same thing in escript? bengt (*) Example. Save the code below as script_name and start it with: script_name 1 2 3 4 and then press ^C a few times. #! /bin/sh trap interrupt_handler INT interrupt_handler () { echo interrupt_handler } for i in $* ; do echo $i sleep 10 done From kostis@REDACTED Fri Jan 23 09:54:35 2009 From: kostis@REDACTED (Kostis Sagonas) Date: Fri, 23 Jan 2009 10:54:35 +0200 Subject: [erlang-questions] -spec notation for unexported functions? In-Reply-To: <2770765.49981232699030612.JavaMail.root@zimbra> References: <2770765.49981232699030612.JavaMail.root@zimbra> Message-ID: <497985CB.5060306@cs.ntua.gr> Adam Lindberg wrote: > Hi, > > When using Dialyzer and augmenting the code with -spec specifications, what is the preferred level of brevity? For ALL functions in a module or only for the exported interface functions? Which way gives a more correct analysis? This is an excellent question. My approach is the following: - Add specs for *all* exported functions. To make sure I have not forgotten any I always compile with the new compiler option +warn_missing_spec which warns for missing specs for exported functions. This way, the module interfaces are checked for violations. - The above typically is enough, but to see whether some module-local function might need a -spec, I run typer in the file (this is very simple: typer file.erl) and inspect the specs that typer infers for all module local functions. If they look OK, then I stop there. If some of them look too weak, e.g. an argument is inferred to be the any() term when I intend to use that argument with an integer(), then I add a few -specs for these functions too. Typically, this action strengthens some more inferred -specs for module-local functions. Kostis PS. The emacs support for -specs and -types is indeed missing, but we lack the expertise to fix it. Help on this one is appreciated. From thijsterlouw@REDACTED Fri Jan 23 10:03:51 2009 From: thijsterlouw@REDACTED (Thijs Terlouw) Date: Fri, 23 Jan 2009 01:03:51 -0800 (PST) Subject: [erlang-questions] gen_tcp:transfer_ownership of socket to another node? In-Reply-To: <4183f4b90901230046p409e7d2fo66fc8f447ad3c73e@mail.gmail.com> References: <4183f4b90901230046p409e7d2fo66fc8f447ad3c73e@mail.gmail.com> Message-ID: <21620863.post@talk.nabble.com> Thijs Terlouw wrote: > > "transfer the ownership of that socket" > I wanted to controlling, but unintentionally changed the name. To clarify, my question is about this function in the context of several nodes: gen_tcp:controlling_process(Socket, Pid). -- View this message in context: http://www.nabble.com/gen_tcp%3Atransfer_ownership-of-socket-to-another-node--tp21620729p21620863.html Sent from the Erlang Questions mailing list archive at Nabble.com. From thijsterlouw@REDACTED Fri Jan 23 10:04:33 2009 From: thijsterlouw@REDACTED (Thijs Terlouw) Date: Fri, 23 Jan 2009 01:04:33 -0800 (PST) Subject: [erlang-questions] gen_tcp:controlling_process of socket to another node? Message-ID: <21620863.post@talk.nabble.com> Thijs Terlouw wrote: > > "transfer the ownership of that socket" > I wanted to say controlling, but unintentionally changed the name. To clarify, my question is about this function in the context of several nodes: gen_tcp:controlling_process(Socket, Pid). -- View this message in context: http://www.nabble.com/gen_tcp%3Atransfer_ownership-of-socket-to-another-node--tp21620729p21620863.html Sent from the Erlang Questions mailing list archive at Nabble.com. From tony@REDACTED Fri Jan 23 10:24:22 2009 From: tony@REDACTED (Tony Rogvall) Date: Fri, 23 Jan 2009 10:24:22 +0100 Subject: [erlang-questions] gen_tcp:transfer_ownership of socket to another node? In-Reply-To: <4183f4b90901230046p409e7d2fo66fc8f447ad3c73e@mail.gmail.com> References: <4183f4b90901230046p409e7d2fo66fc8f447ad3c73e@mail.gmail.com> Message-ID: <178DBE62-5EBD-4CA9-AFFA-4B0591BE549C@rogvall.se> Have you tried it? /Tony On 23 jan 2009, at 09.46, Thijs Terlouw wrote: > What happens when I accept a new TCP connection (in processA) and > then transfer the ownership of that socket from processA to processB > which is running on another Erlang node(B)? I assume that Beam then > keeps 'something' running on the original node(A) to keep the > connection open, even if processA is killed? > > That way i would be able to send data to the socket from processB > after processA is killed? The data would then be copied from one VM > to another VM (because the socket cannot move of course)? > > Is this correct? > > Thijs Terlouw - China > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From vychodil.hynek@REDACTED Fri Jan 23 11:02:57 2009 From: vychodil.hynek@REDACTED (Hynek Vychodil) Date: Fri, 23 Jan 2009 11:02:57 +0100 Subject: [erlang-questions] The If expression In-Reply-To: <3A9F40FC-0F61-4327-905D-B9331AF83D8C@cs.otago.ac.nz> References: <3A9F40FC-0F61-4327-905D-B9331AF83D8C@cs.otago.ac.nz> Message-ID: <20090123100258.3ED6324063@relay.gooddata.com> On Fri, Jan 23, 2009 at 3:54 AM, Richard O'Keefe wrote: > > On 2 Jan 2009, at 9:14 am, Fredrik Svahn wrote: > > In addition to the above (which is kept for backwards compatibility) I > > suggest adding an alternative form with the following syntax: > > > > if Expression -> Body else -> ElseBody end > > > > which should act as syntactical sugar for the more clumsy and > > unintuitive: > > > > case Expression of > > true -> Body; > > _Else -> ElseBody > > end > > > I'm sorry for the late reply, but December/January is the > long holiday in New Zealand, and I only got back yesterday. > > This is a very bad idea because > - It would give us two very *different* conditional structures > with the *same* keyword, where it is hard to tell which one > was intended until several lines later. > > - 'if' isn't actually all that rare. In some code I wrote last > year, I find one 'if' for every four 'case's. The OTP sources > have 1 if/10 case, which is less common, but not _that_ rare. > If the old sense of 'if' were rare, we could probably live with > the confusion. > > - The new syntax is not consistent with Erlang "style", which > expects multiple arms as a matter of routine (like the Fortran, > Ada, Eiffel, Algol 68 "block if" constructs, but without an "else"). > > - As a result the new syntax is rather inconvenient. The majority > of my existing uses of 'if' have more than one arm, so would need > nested new-'if's. It's hard to see that as an improvement. > > > > My hope is that with this improvement 'if'-statements would be the > > recommended choice for expressions evaluating to a bool() > > It would not be an improvement. > Such expressions should be avoided, not canonised. > > The proposal would address two of the problems with the current > > syntax: > > > > 1. Today only guards are allowed, not full expressions. For instance, > > today it is NOT ok to write: > > > > if erlang:system_info(smp_support) -> init_smp(); > > true -> init() > > end. > > > > which many believe is a rather serious limitation of the usefulness. > > And many don't. In fact this is an excellent example of what's > wrong with Boolean functions. The interface *should* have been > something like > > case erlang:system_info(smp) > of not_supported -> ... > ; supported -> ... > end > > and other values are imaginable: smp support might have been compiled > in, but not actually useful because only one core is available. So > maybe the interface should have been > > case erlang:system_info(smp) > of not_supported -> ... > ; interfaces_supported -> ... > ; functional_and_useful -> ... > end > > Indeed, if I wanted to know whether to set up for SMP, I would > probably use system_info(multi_scheduling) instead: > > case erlang:system_info(multi_scheduling) > of disabled -> no SMP or only one scheduler > ; blocked -> there are multiple schedulers and all > but one of them are blocked > ; enabled -> multiple schedulers are really available > end > > About 40 years ago when enumeration types were introduced it > was pointed out that people over-used Boolean. I've been guilty > of that myself. In Erlang, our aim is to write reliable and > maintainable software. We shouldn't regard it as a PROBLEM > that Boolean expressions are hard to use, we should regard it > as a heaven-sent OPPORTUNITY to critically, and I really do mean > SERIOUSLY critically review all uses of Boolean to see whether > they are really appropriate. My own experience is that in the > majority of cases they are not. (My use of 'if' is almost > entirely arithmetic comparisons.) > > > 2. At least of of the guards have to evaluate to true, otherwise a > > runtime error will occur. This leads to unintuitive constructs like: > > > > if Bool -> do_true(); > > true -> do_false() end. > > > > Which could be replaced by a more intuitive: > > > > if Bool -> do_true() else -> do_false() end. > > It may be more FAMILIAR, but that doesn't mean 'else' is a good > thing. I know that writing '; true ->' is a very easy way to get > 'else' in Erlang, but we have a couple of decades of psychology- > of-programming results to show that it's a bad idea. I have > started to replace by > > if X > Y -> a() if X > Y -> a() > ; true -> b() ; X =< Y -> b() > end end > > if X > Y -> a() if X > Y -> a() > ; X < Y -> b() ; X < Y -> b() > ; true -> c() ; X ==Y -> c() > end end > > which I find mildly annoying when _writing_ the code > but enormously helpful when _reading_ it. > > This is one reason why I regard a proposal to add 'else' > to Erlang as a bad idea. > Nice point. Really nice Erlangish way. > > > An open question is if it should also be allowed to have expressions > > without an 'else' clause, as proposed by Damien Katz, i.e.: > > > > if Expression -> Body end > > Obviously not, because > > if Guard -> Body end > > is already legal Erlang syntax. > > > Which might be useful in some cases, e.g. > > > > if Logging -> log:write("Aiee") end, > > Dijkstra's "A Discipline of Programming" gives arguments against > using one-armed ifs in imperative code. In a mostly functional > language it's even worse. Erlang gets this *right*: if you don't > say what to do in some case, then a situation has arisen that > your program does not handle, and the right answer is an exception. > > > In this particular case returning false might seem like a good idea, > > but in other cases e.g. an empty list might be just as natural. I am > > just not sure how to apply the rule of least surprise to this... > > The rule of least surprise has a corollary: > if there ISN'T a least surprising result, > there is no result (that is, there is an exception). > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero! Try Good Data now for free: www.gooddata.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From raimo+erlang-questions@REDACTED Fri Jan 23 11:16:05 2009 From: raimo+erlang-questions@REDACTED (Raimo Niskanen) Date: Fri, 23 Jan 2009 11:16:05 +0100 Subject: [erlang-questions] : I'm not worthy (anthropomorphism ahead) In-Reply-To: <4978F920.80304@ghostgun.com> References: <20090121232450.GL2497@h216-235-12-171.host.egate.net> <4978F920.80304@ghostgun.com> Message-ID: <20090123101605.GB22814@erix.ericsson.se> I fixed these broken links, thank you for pointing them out. On Fri, Jan 23, 2009 at 09:54:24AM +1100, jm wrote: > As an aside on the page you link to ( > http://www.erlang.se/contact/alvsjo.shtml ) there is a link to > http://www.stockholm.se/english/index.htm which gives a 404. It appears > that the new page is http://www.stockholm.se/-/English/ Who ever > maintains this page may wish to update to the new link. > > Having spotted one broken link I thought I'd better continue and check > the rest. There appears to be two more: > This text "Gula Sidorna" which links to > http://www.gulasidorna.se/?lang=en/ also doesn't seem to go where it's > intended. > And, http://www.flygbussarna.com/ seems to be a parked or squatted domain. > > Jeff. > > Vance Shipley wrote: > > http://www.erlang.se/contact/alvsjo.shtml > > > > On Wed, Jan 21, 2009 at 05:46:13PM -0500, Steven Edwards wrote: > > } which Ericsson office is the Mecca of Erlang? I need to know which > > } direction to pray. :) > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions@REDACTED > > http://www.erlang.org/mailman/listinfo/erlang-questions > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions -- / Raimo Niskanen, Erlang/OTP, Ericsson AB From kenji.rikitake@REDACTED Fri Jan 23 11:59:26 2009 From: kenji.rikitake@REDACTED (Kenji Rikitake) Date: Fri, 23 Jan 2009 19:59:26 +0900 Subject: [erlang-questions] annoying yikes In-Reply-To: References: Message-ID: <20090123105926.GA18631@k2r.org> I also experienced the same phenomenon using erlang R12B4 compiled with gcc4.2.1 (stock cc on FreeBSD 7.x) with HiPE. Disabling HiPE or changing compiler to gcc3.4.6 solved the issue. FYI. -- Kenji Rikitake In the message dated Fri, Jan 16, 2009 at 03:00:15AM +0000, Linan Wang writes: > Hi,I have a small program that works well on my iMac but always report > "Yikes! erts_alloc() returned misaligned address 0x4886810e" on a FreeBSD > server. Both machines are loaded with R11B5. Any idea why? > thanks From ulf@REDACTED Fri Jan 23 13:41:52 2009 From: ulf@REDACTED (Ulf Wiger) Date: Fri, 23 Jan 2009 13:41:52 +0100 Subject: [erlang-questions] question re parallel map code on pg 366 of "Programming Erlang" In-Reply-To: <44ed5e0f0901211951i33280b69h7b95b3303f8d154c@mail.gmail.com> References: <44ed5e0f0901211951i33280b69h7b95b3303f8d154c@mail.gmail.com> Message-ID: <8209f740901230441v2636871fje25cc77b674d0f01@mail.gmail.com> I gave a tutorial at the DAMP workshop (in conjunction with POPL) this week, and used pmap() as an example of how parallelizing sequential functions in Erlang is not always as straightforward as one might think. http://ulf.wiger.net/weblog/2009/01/23/erlang-programming-for-multicore/ BR, Ulf W 2009/1/22 David Cabana : > I have a question re Joe's parallel map code on page 366 of Programming Erlang. > Here's the code, modulo a couple of variable name changes. > > pmap(F, Arglist) -> > S = self(), > TaskID = make_ref(), > Workers = lists:map( fun(X) -> > spawn( fun() -> do_F(S, TaskID, F, X ) end) > end, Arglist), > gather(Workers, TaskID). > > do_F(Caller, TaskID, F, X) -> > Caller ! {self(), TaskID, catch(F(X))}. > > gather([W|R], TaskID) -> > receive > {W, TaskID, Val}-> > [Val | gather(R, TaskID)] > end; > > gather([], _) -> > []. > > My question concerns the use of catch inside the do_F function. Here's what Joe > says on page 367: > > "In pmap we use catch(F(H)) when we map the function over the list. In > map we just > use F(H). This is because we want to make sure pmap terminates > correctly in the case > where the computation of F(H) raises an exception." > > I don't get it. > > If the computation of F(H) raises an exception, presumably it would do > so whether F was called by > map or by pmap. Why catch the exception in the one case but not the other? > Why is it important that pmap terminate normally, but not so that map > terminate normally? > > Thanks, > drc > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From zerthurd@REDACTED Fri Jan 23 13:49:58 2009 From: zerthurd@REDACTED (Maxim Treskin) Date: Fri, 23 Jan 2009 18:49:58 +0600 Subject: [erlang-questions] SCTP: controlling process for specified socket AND association ID Message-ID: Hello Is it possible to make controlling process, which handles all messages from specified association ID? At this time, I have one SCTP-listener, which controls socket and routes data received from it to processes of each assoc_id. How I can remove this routing? I want something like SCTP-accept function for C-language, and don't want to use routing logic in listener process. Thank you. -- Maxim Treskin -------------- next part -------------- An HTML attachment was scrubbed... URL: From raimo+erlang-questions@REDACTED Fri Jan 23 14:15:21 2009 From: raimo+erlang-questions@REDACTED (Raimo Niskanen) Date: Fri, 23 Jan 2009 14:15:21 +0100 Subject: [erlang-questions] SCTP: controlling process for specified socket AND association ID In-Reply-To: References: Message-ID: <20090123131520.GA19696@erix.ericsson.se> On Fri, Jan 23, 2009 at 06:49:58PM +0600, Maxim Treskin wrote: > Hello > > Is it possible to make controlling process, which handles all messages from > specified association ID? > At this time, I have one SCTP-listener, which controls socket and routes > data received from it to processes of each assoc_id. > How I can remove this routing? I want something like SCTP-accept function > for C-language, and don't want to use routing logic in listener process. No, that is today not possible. I think what you actually want is the sctp_peeloff() that branches off one association from a socket into a new one-to-one socket. http://tools.ietf.org/html/draft-ietf-tsvwg-sctpsocket-13#section-8.2 That feature is not implemented and have to be carefully thought through, especially regarding SMP semantics. So it is rather far off among future plans. E.g active socket mode is a nearer future plan. > > Thank you. > > -- > Maxim Treskin > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions -- / Raimo Niskanen, Erlang/OTP, Ericsson AB From drcabana@REDACTED Fri Jan 23 16:09:35 2009 From: drcabana@REDACTED (David Cabana) Date: Fri, 23 Jan 2009 10:09:35 -0500 Subject: [erlang-questions] question re parallel map code on pg 366 of "Programming Erlang" In-Reply-To: <8209f740901230441v2636871fje25cc77b674d0f01@mail.gmail.com> References: <44ed5e0f0901211951i33280b69h7b95b3303f8d154c@mail.gmail.com> <8209f740901230441v2636871fje25cc77b674d0f01@mail.gmail.com> Message-ID: <44ed5e0f0901230709w2576be2apc36a03d5ce452da8@mail.gmail.com> Ulf, thanks for that link. The discussion of pmap is very interesting, as is the entire presentation. I don't suppose there's video or a podcast of the spoken portion of the presentation? I have to admit I am not familiar with the Erlang version of QuickCheck ( a similar tool is widely used in Haskell). Googling QuickCheck led me to a commercial tool at http://www.quviq.com/ . Is this the same tool you mention in your presentation? I saw no price mentioned on the quviq site, so I'm guessing this is not something the average student of Erlang can afford to purchase for home use... On Fri, Jan 23, 2009 at 7:41 AM, Ulf Wiger wrote: > I gave a tutorial at the DAMP workshop (in conjunction with POPL) this week, > and used pmap() as an example of how parallelizing sequential functions in > Erlang is not always as straightforward as one might think. > > http://ulf.wiger.net/weblog/2009/01/23/erlang-programming-for-multicore/ From ulf@REDACTED Fri Jan 23 17:12:57 2009 From: ulf@REDACTED (Ulf Wiger) Date: Fri, 23 Jan 2009 17:12:57 +0100 Subject: [erlang-questions] question re parallel map code on pg 366 of "Programming Erlang" In-Reply-To: <44ed5e0f0901230709w2576be2apc36a03d5ce452da8@mail.gmail.com> References: <44ed5e0f0901211951i33280b69h7b95b3303f8d154c@mail.gmail.com> <8209f740901230441v2636871fje25cc77b674d0f01@mail.gmail.com> <44ed5e0f0901230709w2576be2apc36a03d5ce452da8@mail.gmail.com> Message-ID: <8209f740901230812pf47117axa1aa098d5d374968@mail.gmail.com> No video, sorry. That's the same QuickCheck. As for the pricing, I honestly don't know what you'd have to pay. Nor do I know what an average student can afford. In my time, it wasn't much. ;) BR, Ulf W 2009/1/23, David Cabana : > Ulf, thanks for that link. The discussion of pmap is very > interesting, as is the entire presentation. I don't suppose there's > video or a podcast of the spoken portion of the presentation? > > I have to admit I am not familiar with the Erlang version of > QuickCheck ( a similar tool is widely used in Haskell). Googling > QuickCheck led me to a commercial tool at http://www.quviq.com/ . Is > this the same tool you mention in your presentation? I saw no price > mentioned on the quviq site, so I'm guessing this is not something the > average student of Erlang can afford to purchase for home use... > > On Fri, Jan 23, 2009 at 7:41 AM, Ulf Wiger wrote: >> I gave a tutorial at the DAMP workshop (in conjunction with POPL) this >> week, >> and used pmap() as an example of how parallelizing sequential functions in >> Erlang is not always as straightforward as one might think. >> >> http://ulf.wiger.net/weblog/2009/01/23/erlang-programming-for-multicore/ > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From jeedward@REDACTED Fri Jan 23 16:51:17 2009 From: jeedward@REDACTED (John Edward) Date: Fri, 23 Jan 2009 07:51:17 -0800 (PST) Subject: [erlang-questions] Final call for papers: MULTICONF-09 Message-ID: <110965.46677.qm@web45910.mail.sp1.yahoo.com> ? ? The 2009 Multi Conference in Computer Science, Information Technology and Control systems and Computational Science and Computer Engineering (MULTICONF-09) (website: http://www.PromoteResearch.org) will be held during July 13-16 2009 in Orlando, FL, USA. We invite draft paper submissions. The event consists of the following conferences: ????????? International Conference on Artificial Intelligence and Pattern Recognition (AIPR-09) ????????? International Conference on Automation, Robotics and Control Systems (ARCS-09) ????????? International Conference on Bioinformatics, Computational Biology, Genomics and Chemoinformatics (BCBGC-09) ????????? International Conference on Enterprise Information Systems and Web Technologies (EISWT-09) ????????? International Conference on High Performance Computing, Networking and Communication Systems (HPCNCS-09) ????????? International Conference on Information Security and Privacy (ISP-09) ????????? International Conference on Recent Advances in Information Technology and Applications (RAITA-09) ????????? International Conference on Software Engineering Theory and Practice (SETP-09) ????????? International Conference on Theory and Applications of Computational Science (TACS-09) ????????? International Conference on Theoretical and Mathematical Foundations of Computer Science (TMFCS-09) ? The website http://www.PromoteResearch.org? contains more details. ? Sincerely John Edward Publicity committee ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From tali.wang@REDACTED Fri Jan 23 19:48:17 2009 From: tali.wang@REDACTED (Linan Wang) Date: Fri, 23 Jan 2009 18:48:17 +0000 Subject: [erlang-questions] annoying yikes In-Reply-To: <20090123105926.GA18631@k2r.org> References: <20090123105926.GA18631@k2r.org> Message-ID: Interesting solutions. Thanks! On Fri, Jan 23, 2009 at 10:59 AM, Kenji Rikitake wrote: > I also experienced the same phenomenon using erlang R12B4 compiled with > gcc4.2.1 (stock cc on FreeBSD 7.x) with HiPE. Disabling HiPE or > changing compiler to gcc3.4.6 solved the issue. FYI. -- Kenji Rikitake > > In the message < > abb391f80901151900p4fb9998eo7de83827c118bfb8@REDACTED> > dated Fri, Jan 16, 2009 at 03:00:15AM +0000, > Linan Wang writes: > > Hi,I have a small program that works well on my iMac but always report > > "Yikes! erts_alloc() returned misaligned address 0x4886810e" on a FreeBSD > > server. Both machines are loaded with R11B5. Any idea why? > > thanks > -- Best regards Linan Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: From cureadvocate@REDACTED Fri Jan 23 21:09:05 2009 From: cureadvocate@REDACTED (Steven Edwards) Date: Fri, 23 Jan 2009 15:09:05 -0500 Subject: [erlang-questions] JInterface, RPC, self() Message-ID: `I still heart Erlang, but we're having some trouble communicating. I'm trying to get RPCs to work correctly, but receive {Pid, Result} fails. I'm pretty sure that it fails because I use {mbox, simpleserver@REDACTED} as the initial Pid and JInterface responds with a differently named process id. (Same process, but Erlang's representation.) I can get it working through a hack (by returning {pid_result, mbox.whereis("mbox")} from the Java server on a {getpid} request), but is there a more elegant solution? Thanks, Steven // Client: --- -module(client). -export([echo/1, add/2, add2/2]). rpc(Pid, Msg) -> Pid ! {self(), Msg}, receive {Pid, Result} -> {pid_received, Result}; Result -> {nope, Result} after 750 -> false end. echo(Msg) -> rpc({mbox, simpleserver@REDACTED}, {echo, Msg}). add(X, Y) -> rpc({mbox, simpleserver@REDACTED}, {add, X, Y}). add2(X, Y) -> rpc({mbox, simpleserver@REDACTED}, {add2, X, Y}). --- Server: --- import com.ericsson.otp.erlang.*; public class SimpleServer { public static void main(String[] args) throws Exception { OtpNode self = new OtpNode("simpleserver", "cookie"); OtpMbox mbox = self.createMbox("mbox"); OtpErlangObject[] tupleElements = new OtpErlangObject[2]; OtpEpmd.publishPort(self); tupleElements[0] = mbox.self(); while (true) try { OtpErlangTuple terms = (OtpErlangTuple) mbox.receive(); OtpErlangPid from = (OtpErlangPid) terms.elementAt(0); OtpErlangTuple msg = (OtpErlangTuple) terms.elementAt(1); String command = msg.elementAt(0).toString(); if (command.equals("echo")) { mbox.send(from, new OtpErlangAtom(msg.elementAt(1).toString())); } else if (command.equals("add")) { long x = ((OtpErlangLong) msg.elementAt(1)).longValue(); long y = ((OtpErlangLong) msg.elementAt(2)).longValue(); mbox.send(from, new OtpErlangLong(x+y)); } else if (command.equals("add2")) { long x = ((OtpErlangLong) msg.elementAt(1)).longValue(); long y = ((OtpErlangLong) msg.elementAt(2)).longValue(); tupleElements[1] = new OtpErlangLong(x+y); mbox.send(from, new OtpErlangTuple(tupleElements)); } } catch (OtpErlangExit e) { break; } } } --- -------------- next part -------------- An HTML attachment was scrubbed... URL: From dcaoyuan@REDACTED Fri Jan 23 22:31:47 2009 From: dcaoyuan@REDACTED (Caoyuan) Date: Sat, 24 Jan 2009 05:31:47 +0800 Subject: [erlang-questions] JInterface, RPC, self() In-Reply-To: References: Message-ID: http://blogtrader.net/page/dcaoyuan/entry/rpc_server_for_erlang_in 2009/1/24 Steven Edwards : > `I still heart Erlang, but we're having some trouble communicating. I'm > trying to get RPCs to work correctly, but receive {Pid, Result} fails. I'm > pretty sure that it fails because I use {mbox, simpleserver@REDACTED} as the > initial Pid and JInterface responds with a differently named process id. > (Same process, but Erlang's representation.) > > I can get it working through a hack (by returning {pid_result, > mbox.whereis("mbox")} from the Java server on a {getpid} request), but is > there a more elegant solution? > > Thanks, > > Steven > > // > > Client: > > --- > -module(client). > -export([echo/1, add/2, add2/2]). > > rpc(Pid, Msg) -> > Pid ! {self(), Msg}, > receive > {Pid, Result} -> {pid_received, Result}; > Result -> {nope, Result} > after 750 -> false > end. > > echo(Msg) -> rpc({mbox, simpleserver@REDACTED}, {echo, Msg}). > > add(X, Y) -> rpc({mbox, simpleserver@REDACTED}, {add, X, Y}). > > add2(X, Y) -> rpc({mbox, simpleserver@REDACTED}, {add2, X, Y}). > --- > > Server: > > --- > import com.ericsson.otp.erlang.*; > > public class SimpleServer { > public static void main(String[] args) throws Exception { > OtpNode self = new OtpNode("simpleserver", "cookie"); > OtpMbox mbox = self.createMbox("mbox"); > OtpErlangObject[] tupleElements = new OtpErlangObject[2]; > > OtpEpmd.publishPort(self); > tupleElements[0] = mbox.self(); > > while (true) try { > OtpErlangTuple terms = (OtpErlangTuple) mbox.receive(); > OtpErlangPid from = (OtpErlangPid) terms.elementAt(0); > OtpErlangTuple msg = (OtpErlangTuple) terms.elementAt(1); > > String command = msg.elementAt(0).toString(); > > if (command.equals("echo")) { > mbox.send(from, new > OtpErlangAtom(msg.elementAt(1).toString())); > } > else if (command.equals("add")) { > long x = ((OtpErlangLong) msg.elementAt(1)).longValue(); > long y = ((OtpErlangLong) msg.elementAt(2)).longValue(); > > mbox.send(from, new OtpErlangLong(x+y)); > } > else if (command.equals("add2")) { > long x = ((OtpErlangLong) msg.elementAt(1)).longValue(); > long y = ((OtpErlangLong) msg.elementAt(2)).longValue(); > tupleElements[1] = new OtpErlangLong(x+y); > > mbox.send(from, new OtpErlangTuple(tupleElements)); > } > } > catch (OtpErlangExit e) { > break; > } > } > } > --- > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From fredrik.svahn@REDACTED Fri Jan 23 23:35:52 2009 From: fredrik.svahn@REDACTED (Fredrik Svahn) Date: Fri, 23 Jan 2009 23:35:52 +0100 Subject: [erlang-questions] The If expression In-Reply-To: <3A9F40FC-0F61-4327-905D-B9331AF83D8C@cs.otago.ac.nz> References: <3A9F40FC-0F61-4327-905D-B9331AF83D8C@cs.otago.ac.nz> Message-ID: On Fri, Jan 23, 2009 at 3:54 AM, Richard O'Keefe wrote: > > On 2 Jan 2009, at 9:14 am, Fredrik Svahn wrote: > I'm sorry for the late reply, but December/January is the > long holiday in New Zealand, and I only got back yesterday. Thanks for the reply. To be honest I had put my plans to write an EEP on hold because I only got one reply which was mostly disagreeing. Using expressions in 'if'-expressions is more of a nice-to-have for me, so I will just keep on using 'case'. A few comments below... > - It would give us two very *different* conditional structures > with the *same* keyword, where it is hard to tell which one > was intended until several lines later. I agree that this is a disadvantage with the proposal. I also agree with your statement below that if the old sense of 'if' is rare (or even discouraged), we can probably live with the confusion. >- 'if' isn't actually all that rare. In some code I wrote last > year, I find one 'if' for every four 'case's. The OTP sources > have 1 if/10 case, which is less common, but not _that_ rare. > If the old sense of 'if' were rare, we could probably live with > the confusion. Newcomers to this mailing list asking how to use "if" are invariably recommended to use "case" instead. Combined with the fact that you can only use guards it is almost FAQ material. Considering this and all the beating the 'if' expression has gotten over the years on the mailing list my assumption was that the use of 'if' was really rather infrequent even outside of OTP. I might be wrong. (Hmmm, I just checked, and there actually is a chapter about 'if':s in the FAQ. It is recommending the use of 'case' and even states that "case is used much more frequently"). > - The new syntax is not consistent with Erlang "style", which > expects multiple arms as a matter of routine (like the Fortran, > Ada, Eiffel, Algol 68 "block if" constructs, but without an "else"). Just out of curiosity, is there any other programming language out there which has an 'if' and which does not have an 'else' apart from the Commodore 64 BASIC? I am not saying Erlang should have because everyone else does. I am just wondering out of curiosity. Even Haskell has an if ... else construct (which like this proposal is syntactic sugar for (or equivalent with) a case construct). > - As a result the new syntax is rather inconvenient. The majority > of my existing uses of 'if' have more than one arm, so would need > nested new-'if's. It's hard to see that as an improvement. The proposal is backwards compatible (with the obvious exception that 'else' would need to become a keyword) so there is no need for you to change your coding style. > About 40 years ago when enumeration types were introduced it > was pointed out that people over-used Boolean. I've been guilty > of that myself. In Erlang, our aim is to write reliable and > maintainable software. We shouldn't regard it as a PROBLEM > that Boolean expressions are hard to use, we should regard it > as a heaven-sent OPPORTUNITY to critically, and I really do mean > SERIOUSLY critically review all uses of Boolean to see whether > they are really appropriate. My own experience is that in the > majority of cases they are not. There is a lot of code out there to critically review, then. In fact 'true' is the second most popular atom in the OTP code, and 'false' is the fourth most popular. percent count atom 7.749% 15074 ok 7.489% 14568 true 4.908% 9547 error 4.895% 9523 false 1.574% 3061 mandatory 1.025% 1994 undefined 0.912% 1774 EXIT 0.904% 1758 reply 0.870% 1693 value > (My use of 'if' is almost entirely arithmetic comparisons.) What else can it really be used for? Ok, there are a couple of guard bifs, but that is basically it, isn't it? BR /Fredrik From tony@REDACTED Fri Jan 23 23:41:59 2009 From: tony@REDACTED (Tony Rogvall) Date: Fri, 23 Jan 2009 23:41:59 +0100 Subject: [erlang-questions] gen_tcp:transfer_ownership of socket to another node? In-Reply-To: <4183f4b90901230046p409e7d2fo66fc8f447ad3c73e@mail.gmail.com> References: <4183f4b90901230046p409e7d2fo66fc8f447ad3c73e@mail.gmail.com> Message-ID: Here is the answer ;-) (a@REDACTED)2> Pid = spawn(b@REDACTED, fun() -> receive X -> io:format("got ~p\n", [X]) end end). <6016.42.0> (a@REDACTED)3> {ok,U} = inet_udp:open(0,[]). {ok,#Port<0.451>} (a@REDACTED)4> inet_udp:controlling_process(U, Pid). {error,badarg} I other words it is not allowed. /Tony On 23 jan 2009, at 09.46, Thijs Terlouw wrote: > What happens when I accept a new TCP connection (in processA) and > then transfer the ownership of that socket from processA to processB > which is running on another Erlang node(B)? I assume that Beam then > keeps 'something' running on the original node(A) to keep the > connection open, even if processA is killed? > > That way i would be able to send data to the socket from processB > after processA is killed? The data would then be copied from one VM > to another VM (because the socket cannot move of course)? > > Is this correct? > > Thijs Terlouw - China > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions -------------- next part -------------- An HTML attachment was scrubbed... URL: From cayle.spandon@REDACTED Sat Jan 24 01:10:10 2009 From: cayle.spandon@REDACTED (cayle.spandon@REDACTED) Date: Sat, 24 Jan 2009 00:10:10 +0000 Subject: [erlang-questions] Unexpected behavior by io:fread. Message-ID: <00163613a40a34acb504612f546a@google.com> I have run into some unexpected behavior by io:fread. I was wondering if someone could check whether there is something wrong with the way I use io:fread or whether there is a bug in io:fread. I have a text file which contains a "triangle of numbers"as follows:
59
73 41
52 40 09
26 53 06 34
10 51 87 86 81
61 95 66 57 25 68
90 81 80 38 92 67 73
30 28 51 76 81 18 75 44
...
There is a single space between each pair of numbers and each line ends with a carriage-return new-line pair. I use the following Erlang program to read this file into a list.
-module(euler67).
-author('Cayle Spandon').

-export([solve/0]).

solve() ->
{ok, File} = file:open("triangle.txt", [read]),
Data = read_file(File),
ok = file:close(File),
Data.

read_file(File) ->
read_file(File, []).

read_file(File, Data) ->
case io:fread(File, "", "~d") of
{ok, [N]} ->
read_file(File, [N | Data]);
eof ->
lists:reverse(Data)
end.
The output of this program is:
(erlide@REDACTED)30> euler67:solve().
[59,73,41,52,40,9,26,53,6,3410,51,87,86,8161,95,66,57,25,
6890,81,80,38,92,67,7330,28,51,76,81|...]
Note how the last number of the fourth line (34) and the first number of the fifth line (10) have been merged into a single number 3410. When I dump the text file using "od" there is nothing special about those lines; they end with cr-nl just like any other line:
> od -ta triangle.txt
0000000 5 9 cr nl 7 3 sp 4 1 cr nl 5 2 sp 4 0
0000020 sp 0 9 cr nl 2 6 sp 5 3 sp 0 6 sp 3 4
0000040 cr nl 1 0 sp 5 1 sp 8 7 sp 8 6 sp 8 1
0000060 cr nl 6 1 sp 9 5 sp 6 6 sp 5 7 sp 2 5
0000100 sp 6 8 cr nl 9 0 sp 8 1 sp 8 0 sp 3 8
0000120 sp 9 2 sp 6 7 sp 7 3 cr nl 3 0 sp 2 8
0000140 sp 5 1 sp 7 6 sp 8 1 sp 1 8 sp 7 5 sp
0000160 4 4 cr nl 8 4 sp 1 4 sp 9 5 sp 8 7 sp
One interesting observation is that some of the numbers for which the problem occurs happen to be on 16-byte boundary in the text file (but not all, for example 6890). -------------- next part -------------- An HTML attachment was scrubbed... URL: From cureadvocate@REDACTED Sat Jan 24 01:41:08 2009 From: cureadvocate@REDACTED (Steven Edwards) Date: Fri, 23 Jan 2009 19:41:08 -0500 Subject: [erlang-questions] JInterface, RPC, self() In-Reply-To: References: Message-ID: Thanks. I'll spend some time playing with the code to make sure I understand it. On Fri, Jan 23, 2009 at 4:31 PM, Caoyuan wrote: > http://blogtrader.net/page/dcaoyuan/entry/rpc_server_for_erlang_in > > 2009/1/24 Steven Edwards : > > `I still heart Erlang, but we're having some trouble communicating. I'm > > trying to get RPCs to work correctly, but receive {Pid, Result} fails. > I'm > > pretty sure that it fails because I use {mbox, simpleserver@REDACTED} as > the > > initial Pid and JInterface responds with a differently named process id. > > (Same process, but Erlang's representation.) > > > > I can get it working through a hack (by returning {pid_result, > > mbox.whereis("mbox")} from the Java server on a {getpid} request), but is > > there a more elegant solution? > > > > Thanks, > > > > Steven > > > > // > > > > Client: > > > > --- > > -module(client). > > -export([echo/1, add/2, add2/2]). > > > > rpc(Pid, Msg) -> > > Pid ! {self(), Msg}, > > receive > > {Pid, Result} -> {pid_received, Result}; > > Result -> {nope, Result} > > after 750 -> false > > end. > > > > echo(Msg) -> rpc({mbox, simpleserver@REDACTED}, {echo, Msg}). > > > > add(X, Y) -> rpc({mbox, simpleserver@REDACTED}, {add, X, Y}). > > > > add2(X, Y) -> rpc({mbox, simpleserver@REDACTED}, {add2, X, Y}). > > --- > > > > Server: > > > > --- > > import com.ericsson.otp.erlang.*; > > > > public class SimpleServer { > > public static void main(String[] args) throws Exception { > > OtpNode self = new OtpNode("simpleserver", "cookie"); > > OtpMbox mbox = self.createMbox("mbox"); > > OtpErlangObject[] tupleElements = new OtpErlangObject[2]; > > > > OtpEpmd.publishPort(self); > > tupleElements[0] = mbox.self(); > > > > while (true) try { > > OtpErlangTuple terms = (OtpErlangTuple) mbox.receive(); > > OtpErlangPid from = (OtpErlangPid) terms.elementAt(0); > > OtpErlangTuple msg = (OtpErlangTuple) terms.elementAt(1); > > > > String command = msg.elementAt(0).toString(); > > > > if (command.equals("echo")) { > > mbox.send(from, new > > OtpErlangAtom(msg.elementAt(1).toString())); > > } > > else if (command.equals("add")) { > > long x = ((OtpErlangLong) msg.elementAt(1)).longValue(); > > long y = ((OtpErlangLong) msg.elementAt(2)).longValue(); > > > > mbox.send(from, new OtpErlangLong(x+y)); > > } > > else if (command.equals("add2")) { > > long x = ((OtpErlangLong) msg.elementAt(1)).longValue(); > > long y = ((OtpErlangLong) msg.elementAt(2)).longValue(); > > tupleElements[1] = new OtpErlangLong(x+y); > > > > mbox.send(from, new OtpErlangTuple(tupleElements)); > > } > > } > > catch (OtpErlangExit e) { > > break; > > } > > } > > } > > --- > > > > > > > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions@REDACTED > > http://www.erlang.org/mailman/listinfo/erlang-questions > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cureadvocate@REDACTED Sat Jan 24 02:14:45 2009 From: cureadvocate@REDACTED (Steven Edwards) Date: Fri, 23 Jan 2009 20:14:45 -0500 Subject: [erlang-questions] JInterface, RPC, self() In-Reply-To: References: Message-ID: A simple solution came to mind: if receive {Pid, Result} isn't working because Pid is bound to {mbox, simpleserver@REDACTED}, why not return that instead of mbox.self()? Unsurprisingly, it works! The updated server code: --- import com.ericsson.otp.erlang.*; public class SimpleServer { public static void main(String[] args) throws Exception { OtpNode self = new OtpNode("simpleserver", "cookie"); OtpMbox mbox = self.createMbox("mbox"); OtpErlangObject[] tupleElements = new OtpErlangObject[2]; OtpErlangObject[] selfTuple = new OtpErlangObject[2]; selfTuple[0] = new OtpErlangAtom("mbox"); selfTuple[1] = new OtpErlangAtom(self.node()); OtpEpmd.publishPort(self); tupleElements[0] = new OtpErlangTuple(selfTuple); while (true) try { OtpErlangTuple terms = (OtpErlangTuple) mbox.receive(); OtpErlangPid from = (OtpErlangPid) terms.elementAt(0); OtpErlangTuple msg = (OtpErlangTuple) terms.elementAt(1); String command = msg.elementAt(0).toString(); if (command.equals("echo")) { mbox.send(from, new OtpErlangAtom(msg.elementAt(1).toString())); } else if (command.equals("add")) { long x = ((OtpErlangLong) msg.elementAt(1)).longValue(); long y = ((OtpErlangLong) msg.elementAt(2)).longValue(); mbox.send(from, new OtpErlangLong(x+y)); } else if (command.equals("add2")) { long x = ((OtpErlangLong) msg.elementAt(1)).longValue(); long y = ((OtpErlangLong) msg.elementAt(2)).longValue(); tupleElements[1] = new OtpErlangLong(x+y); mbox.send(from, new OtpErlangTuple(tupleElements)); } } catch (OtpErlangExit e) { break; } } } --- On Fri, Jan 23, 2009 at 3:09 PM, Steven Edwards wrote: > `I still heart Erlang, but we're having some trouble communicating. I'm > trying to get RPCs to work correctly, but receive {Pid, Result} fails. I'm > pretty sure that it fails because I use {mbox, simpleserver@REDACTED} as > the initial Pid and JInterface responds with a differently named process > id. (Same process, but Erlang's representation.) > > I can get it working through a hack (by returning {pid_result, > mbox.whereis("mbox")} from the Java server on a {getpid} request), but is > there a more elegant solution? > > Thanks, > > Steven -------------- next part -------------- An HTML attachment was scrubbed... URL: From rvirding@REDACTED Sat Jan 24 03:31:33 2009 From: rvirding@REDACTED (Robert Virding) Date: Sat, 24 Jan 2009 03:31:33 +0100 Subject: [erlang-questions] JInterface, RPC, self() In-Reply-To: References: Message-ID: <3dbc6d1c0901231831p1e321b02r658616edbbe784a6@mail.gmail.com> 2009/1/23 Steven Edwards > `I still heart Erlang, but we're having some trouble communicating. I'm > trying to get RPCs to work correctly, but receive {Pid, Result} fails. I'm > pretty sure that it fails because I use {mbox, simpleserver@REDACTED} as > the initial Pid and JInterface responds with a differently named process > id. (Same process, but Erlang's representation.) The simple answer is that {mbox,simpleserver@REDACTED} is not the pid of a process, it is a tuple which us interpreted as the registered name on another node. So if the actual pid is returned in the message then it can never match this (or any) tuple. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From thijsterlouw@REDACTED Sat Jan 24 06:08:24 2009 From: thijsterlouw@REDACTED (Thijs Terlouw) Date: Fri, 23 Jan 2009 21:08:24 -0800 (PST) Subject: [erlang-questions] gen_tcp:transfer_ownership of socket to another node? In-Reply-To: References: <4183f4b90901230046p409e7d2fo66fc8f447ad3c73e@mail.gmail.com> Message-ID: <21637338.post@talk.nabble.com> Tony Rogvall-2 wrote: > > Here is the answer ;-) > I other words it is not allowed. > /Tony > Thanks. In the meantime I also tried it and I reached the same conclusion. I started two different nodes, one running a server program and one running a client. Then in the server program I spawned a new process to run on the client node and handed the control over to that process. This all worked fine. In the spawned process I verified the node() and then tried to do socket operations, but got the badarg error. So it seems it is allowed to change the controlling_process to a process on a different node. But on that node, you cannot do anything with the socket (get badarg error). When you stay on the same node, everything works as expected. This should be clarified in the documentation I think. -- View this message in context: http://www.nabble.com/gen_tcp%3Atransfer_ownership-of-socket-to-another-node--tp21620729p21637338.html Sent from the Erlang Questions mailing list archive at Nabble.com. From cureadvocate@REDACTED Sat Jan 24 12:44:55 2009 From: cureadvocate@REDACTED (Steven Edwards) Date: Sat, 24 Jan 2009 06:44:55 -0500 Subject: [erlang-questions] JInterface, RPC, self() In-Reply-To: <3dbc6d1c0901231831p1e321b02r658616edbbe784a6@mail.gmail.com> References: <3dbc6d1c0901231831p1e321b02r658616edbbe784a6@mail.gmail.com> Message-ID: Gotcha. Is there a BIF that translates the tuple into the pid? Steven On Fri, Jan 23, 2009 at 9:31 PM, Robert Virding wrote: > 2009/1/23 Steven Edwards > >> `I still heart Erlang, but we're having some trouble communicating. I'm >> trying to get RPCs to work correctly, but receive {Pid, Result} fails. I'm >> pretty sure that it fails because I use {mbox, simpleserver@REDACTED} as >> the initial Pid and JInterface responds with a differently named process >> id. (Same process, but Erlang's representation.) > > > The simple answer is that {mbox,simpleserver@REDACTED} is not the pid of a > process, it is a tuple which us interpreted as the registered name on > another node. So if the actual pid is returned in the message then it can > never match this (or any) tuple. > > Robert > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thijsterlouw@REDACTED Sat Jan 24 15:06:27 2009 From: thijsterlouw@REDACTED (Thijs Terlouw) Date: Sat, 24 Jan 2009 06:06:27 -0800 (PST) Subject: [erlang-questions] Re gistering a process with multiple names In-Reply-To: <95be1d3b0901220240p437b4f5fj913f69d6bfba08ed@mail.gmail.com> References: <95be1d3b0901220240p437b4f5fj913f69d6bfba08ed@mail.gmail.com> Message-ID: <21640975.post@talk.nabble.com> Vlad Dumitrescu-2 wrote: > > If your process names are dynamically generated, you might want to > avoid using atoms (i.e. erlang:register/2) for them. Your registry > could use any term as name. If you use the global module to register (instead of erlang module), you can also use terms instead of just atoms: global:register_name(Name, Pid) Name = term() Pid = pid() I never understood why erlang:register only accepts atoms. Seems a waste to me. ----- - Thijs Terlouw, http://www.startinchina.com Shenzhen, China -- View this message in context: http://www.nabble.com/Registering-a-process-with-multiple-names-tp21601309p21640975.html Sent from the Erlang Questions mailing list archive at Nabble.com. From rvirding@REDACTED Sat Jan 24 16:46:30 2009 From: rvirding@REDACTED (Robert Virding) Date: Sat, 24 Jan 2009 16:46:30 +0100 Subject: [erlang-questions] JInterface, RPC, self() In-Reply-To: References: <3dbc6d1c0901231831p1e321b02r658616edbbe784a6@mail.gmail.com> Message-ID: <3dbc6d1c0901240746s3dadd337v500a9aadec09a94c@mail.gmail.com> Not directly no. Doing whereis/1 or registered/0 will only work with registered names on the same node. An quick solution is to do an rpc to other node and do whereis/1 there and send back the pid. If you intend to use globally registered names more extensively then I would recommend the module 'group'. Robert 2009/1/24 Steven Edwards > Gotcha. Is there a BIF that translates the tuple into the pid? > > Steven > > On Fri, Jan 23, 2009 at 9:31 PM, Robert Virding wrote: > >> 2009/1/23 Steven Edwards >> >>> `I still heart Erlang, but we're having some trouble communicating. I'm >>> trying to get RPCs to work correctly, but receive {Pid, Result} fails. I'm >>> pretty sure that it fails because I use {mbox, simpleserver@REDACTED} as >>> the initial Pid and JInterface responds with a differently named process >>> id. (Same process, but Erlang's representation.) >> >> >> The simple answer is that {mbox,simpleserver@REDACTED} is not the pid of >> a process, it is a tuple which us interpreted as the registered name on >> another node. So if the actual pid is returned in the message then it can >> never match this (or any) tuple. >> >> Robert >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cureadvocate@REDACTED Sat Jan 24 17:36:06 2009 From: cureadvocate@REDACTED (Steven Edwards) Date: Sat, 24 Jan 2009 11:36:06 -0500 Subject: [erlang-questions] JInterface, RPC, self() In-Reply-To: <3dbc6d1c0901240746s3dadd337v500a9aadec09a94c@mail.gmail.com> References: <3dbc6d1c0901231831p1e321b02r658616edbbe784a6@mail.gmail.com> <3dbc6d1c0901240746s3dadd337v500a9aadec09a94c@mail.gmail.com> Message-ID: Thanks. The quick solution is the one I chose: send {ident}, receive {pid, Pid} for each new Java node. I know the lists module is implemented in a non-Erlang language (C?) to be more efficient. Are global and the other kernel modules implemented in a similar fashion? Steven On Sat, Jan 24, 2009 at 10:46 AM, Robert Virding wrote: > Not directly no. Doing whereis/1 or registered/0 will only work with > registered names on the same node. An quick solution is to do an rpc to > other node and do whereis/1 there and send back the pid. If you intend to > use globally registered names more extensively then I would recommend the > module 'group'. > > Robert > > 2009/1/24 Steven Edwards > > Gotcha. Is there a BIF that translates the tuple into the pid? >> >> Steven >> >> On Fri, Jan 23, 2009 at 9:31 PM, Robert Virding wrote: >> >>> 2009/1/23 Steven Edwards >>> >>>> `I still heart Erlang, but we're having some trouble communicating. I'm >>>> trying to get RPCs to work correctly, but receive {Pid, Result} fails. I'm >>>> pretty sure that it fails because I use {mbox, simpleserver@REDACTED} >>>> as the initial Pid and JInterface responds with a differently named process >>>> id. (Same process, but Erlang's representation.) >>> >>> >>> The simple answer is that {mbox,simpleserver@REDACTED} is not the pid of >>> a process, it is a tuple which us interpreted as the registered name on >>> another node. So if the actual pid is returned in the message then it can >>> never match this (or any) tuple. >>> >>> Robert >>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ad.sergey@REDACTED Sat Jan 24 22:00:46 2009 From: ad.sergey@REDACTED (Sergey S) Date: Sat, 24 Jan 2009 13:00:46 -0800 Subject: [erlang-questions] Why are you using inlining? Message-ID: Hello. When do you think inlining is profitable trick? As Erlang has support of inlining, then there should be situations where inlining is significant. I was looking for examples, but didn't find any :/ It's good idea to make some experiments, but I didn't achieve any interesting results. Which kind of code does become faster when using inlining? Thanks. -- Sergey From drcabana@REDACTED Sat Jan 24 22:40:26 2009 From: drcabana@REDACTED (David Cabana) Date: Sat, 24 Jan 2009 16:40:26 -0500 Subject: [erlang-questions] How should one specify compiler options when compiling from emacs erlang-mode? Message-ID: <44ed5e0f0901241340u12a1e181v7d3039acae0329f0@mail.gmail.com> What is the accepted way to specify compiler options when using emacs erlang-mode? I want to specify an include path, without randomly hacking up erlang.el in non-maintainable ways. Thank you, drc From ad.sergey@REDACTED Sun Jan 25 02:01:02 2009 From: ad.sergey@REDACTED (Sergey S) Date: Sat, 24 Jan 2009 17:01:02 -0800 Subject: [erlang-questions] Can Erlang messages be delivered out of order? Message-ID: Hello. Does Erlang runtime guarantee that messages will be delivered in exactly the same order as they were sent? To illustrate my question I've written a simple example: %------------- process_flag(trap_exit, true), Parent = self(), spawn_link(fun() -> Parent ! hello, Parent ! world end) receive hello -> ok end, receive world -> ok end, receive {'EXIT', _Pid, normal} -> ok end. %------------- Is it guaranteed by the runtime that the 'hello' message will always be the first message put into mailbox, 'world' - the second one, and {'EXIT', _Pid, normal} - third? Thanks. -- Sergey From bqt@REDACTED Sun Jan 25 04:06:37 2009 From: bqt@REDACTED (Johnny Billquist) Date: Sun, 25 Jan 2009 04:06:37 +0100 Subject: [erlang-questions] Can Erlang messages be delivered out of order? In-Reply-To: References: Message-ID: <497BD73D.5050708@softjar.se> Sergey S wrote: > Hello. > > Does Erlang runtime guarantee that messages will be delivered in > exactly the same order as they were sent? > > To illustrate my question I've written a simple example: > > %------------- > process_flag(trap_exit, true), > Parent = self(), > > spawn_link(fun() -> > Parent ! hello, > Parent ! world > end) > > receive hello -> ok end, > receive world -> ok end, > receive {'EXIT', _Pid, normal} -> ok end. > %------------- > > Is it guaranteed by the runtime that the 'hello' message will always > be the first message put into mailbox, 'world' - the second one, and > {'EXIT', _Pid, normal} - third? If you read the manual, you'll find that each process have it's own receive queue, and that new messages are always placed at the end of that queue. So, for you example, yes. The messages will be in the order you expect. It always becomes more interesting when you have several processes doing sends to the same target process, since then it's impossible to tell which message will be first in the queue in that case, but that should be pretty obvious. :-) However, your example program don't work the way you seem to expect anyway. The receive function isn't actually extracting the first message in the receive queue, but the first *matching* message. So, even if the messages would have been pleced in the wrong order, your program would have worked just as fine. Johnny From voaneos@REDACTED Sun Jan 25 10:12:23 2009 From: voaneos@REDACTED (Voaneos) Date: Sun, 25 Jan 2009 17:12:23 +0800 Subject: [erlang-questions] i got "command not found" when make install Message-ID: <21a6acd40901250112j4726f9cld3e4428a536064f5@mail.gmail.com> hi all i got no error when 'configure', but error when make install make[5]: Leaving directory `/root/backup/otp_src_R12B-5/erts/lib_src' make[4]: Leaving directory `/root/backup/otp_src_R12B-5/erts/lib_src' make[3]: Leaving directory `/root/backup/otp_src_R12B-5/erts/lib_src' make[2]: Leaving directory `/root/backup/otp_src_R12B-5/erts/lib_src' make[2]: Entering directory `/root/backup/otp_src_R12B-5/erts/start_scripts' make -w RELEASE_PATH=/usr/local/lib/erlang release_spec make[3]: Entering directory `/root/backup/otp_src_R12B-5/erts/start_scripts' /usr/bin/install -c -d /root/backup/otp_src_R12B-5/erts/start_scripts/tmp ( cd /root/backup/otp_src_R12B-5/erts/start_scripts/tmp && \ erlc -W -I/root/backup/otp_src_R12B-5/lib/kernel/ebin -I/root/backup/otp_src_R12B-5/lib/stdlib/ebin -I/root/backup/otp_src_R12B-5/lib/sasl/ebin -o /root/backup/otp_src_R12B-5/erts/start_scripts/start_clean.script /root/backup/otp_src_R12B-5/erts/start_scripts/start_clean.rel ) /bin/sh: line 1: erlc: command not found make[3]: *** [/root/backup/otp_src_R12B-5/erts/start_scripts/start_clean.script] Error 127 make[3]: Leaving directory `/root/backup/otp_src_R12B-5/erts/start_scripts' make[2]: *** [release] Error 2 make[2]: Leaving directory `/root/backup/otp_src_R12B-5/erts/start_scripts' make[1]: *** [release] Error 2 make[1]: Leaving directory `/root/backup/otp_src_R12B-5/erts' make: *** [install.emulator] Error 2 [root@REDACTED otp_src_R12B-5]# my os Linux fscbx 2.6.18-53.el5 #1 SMP Mon Nov 12 02:22:48 EST 2007 i686 i686 i386 GNU/Linux -------------- next part -------------- An HTML attachment was scrubbed... URL: From exta7@REDACTED Sun Jan 25 12:01:42 2009 From: exta7@REDACTED (Zvi) Date: Sun, 25 Jan 2009 03:01:42 -0800 (PST) Subject: [erlang-questions] The If expression In-Reply-To: References: Message-ID: <21650458.post@talk.nabble.com> 1. I'm in favor of deperectaing if and using some LISP-like cond mechanism (cond even reserved word), i.e.: cond BoolExpr1 [when Guard1] -> Val1; BoolExpr2 [when Guard2] -> Val2; ... BoolExprN [when GuardN] -> ValN; [true -> ValOtherwise] end there might be some syntactic sugar for OTHERWISE clause (but better not, see below). Also might needed some mechanism for combining several BoolExpr/Guard clauses with the same Val expression. 2. I miss C/C++/Java like conditional if expresssion: Cond ? Expr1 : Expr2 it's much clearer than Erlang's: case Cond of true -> Expr1 ; false -> Expr2 end I using macro like: -define(IF(cond,e1,e2), (case (cond) of true -> (e1); false -> (e2) end) ). but syntactic sugar at the language level would be much better. 3. With all the multicore buzz, I that new speculative parallel control flow mechanisms are needed, like pcase and pcond: pcase Expr of Pattern1 [when Guard1] -> Expr1; Pattern2 [when Guard2] -> Expr2; ... PatternN [when GuardN] -> ExprN end pcond Cond1 [when Guard1] -> Expr1; Cond2 [when Guard2] -> Expr2; ... CondN [when GuardN] -> ExprN end Here conditions/patterns aren't calculated/matched in the serial orded from top down, but in parallel and when the first is true or matched it's corresponding expression is evaluated, thus "else"/"otherwise/->true" clause is must be avoided. Thus Richard's examples are already multicore future-proof ;) pcond X > Y -> a(); X =< Y -> b() end pcond X > Y -> a(); X < Y -> b(); X ==Y -> c(); end pcase math:sign(X-Y) of 1 -> a(); -1 -> b(); 0 -> c(); end The next part is speculative execution of expressions themselves, but before there are need to be mechanism of specifing pure functions. Zvi -- View this message in context: http://www.nabble.com/The-If-expression-tp21244494p21650458.html Sent from the Erlang Questions mailing list archive at Nabble.com. From ad.sergey@REDACTED Sun Jan 25 12:56:25 2009 From: ad.sergey@REDACTED (Sergey S) Date: Sun, 25 Jan 2009 03:56:25 -0800 Subject: [erlang-questions] Can Erlang messages be delivered out of order? In-Reply-To: <497BD73D.5050708@softjar.se> References: <497BD73D.5050708@softjar.se> Message-ID: Hello. > If you read the manual, you'll find that each process have it's own receive > queue, and that new messages are always placed at the end of that queue. > So, for you example, yes. Thanks. I didn't know how message passing is implemented. It got away from me, while I was reading docs on that. > However, your example program don't work the way you seem to expect anyway. > So, even if the messages would have been pleced in the wrong order, your program would have worked just as fine. Those receive-statements were supposed to illustrate the order in which I expect messages will be delivered. But you are right in that program will receive all the message independent from the order. So it was not very good example to illustrate what I expect =) -- Sergey From richardc@REDACTED Sun Jan 25 14:41:45 2009 From: richardc@REDACTED (Richard Carlsson) Date: Sun, 25 Jan 2009 14:41:45 +0100 Subject: [erlang-questions] Structuring an Eunit Suite In-Reply-To: <269388e30901140711q244c1becjc02713279574bf16@mail.gmail.com> References: <269388e30901140711q244c1becjc02713279574bf16@mail.gmail.com> Message-ID: <497C6C19.4060804@it.uu.se> Ben Hood wrote: > I have a suite of tests that each connect to a message server and > execute a number of commands. > > I want to be able to parameterize where the connection supplied from, > so that I can re-use the tests on different transports. > > What I've got now is a suite that looks like this: > > foo_test() -> > test_util:foo_test(new_connection()). > ...... > > new_connection() -> > %% returns a specific connection to the server > > ...... > > and all of the real tests are in the test_util module, e.g: > > foo_test(Connection) -> > %% assert something > > Ideally I would like eunit to do something like > > "foreach _test function in the test_util module, create a new > connection and pass it as a function argument" Sorry, but I forgot to reply to this question. Here's a sketch for doing this sort of thing: foo_test_() -> {setup, fun new_connection/0, fun close_connection/1, {with, [fun test_util:foo_test/1, fun test_util:bar_test/1, fun test_util:baz_test/1 ]} }. The drawback being that you need to manually list the "abstract test functions" (tests that need an argument) within the {with, List} tuple. I should perhaps add some sort of utility function to eunit for enumerating functions in general, based on regexps... /Richard From vychodil.hynek@REDACTED Sun Jan 25 14:45:51 2009 From: vychodil.hynek@REDACTED (Hynek Vychodil) Date: Sun, 25 Jan 2009 14:45:51 +0100 Subject: [erlang-questions] Can Erlang messages be delivered out of order? In-Reply-To: References: <497BD73D.5050708@softjar.se> Message-ID: <20090125134552.0853424013@relay.gooddata.com> On Sun, Jan 25, 2009 at 12:56 PM, Sergey S wrote: > Hello. > > > If you read the manual, you'll find that each process have it's own > receive > > queue, and that new messages are always placed at the end of that queue. > > So, for you example, yes. > > Thanks. I didn't know how message passing is implemented. It got away > from me, while I was reading docs on that. > > > However, your example program don't work the way you seem to expect > anyway. > > > So, even if the messages would have been pleced in the wrong order, your > program would have worked just as fine. > > Those receive-statements were supposed to illustrate the order in > which I expect messages will be delivered. But you are right in that > program will receive all the message independent from the order. So it > was not very good example to illustrate what I expect =) > > -- > Sergey > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > If you want test it, here is example of testing module code: -module(messageorder). -export([test/0]). test() -> process_flag(trap_exit, true), Parent = self(), flush(), Pid = spawn_link(fun() -> Parent ! hello, Parent ! world end), receive X -> hello = X end, receive Y -> world = Y end, receive Z -> {'EXIT', Pid, normal} = Z end, ok. flush() -> receive _ -> flush() after 0 -> ok end. -- --Hynek (Pichi) Vychodil Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero! Try Good Data now for free: www.gooddata.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rvirding@REDACTED Sun Jan 25 16:01:32 2009 From: rvirding@REDACTED (Robert Virding) Date: Sun, 25 Jan 2009 16:01:32 +0100 Subject: [erlang-questions] Can Erlang messages be delivered out of order? In-Reply-To: References: <497BD73D.5050708@softjar.se> Message-ID: <3dbc6d1c0901250701w76c910dahf6aaeccb73bccbc4@mail.gmail.com> 2009/1/25 Sergey S > Hello. > > > If you read the manual, you'll find that each process have it's own > receive > > queue, and that new messages are always placed at the end of that queue. > > So, for you example, yes. > > Thanks. I didn't know how message passing is implemented. It got away > from me, while I was reading docs on that. > > > However, your example program don't work the way you seem to expect > anyway. > > > So, even if the messages would have been pleced in the wrong order, your > program would have worked just as fine. > > Those receive-statements were supposed to illustrate the order in > which I expect messages will be delivered. But you are right in that > program will receive all the message independent from the order. So it > was not very good example to illustrate what I expect =) Strictly speaking, what erlang guarantees is that if the messages sent from one process arrive at the destination process then they will arrive in the order in which they were sent. This is a weaker definition but one which is reasonable to implement and guarantee in a distributed system. For local processes you can safely assume all messages arrive at the destination. This says nothing about how messages from different processes are interleaved with one another in the destination process, but you can safely assume that they will be received in the order in which they *arrive*. Or at least close to that order. It is not safe to assume that this corresponds in the time order in which they were sent as they may take differently to long to get there. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From ad.sergey@REDACTED Sun Jan 25 17:06:54 2009 From: ad.sergey@REDACTED (Sergey S) Date: Sun, 25 Jan 2009 08:06:54 -0800 Subject: [erlang-questions] Can Erlang messages be delivered out of order? In-Reply-To: <3dbc6d1c0901250701w76c910dahf6aaeccb73bccbc4@mail.gmail.com> References: <497BD73D.5050708@softjar.se> <3dbc6d1c0901250701w76c910dahf6aaeccb73bccbc4@mail.gmail.com> Message-ID: Hello. > Strictly speaking, what erlang guarantees is that if the messages sent from > one process arrive at the destination process then they will arrive in the > order in which they were sent. Thanks! That is what I was looking for! =) -- Sergey From ad.sergey@REDACTED Sun Jan 25 17:06:58 2009 From: ad.sergey@REDACTED (Sergey S) Date: Sun, 25 Jan 2009 08:06:58 -0800 Subject: [erlang-questions] Can Erlang messages be delivered out of order? In-Reply-To: <20090125134552.1230524065@relay.gooddata.com> References: <497BD73D.5050708@softjar.se> <20090125134552.1230524065@relay.gooddata.com> Message-ID: Hello. > If you want test it, here is example of testing module code: Thanks for your answer. But some hours ago I was trying to use a similar tests to ensure that there is no possibility of "out of order" delivery. I think tests like that are useful, but don't make you actually sure that results you've taken will always be the same (i.e. with a probability of 100%). * Suppose that we haven't read how message passing is implemented and what Erlang runtime does guarantee * First message has more probability to be delivered first, just because it was sent earlier. Using the same argument we can explain why the second message was delivered before third one in our test. There is only one way to ensure - know what runtime system does guarantee about that. -- Sergey From wglozer@REDACTED Sun Jan 25 19:04:29 2009 From: wglozer@REDACTED (Will) Date: Sun, 25 Jan 2009 10:04:29 -0800 Subject: [erlang-questions] announce: epgsql-1.0 Message-ID: Hello, I've released version 1.0 of epgsql, a pure Erlang database driver for PostgreSQL. The code can be found in mercurial repositories at: http://glozer.net/src/epgsql http://bitbucket.org/will/epgsql Aside from bug fixes, recent changes include representing all date/time types as tuples and support for the 'returning' clause. Details can be found in the README file. http://glozer.net/src/epgsql/README -Will -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthias@REDACTED Sun Jan 25 21:46:00 2009 From: matthias@REDACTED (Matthias Lang) Date: Sun, 25 Jan 2009 21:46:00 +0100 Subject: [erlang-questions] i got "command not found" when make install In-Reply-To: <21a6acd40901250112j4726f9cld3e4428a536064f5@mail.gmail.com> References: <21a6acd40901250112j4726f9cld3e4428a536064f5@mail.gmail.com> Message-ID: <20090125204600.GA3640@contorpis.lisalinda.com> On Sunday, January 25, Voaneos wrote: > hi all > > i got no error when 'configure', > but error when make install The symptoms you posted are consistent with skipping step 5, i.e. 'make', in the instructions in the README file. Matt > make[5]: Leaving directory `/root/backup/otp_src_R12B-5/erts/lib_src' > make[4]: Leaving directory `/root/backup/otp_src_R12B-5/erts/lib_src' > make[3]: Leaving directory `/root/backup/otp_src_R12B-5/erts/lib_src' > make[2]: Leaving directory `/root/backup/otp_src_R12B-5/erts/lib_src' > make[2]: Entering directory `/root/backup/otp_src_R12B-5/erts/start_scripts' > make -w RELEASE_PATH=/usr/local/lib/erlang release_spec > make[3]: Entering directory `/root/backup/otp_src_R12B-5/erts/start_scripts' > /usr/bin/install -c -d /root/backup/otp_src_R12B-5/erts/start_scripts/tmp > ( cd /root/backup/otp_src_R12B-5/erts/start_scripts/tmp && \ > erlc -W -I/root/backup/otp_src_R12B-5/lib/kernel/ebin > -I/root/backup/otp_src_R12B-5/lib/stdlib/ebin > -I/root/backup/otp_src_R12B-5/lib/sasl/ebin -o > /root/backup/otp_src_R12B-5/erts/start_scripts/start_clean.script > /root/backup/otp_src_R12B-5/erts/start_scripts/start_clean.rel ) > /bin/sh: line 1: erlc: command not found > make[3]: *** > [/root/backup/otp_src_R12B-5/erts/start_scripts/start_clean.script] Error > 127 > make[3]: Leaving directory `/root/backup/otp_src_R12B-5/erts/start_scripts' > make[2]: *** [release] Error 2 > make[2]: Leaving directory `/root/backup/otp_src_R12B-5/erts/start_scripts' > make[1]: *** [release] Error 2 > make[1]: Leaving directory `/root/backup/otp_src_R12B-5/erts' > make: *** [install.emulator] Error 2 > [root@REDACTED otp_src_R12B-5]# > > > > my os > > Linux fscbx 2.6.18-53.el5 #1 SMP Mon Nov 12 02:22:48 EST 2007 i686 i686 i386 > GNU/Linux > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From steven.charles.davis@REDACTED Sun Jan 25 22:05:29 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Sun, 25 Jan 2009 13:05:29 -0800 (PST) Subject: [erlang-questions] Can Erlang messages be delivered out of order? In-Reply-To: <3dbc6d1c0901250701w76c910dahf6aaeccb73bccbc4@mail.gmail.com> References: <497BD73D.5050708@softjar.se> <3dbc6d1c0901250701w76c910dahf6aaeccb73bccbc4@mail.gmail.com> Message-ID: <89bc1d8c-47c9-4193-a380-d15dded1c177@r41g2000prr.googlegroups.com> This is actually a greater guarantee than I expected. Very useful to know. Thanks, Robert (and thanks to Sergey for asking the question too!) /s On Jan 25, 9:01?am, Robert Virding wrote: > Strictly speaking, what erlang guarantees is that if the messages sent from > one process arrive at the destination process then they will arrive in the > order in which they were sent. This is a weaker definition but one which is > reasonable to implement and guarantee in a distributed system. For local > processes you can safely assume all messages arrive at the destination. From norbu09@REDACTED Sun Jan 25 22:42:00 2009 From: norbu09@REDACTED (lenz) Date: Mon, 26 Jan 2009 10:42:00 +1300 Subject: [erlang-questions] first erlounge wellington Message-ID: erloungers, It is only some more days to go till the first erlounge in wellington and as far as i know the first one in the southern hemisphere. Most probably you get this message via various channels and i apologize for it but getting the message out and spreading the word is key to reach all those who might be interested. Any agenda? Well, I'll give a short intro to erlang itself and would develop a small mochiweb application with a CouchDB backend during the evening. nothing too big, just to give you an impression of what erlang can do and how you play with CouchDB a bit. If you are interested in either one or both or if you want to present something to the rest of us, feel free to come along. If you are just interested to meet with other geeks, early adopters, functional programmers, startup guys, established telco programmers ... come along. We try to make this a place for information exchange besides the established languages and for interesting new takes on obvious challenges. When: 3rd of February 6 PM Where: AltSpace (http://altspace.co.nz/) more info: http://groups.google.com/group/erlounge-wellington cheers lenz -- iWantMyName.com painless domain registration (finally) -------------- next part -------------- An HTML attachment was scrubbed... URL: From enrico.thierbach@REDACTED Sun Jan 25 22:49:39 2009 From: enrico.thierbach@REDACTED (Enrico Thierbach) Date: Sun, 25 Jan 2009 22:49:39 +0100 Subject: [erlang-questions] EEP0018/native JSON parsing Message-ID: Hi guys, I have just finished what I would call the first stage of the native JSON parser implementation. This is the state as of now at http://github.com/pboy/eep0018/, Please see the readme file. In short, this is the status: - I parse everything that comes along like mochijson2 and rabbitmq - optionally I can parse according to eep0018 - my code runs 6 times as fast as mochijson2/rabbitmq at JSON input of a certain size, and is usally not slower on very small JSON input. jan tried the module along with couchdb, and find one issue regarding UTF8 characters; besides of that everything seemed to run fine and much faster. The utf8 parsing issue is resolved (or better: worked around: the JSON parser and the CouchDB tests have different ideas on what is valid UTF8). What would be next? 1. I would like to invite you all to review and try the code. 2. I need some hints regarding "parallel execution". The native driver does not support multithreading (and why should it? It only complicates things where OTP can do that kind of stuff by itself already.) With the current code the driver gets loaded only once. Therefore on a multicore machine only one CPU gets really used. Is it somehow possible to load the driver multiple times? The only way I see so far is having the driver compiled and installed multiple times with different names; but I guess there is a better way. The code itself should luckily run in a parallel situation. 3. and finally I'll have to tackle the Erlang->JSON issue. I don't expect a speedup as big. Please see my next mail for some comments on EEP0018. /eno ==================================================================== A wee piece of ruby every monday: http://1rad.wordpress.com/ From enrico.thierbach@REDACTED Sun Jan 25 22:55:11 2009 From: enrico.thierbach@REDACTED (Enrico Thierbach) Date: Sun, 25 Jan 2009 22:55:11 +0100 Subject: [erlang-questions] EEP0018, some remarks Message-ID: hi list, whilst working on a native eep0018 implementation ( http://github.com/pboy/eep0018) I came across some problems with EEP0018. The following is an excerpt from my README file, that states these issues: ============================================================================================ json_to_term/2 Options - Differences to EEP 18 ============================================== EEP0018 states | The {float,true} option says to convert all JSON numbers to | Erlang floats, even if they look like integers. | With this option, the result has type json(L, float()). | | The {float,false} option says to convert integers to integers; | it is the default. | With this option, the result has type json(L, number()). | | The {label,binary} option says to convert all JSON strings | to Erlang binaries, even if they are keys in key:value pairs. | With this option, the result has type json(binary(), N). | This is the default. | | The {label,atom} option says to convert keys to atoms if | possible, leaving other strings as binaries. | With this option, the result has type json(json_label(), N). | | The {label,existing_atom} option says to convert keys to | atoms if the atoms already exist, leaving other keys as | binaries. All other strings remain binaries too. | With this option, the result has type json(json_label(), N). Instead of that we implement the following options {parse,object}(*) ...... Parse only Erlang objects and arrays, i.e. parsing "123" would fail. {parse,value} Parse all Erlang values, i.e. parsing "123" would succeed. {objects,eep0018} ... (*) JSON objects will be mapped as laid out in EEP0018, i.e. {} -> [{}] {"a":"b","c":"d"} -> [{<<"a">>,<<"b">>},{<<"c">>,<<"d">>}] {objects,compat} JSON objects will be mapped as in some other implementations, i.e. {} -> {[]} {"a":"b","c":"d"} -> {[{<<"a">>,<<"b">>},{<<"c">>,<<"d">>}]} {labels,binary} ... (*) Labels will be mapped as binaries, i.e. {"a":"b","c":"d"} -> {[{<<"a">>,<<"b">>},{<<"c">>,<<"d">>}]} {labels,atom} Labels will be mapped as binaries, i.e. {"a":"b","c":"d"} -> {[{a,<<"b">>},{c,<<"d">>}]} Use this option only if you know that there is a limited range of possible labels and that these labels can be converted to atoms. The {labels,existing_atom} option is not implemented, because a) it runs quite slow, and b) the result of such an operation is unpredictable. {number,exact} ... (*) Numbers are parsed exactly as they are in the JSON source code, i.e. a JSON integer will be mapped as an Erlang integer, and a JSON float will be mapped as an Erlang float, in the precision supported by the current OTP runtime. {number,number} Numbers are parsed exactly as they are in the JSON source code, i.e. a JSON integer will be mapped as an Erlang integer, and a JSON float will be mapped as an Erlang float, in the precision supported by the C runtime and ei libraries, eg. signed 32-bit for integers and 64 bit floating points. {number,float} All numbers are parsed as an Erlang float, in the precision supported by the C runtime (eg. 64 bit). Performance considerations ========================== Some of these options have a huge performance impact, as they are implemented on the Erlang side and so require a two-step parsing process (one round in the driver and one extra round in Erlang): * {number,exact} is implemented by transmitting the number value as a string * {objects,compat} is currently implemented in Erlang. A final implementation - after everyone agreed upon the Erlang mapping of JSON objects, would of course be done in C. ============================================================================================ /eno -- ==================================================================== A wee piece of ruby every monday: http://1rad.wordpress.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From vik@REDACTED Sun Jan 25 22:16:42 2009 From: vik@REDACTED (Vik Olliver) Date: Mon, 26 Jan 2009 10:16:42 +1300 Subject: [erlang-questions] Can Erlang messages be delivered out of order? In-Reply-To: <89bc1d8c-47c9-4193-a380-d15dded1c177@r41g2000prr.googlegroups.com> References: <497BD73D.5050708@softjar.se> <3dbc6d1c0901250701w76c910dahf6aaeccb73bccbc4@mail.gmail.com> <89bc1d8c-47c9-4193-a380-d15dded1c177@r41g2000prr.googlegroups.com> Message-ID: <497CD6BA.2030206@catalyst.net.nz> Even if there is a line glitch and retry on one of the messages? Just making sure here... Vik :v) On 26/01/09 Steve Davis wrote: > This is actually a greater guarantee than I expected. Very useful to > know. > > Thanks, Robert > (and thanks to Sergey for asking the question too!) > > /s > > On Jan 25, 9:01 am, Robert Virding wrote: > > > Strictly speaking, what erlang guarantees is that if the messages > sent from > > > one process arrive at the destination process then they will > arrive in the > > > order in which they were sent. This is a weaker definition but > one which is > > > reasonable to implement and guarantee in a distributed system. > For local > > > processes you can safely assume all messages arrive at the > destination. > From ok@REDACTED Mon Jan 26 04:50:13 2009 From: ok@REDACTED (Richard O'Keefe) Date: Mon, 26 Jan 2009 16:50:13 +1300 Subject: [erlang-questions] The If expression In-Reply-To: References: <3A9F40FC-0F61-4327-905D-B9331AF83D8C@cs.otago.ac.nz> Message-ID: <9057455C-61FE-485E-9079-3D669B8A6103@cs.otago.ac.nz> On 24 Jan 2009, at 11:35 am, Fredrik Svahn wrote: >> - 'if' isn't actually all that rare. In some code I wrote last >> year, I find one 'if' for every four 'case's. The OTP sources >> have 1 if/10 case, which is less common, but not _that_ rare. >> If the old sense of 'if' were rare, we could probably live with >> the confusion. > > Newcomers to this mailing list asking how to use "if" are invariably > recommended to use "case" instead. Combined with the fact that you can > only use guards it is almost FAQ material. Considering this and all > the beating the 'if' expression has gotten over the years on the > mailing list my assumption was that the use of 'if' was really rather > infrequent even outside of OTP. I might be wrong. > > (Hmmm, I just checked, and there actually is a chapter about 'if':s in > the FAQ. It is recommending the use of 'case' and even states that > "case is used much more frequently"). Ten to one *is* "much more frequently". However, one in ten is not a negligible proportion. > Just out of curiosity, is there any other programming language out > there which has an 'if' and which does not have an 'else' apart from > the Commodore 64 BASIC? I am not saying Erlang should have because > everyone else does. I am just wondering out of curiosity. Dijkstra's notation, Promela, classic Lisp (to this day, if you want an "else" in a COND, you have to use the equivalent of "; true ->"), Occam. - As a result the new syntax is rather inconvenient. The majority > >> of my existing uses of 'if' have more than one arm, so would need >> nested new-'if's. It's hard to see that as an improvement. > > The proposal is backwards compatible (with the obvious exception that > 'else' would need to become a keyword) so there is no need for you to > change your coding style. That much was obvious. My point is that common things like if X < Y -> a() ; X > Y -> b() ; X ==Y -> c() end have to be rewritten as if X < Y -> a() else if Y > Y -> b() else c() end end so there isn't much *point* in changing coding style either. > > There is a lot of code out there to critically review, then. Yes, there is. In fact, looking for 'true' and 'false' is a good way to find code that could be clearer. > In fact > 'true' is the second most popular atom in the OTP code, and 'false' is > the fourth most popular. No dispute there. Oh, that it were not so! > > What else can it really be used for? Ok, there are a couple of guard > bifs, but that is basically it, isn't it? Type tests. From jan@REDACTED Mon Jan 26 10:11:39 2009 From: jan@REDACTED (Jan Lehnardt) Date: Mon, 26 Jan 2009 10:11:39 +0100 Subject: [erlang-questions] EEP0018/native JSON parsing In-Reply-To: References: Message-ID: <9065117F-FCD9-4146-A0BC-E7C0B1B760E5@apache.org> On 26 Jan 2009, at 01:24, Paul Davis wrote: > After a bit of pestering from Jan, I broke down and tested the two > versions side by side. The code for both versions are in my github > repo. Also, disregard the errors on eno's test runs. He's using a > different number format than is expected so nearly all the tests fail. The number tests fail since Enrico maintains bignum precision on the C-end. Which none of the existing JSON libs do, but is rather neat, but you (the Erlang experts) would know if we need that. Cheers Jan -- > Anyway, numbers: > > davis2318:/usr/local/src/eep0018 davisp$ git branch > eno > * master > pjd > sax > davis2318:/usr/local/src/eep0018 davisp$ make check > for d in src tests; do (cd $d; make); done > > [snip] > > for d in src tests; do (cd $d; make check); done > cp ../src/*.so ./ > cp ../src/*.beam ./ > erl -noshell -s runner main > single_proc => eep0018: 0.417 s [success] > multi_proc => eep0018: 1.396 s [success] > single_proc => mochijson2: 3.191 s [success] > multi_proc => mochijson2: 9.915 s [success] > single_proc => rabbitmq: 2.904 s [success] > multi_proc => rabbitmq: 9.510 s [success] > davis2318:/usr/local/src/eep0018 davisp$ git checkout eno > Switched to branch "eno" > davis2318:/usr/local/src/eep0018 davisp$ make clean && make check > for d in src tests; do (cd $d; make clean); done > rm -f *.o *.beam eep0018_drv.so > rm -f *.so *.beam > for d in src tests; do (cd $d; make); done > > [snip] > > for d in src tests; do (cd $d; make check); done > cp ../src/*.so ./ > cp ../src/*.beam ./ > erl -noshell -s runner main > single_proc => eep0018: 0.698 s [failure] > 19 decoding errors. > 19 round trip errors. > multi_proc => eep0018: 3.197 s [failure] > 95 decoding errors. > 95 round trip errors. > single_proc => mochijson2: 3.161 s [success] > multi_proc => mochijson2: 9.895 s [success] > single_proc => rabbitmq: 3.008 s [success] > multi_proc => rabbitmq: 10.090 s [success] > > On Sun, Jan 25, 2009 at 4:49 PM, Enrico Thierbach > wrote: >> Hi guys, >> >> I have just finished what I would call the first stage of the native >> JSON parser implementation. This is the state as of now at >> http://github.com/pboy/eep0018/, Please see the readme file. >> >> In short, this is the status: >> >> - I parse everything that comes along like mochijson2 and rabbitmq >> - optionally I can parse according to eep0018 >> - my code runs 6 times as fast as mochijson2/rabbitmq at JSON input >> of a certain size, and is usally not slower on very small JSON input. >> >> jan tried the module along with couchdb, and find one issue regarding >> UTF8 characters; besides of that everything seemed to run fine and >> much faster. The utf8 parsing issue is resolved (or better: worked >> around: the JSON parser and the CouchDB tests have different ideas on >> what is valid UTF8). >> >> What would be next? >> >> 1. I would like to invite you all to review and try the code. >> >> 2. I need some hints regarding "parallel execution". The native >> driver >> does not support multithreading (and why should it? It only >> complicates things where OTP can do that kind of stuff by itself >> already.) With the current code the driver gets loaded only once. >> Therefore on a multicore machine only one CPU gets really used. Is it >> somehow possible to load the driver multiple times? The only way I >> see >> so far is having the driver compiled and installed multiple times >> with >> different names; but I guess there is a better way. The code itself >> should luckily run in a parallel situation. >> >> 3. and finally I'll have to tackle the Erlang->JSON issue. I don't >> expect a speedup as big. >> >> Please see my next mail for some comments on EEP0018. >> >> /eno >> >> ==================================================================== >> A wee piece of ruby every monday: http://1rad.wordpress.com/ >> > From twoggle@REDACTED Mon Jan 26 12:57:11 2009 From: twoggle@REDACTED (Tim Fletcher) Date: Mon, 26 Jan 2009 03:57:11 -0800 (PST) Subject: [erlang-questions] idea: include percent encoding functions in stdlib Message-ID: <4bb422e5-c50d-4e39-a7b7-67c9c362b469@y23g2000pre.googlegroups.com> As far as i can tell there are no routines in the standard library for percent encoding/decoding (aka URL/URI encoding/decoding). There would appear to be two encodings that are useful: 1) RFC 3986 (the current URI spec) 2) application/x-www-form-urlencoded (as per RFC 1738, except for that space characters are replaced by '+') There are numerous existing Erlang implementations already in use, including mochiweb_util, yaws_api, ibrowse_lib, and oauth_uri (disclaimer: i wrote the last one). There are others (such as erlydtl and smak) which appear to be based on the mochiweb code. >From my testing, neither mochiweb_util or yaws_api implement either of the above encodings correctly, ibrowse_lib correctly implements the second encoding, oauth_uri correctly implements the first encoding, and ibrowse is faster than all the other implementations. Code is available to view/download here: http://github.com/tim/erlang-percent-encoding This includes the four existing implementations above, plus an additional implementation based on ibrowse_lib which implements both encodings. I would be grateful for any feedback on this. Does such a proposal warrant an EEP? Are my tests correct? Any other thoughts? From ad.sergey@REDACTED Mon Jan 26 21:42:25 2009 From: ad.sergey@REDACTED (Sergey S) Date: Mon, 26 Jan 2009 12:42:25 -0800 Subject: [erlang-questions] How to get binaries when using {packet, http} In-Reply-To: <49773B16.9000607@erix.ericsson.se> References: <4975A6E7.10509@erix.ericsson.se> <4976F0D7.1030106@erlang-consulting.com> <49773B16.9000607@erix.ericsson.se> Message-ID: Hello. > Yes, you are right. Which means that if binary strings are introduced in > http-packets it will most probably be done with some other option, like > {packet, http_bin}. Thanks for your answer. In other words nobody knows for sure when it will be, if ever, implemented. But nothing prevents to hope that support of http_bin will be introduced during R13 life =) Anyway... People who want to get binaries from standard http-decoder can use [{packet, raw}, binary] along with erlang:decode_packet/3 to decode a binary. -- Sergey From ad.sergey@REDACTED Mon Jan 26 23:47:52 2009 From: ad.sergey@REDACTED (Sergey S) Date: Mon, 26 Jan 2009 14:47:52 -0800 Subject: [erlang-questions] A couple of questions about constructing and matching binaries Message-ID: Hello. The following questions arose while I was reading Efficiency Guide / 4 Constructing and matching binaries: #1 Please, take a look at the following quote (from 4.2 Constructing binaries): -----------------8<--------------- Bin0 = <<0>>, %% 1 Bin1 = <>, %% 2 %% Lines 3 to 6 have been skippped "The first line (marked with the %% 1 comment), assigns a heap binary to the variable Bin0. The second line is an append operation. Since Bin0 has not been involved in an append operation, >>> a new refc binary will be created <<< and the contents of Bin0 will be copied into it." ----------------->8--------------- Why has Bin1 become reference-counted binary, not the heap one? It's still too small (smaller than 64 bytes) to be stored outside of the heap. I don't understand why "Since Bin0 has not been involved in an append operation" is the reason of moving the binary to the storage of refc binaries :/ #2 Here is another quote, which is also not so clear to me: -----------------8<--------------- The optimization of the binary append operation requires that there is a single ProcBin and a single reference to the ProcBin for the binary. ----------------->8--------------- What does "reference to the ProcBin" mean? For example we have code like this: Bin1 = Bin2 = Bin3 = list_to_binary(lists:duplicate(128, $A)) Has that code created three ProcBins (Bin1, Bin2 and Bin3) or there is only one ProcBin and three references to it? Thanks. -- Sergey From chris.newcombe@REDACTED Tue Jan 27 02:52:43 2009 From: chris.newcombe@REDACTED (Chris Newcombe) Date: Mon, 26 Jan 2009 17:52:43 -0800 Subject: [erlang-questions] EEP0018/native JSON parsing In-Reply-To: References: Message-ID: <781dd98c0901261752w18c32fb9s84e411b1b2e99b09@mail.gmail.com> Hi Enrico, I'm looking for a faster JSON parser too, and was about to tackle this, so thanks for sharing your work. (I found that Erlang, even with +native compilation, takes ~800 millsecs to parse a 1MB JSON document, where as perl JSON:XS (in C) takes 5 milliseconds for the same data. The reverse encoding is just as bad.) I haven't tried your code yet, but I did glance briefly at it: I noticed a couple of things that I suspect are bottlenecks: - the code using the 'output()' callback in the driver entry structure to receive the input JSON document. That means that Erlang is having to copy the input. - the code returns the encoded result via driver_output2() (rather than driver_output_binary or driver_outputv). This means that the encoded response is being copied. - the code generates the result Erlang term via ei_x_encode*. This copies the string data, and also encodes it to Erlang's external-term format (which is rather similar to a binary form of JSON). The Erlang side then has to decode from the external-term format via (and erlang:binary_to_term on the receiving end). I think it is possible to avoid all of these, and hopefully achieve JSON:XS-level speed mentioned above. e.g. 1. Use outputv() to receive the input JSON document as one large binary (no copying). e.g. If the data was received via gen_tcp socket in binary mode, only small binary header pointing to the data would be sent to the driver. 2. Parse with yaj, and generate the result term with the little term-construction language definef for driver_output_term() see http://www.erlang.org/doc/man/erl_driver.html#driver_output_term In particular, using ERL_DRV_BINARY strings (keys and values) can be sub-binaries of the original input-binary, so there is no copying. 3. Send the result back to Erlang via driver_send_term or driver_output_term. This directly transfers ownership of the constructed term to the VM, so there is a) no copying, of either the term structure, or the key/value strings (which are still sub-binaries of the larger input binary) and b) no encoding or decoding through an intermediate format (i.e. no use of the external term format) 5. Use EDTK for all of the boilerplate. This implements the above outputv / driver_send_term mechanism, but with one current problem. Currently the size of the result term is very limited (it's only been used for sending small results). I would need to make that dynamic. (This is the main reason I haven't done it yet -- might require some surgery). One consequence of making sub-binaries of the larger input binary is that the larger input binary cannot be garbage-collected until every key and value sub-binary has been destroyed. That may cause excessive memory usage in some scenarios. So I'm planning on implementing an option to create copies for keys and/or values. However, that only causes 1 copy, as step (3) can still transfer the new binaries back to Erlang without copying the data. However, I'm not sure when I'll get to tackle this -- perhaps in the next few weeks, but it might be further out than that. >> . I need some hints regarding "parallel execution". >> The native driver does not support multithreading (and why should it? It only >> complicates things where OTP can do that kind of stuff by itself >> already.) This very much depends. Erlang 'multithreading' is at the Erlang process-level only (i.e. Erlang has its own process scheduler). If Erlang calls a driver, then by default the OS thread running the erlang process scheduler is blocked until the driver returns. That's fine for short operations, but e.g. if parsing a really huge JSON object, you don't want to block the Erlang scheduler for tens/hundreds of milliseconds (literally the entire VM is stalled, or part of the VM in SMP mode, when there are multiple scheduler OS threads). Drivers can use driver_async() to run work in a separate thread-pool, to avoid blocking the scheduler. However, other Erlang drivers use that thread pool for significant slow tasks, e.g. file IO. EDTK implements private thread-pools to work around that problem. My plan was to test the size of the input JSON document and do a blocking operation if it is small (say a < 100KB) and a threadpool operation otherwise. >>With the current code the driver gets loaded only once. That's fine. >>Therefore on a multicore machine only one CPU gets really used. If you are not running Erlang in SMP mode then it will only use a single CPU for driver operations unless you use the driver_async() feature or private threadpools like EDTK. If you are running in SMP mode with more than one scheduler OS thread, then the level of driver concurrency depends on the 'locking mode' for the driver. By default conservative 'driver-level' locking is used, as many drivers were written before SMP was implemented and are not thread-safe. However, if your driver is thread-safe then you can easily switch to port-level locking, and if multiple Erlang processes each have their own open port using the driver, then Erlang scheduler threads can call the driver simultaneously. However, if you do this you still need to worry about the effects of blocking the Erlang VM schedulers for any significant amount of time. That's why private threadpools are still important. From http://www.erlang.org/doc/man/erl_driver.html "In the runtime system with SMP support, drivers are locked either on driver level or port level (driver instance level). By default driver level locking will be used, i.e., only one emulator thread will execute code in the driver at a time. If port level locking is used, multiple emulator threads may execute code in the driver at the same time. There will only be one thread at a time calling driver call-backs corresponding to the same port, though. In order to enable port level locking set the ERL_DRV_FLAG_USE_PORT_LOCKING driver flagin the driver_entry used by the driver. When port level locking is used it is the responsibility of the driver writer to synchronize all accesses to data shared by the ports (driver instances)." I hope this helps, Chris On Sun, Jan 25, 2009 at 1:49 PM, Enrico Thierbach < enrico.thierbach@REDACTED> wrote: > Hi guys, > > I have just finished what I would call the first stage of the native > JSON parser implementation. This is the state as of now at > http://github.com/pboy/eep0018/, Please see the readme file. > > In short, this is the status: > > - I parse everything that comes along like mochijson2 and rabbitmq > - optionally I can parse according to eep0018 > - my code runs 6 times as fast as mochijson2/rabbitmq at JSON input > of a certain size, and is usally not slower on very small JSON input. > > jan tried the module along with couchdb, and find one issue regarding > UTF8 characters; besides of that everything seemed to run fine and > much faster. The utf8 parsing issue is resolved (or better: worked > around: the JSON parser and the CouchDB tests have different ideas on > what is valid UTF8). > > What would be next? > > 1. I would like to invite you all to review and try the code. > > 2. I need some hints regarding "parallel execution". The native driver > does not support multithreading (and why should it? It only > complicates things where OTP can do that kind of stuff by itself > already.) With the current code the driver gets loaded only once. > Therefore on a multicore machine only one CPU gets really used. Is it > somehow possible to load the driver multiple times? The only way I see > so far is having the driver compiled and installed multiple times with > different names; but I guess there is a better way. The code itself > should luckily run in a parallel situation. > > 3. and finally I'll have to tackle the Erlang->JSON issue. I don't > expect a speedup as big. > > Please see my next mail for some comments on EEP0018. > > /eno > > ==================================================================== > A wee piece of ruby every monday: http://1rad.wordpress.com/ > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris.newcombe@REDACTED Tue Jan 27 04:36:34 2009 From: chris.newcombe@REDACTED (Chris Newcombe) Date: Mon, 26 Jan 2009 19:36:34 -0800 Subject: [erlang-questions] EEP0018/native JSON parsing In-Reply-To: References: <781dd98c0901261752w18c32fb9s84e411b1b2e99b09@mail.gmail.com> Message-ID: <781dd98c0901261936h7274089ar21945fe3cadcd33d@mail.gmail.com> >>It appears that you looked at eno's version of the parser. Yes. Sorry, I didn't see your email. In fact, I still don't see it, only the reply from Jan Lehnardt. Did you cc the list? >>I've implemented some of these suggestions and get a bit of a speed increase. Cool. I notice the numbers in Jan's email. My reference baseline is JSON:XS. http://search.cpan.org/dist/JSON-XS/ It would be interesting to compare performance with that. I'll do that. Please can you send me a link to your code? >>1. use the control callback Interesting. For a very large document that's presumably going block the VM, but for small documents it might well be the fastest. If that's true, the Erlang side should check the input document size and choose the communication mechanism accordingly. >>2, I actually hacked yajl a bit to decode utf-8 data into the same buffer it's reading from specifically to avoid any memcpy stuff. The downside is that this destroys the original binary term. I wonder if that is safe on the data you get from control(). The docs don't seem to say. The pointer is a char* not a const char*, but that might simply be oversight. >>With some more hacking on yajl, it's possible that we could change around the original unicode buffer stuff to decode all unicode strings into a single buffer and then reference that buffer etc. Yes you could allocate a single driver binary of conservative size, incrementally fill it with data (using sub-binary references in the constructed term) and then realloc the binary to the final size (if it is too large) at the end. Good idea. I thought I read somewhere that Yajl will only copy strings that have unicode characters, so this method would presumably only copy those strings. All ascii/latin1 strings (most I would imagine) wouldn't need to be copied (if outputv were used). If that doesn't get performance close to JSON:XS then it might be worth ditching Yajl and adapting the C portion of JSON:XS. (Fortunately Perl internally works with unicode strings as utf8, so even the unicode part should be directly applicable). However, I haven't yet looked at the JSON:XS implementation at all. >>I hadn't heard of EDTK prior to now, I'll take a look in the near future. It's the Erlang Driver Toolkit. Originally written by Scott Lystig Fritchie. It's a code generator. It allows you to write XML file with a declaration of a C API, and it will generate an Erlang driver for that library, that works in both linked-in and spawned-program modes. A major feature is that it tracks resources allocated by the library, and guarantees correct cleanup (including ordering constraints). Another major feature is the concept of a 'port coordinator', used to allow efficient access to a single port instance if creating one per Erlang process is too expensive (as it is with BerkeleyDB). I enhanced it a quite lot (inc. private threadpools) to implement a production-quality Berkeley DB driver (which also supports replication). EDTK only works on Linux at the moment. Some people made a lot of progress with an OS-X port, but I never heard if it was finished. A Win32 port is feasible, esp. now that R12B exposes portable variants of the pthread primitives, but would be a fair amount of work. The code (and a couple of papers/presenations) is here: http://www.snookles.com/erlang/edtk/ License is BSD. Chris On Mon, Jan 26, 2009 at 6:31 PM, Paul Davis wrote: > On Mon, Jan 26, 2009 at 8:52 PM, Chris Newcombe > wrote: > > Hi Enrico, > > > > I'm looking for a faster JSON parser too, and was about to tackle this, > so > > thanks for sharing your work. (I found that Erlang, even with +native > > compilation, takes ~800 millsecs to parse a 1MB JSON document, where as > perl > > JSON:XS (in C) takes 5 milliseconds for the same data. The reverse > encoding > > is just as bad.) > > > > I haven't tried your code yet, but I did glance briefly at it: > > I noticed a couple of things that I suspect are bottlenecks: > > > > - the code using the 'output()' callback in the driver entry structure > to > > receive the input JSON document. That means that Erlang is having to > copy > > the input. > > - the code returns the encoded result via driver_output2() (rather than > > driver_output_binary or driver_outputv). This means that the encoded > > response is being copied. > > - the code generates the result Erlang term via ei_x_encode*. This > > copies the string data, and also encodes it to Erlang's external-term > format > > (which is rather similar to a binary form of JSON). The Erlang side then > > has to decode from the external-term format via (and > erlang:binary_to_term > > on the receiving end). > > > > It appears that you looked at eno's version of the parser. I've > implemented some of these suggestions and get a bit of a speed > increase. > > My specifics were: > > 1. use the control callback > 2. driver_send_term to send an ErlDrvTermData array back > > > I think it is possible to avoid all of these, and hopefully achieve > > JSON:XS-level speed mentioned above. > > e.g. > > > > 1. Use outputv() to receive the input JSON document as one large binary > > (no copying). e.g. If the data was received via gen_tcp socket in binary > > mode, only small binary header pointing to the data would be sent to the > > driver. > > > > 2. Parse with yaj, and generate the result term with the little > > term-construction language definef for driver_output_term() see > > http://www.erlang.org/doc/man/erl_driver.html#driver_output_term > > In particular, using ERL_DRV_BINARY strings (keys and values) can > be > > sub-binaries of the original input-binary, so there is no copying. > > > > 3. Send the result back to Erlang via driver_send_term or > > driver_output_term. This directly transfers ownership of the > constructed > > term to the VM, so there is > > a) no copying, of either the term structure, or the key/value > > strings (which are still sub-binaries of the larger input binary) > > and b) no encoding or decoding through an intermediate format (i.e. no > use > > of the external term format) > > > > 5. Use EDTK for all of the boilerplate. This implements the above > > outputv / driver_send_term mechanism, but with one current problem. > > Currently the size of the result term is very limited (it's only been > used > > for sending small results). I would need to make that dynamic. (This is > > the main reason I haven't done it yet -- might require some surgery). > > > > I'm pretty sure I'm using all of these with the exception of the > outputv callback. Following along point number 2, I actually hacked > yajl a bit to decode utf-8 data into the same buffer it's reading from > specifically to avoid any memcpy stuff. The downside is that this > destroys the original binary term. > > The way I read your explanation, this means that I'm not actually > destroying the binary that erlang is using so this would be ok but at > the cost of making the large memcpy in the erlang VM. With some more > hacking on yajl, it's possible that we could change around the > original unicode buffer stuff to decode all unicode strings into a > single buffer and then reference that buffer etc. > > > > One consequence of making sub-binaries of the larger input binary is that > > the larger input binary cannot be garbage-collected until every key and > > value sub-binary has been destroyed. That may cause excessive memory > usage > > in some scenarios. So I'm planning on implementing an option to create > > copies for keys and/or values. However, that only causes 1 copy, as > step > > (3) can still transfer the new binaries back to Erlang without copying > the > > data. > > > > However, I'm not sure when I'll get to tackle this -- perhaps in the next > > few weeks, but it might be further out than that. > > > > I hadn't heard of EDTK prior to now, I'll take a look in the near future. > > > > >>> . I need some hints regarding "parallel execution". > > > >>> The native driver does not support multithreading (and why should it? > It > >>> only > >>> complicates things where OTP can do that kind of stuff by itself > >>> already.) > > > > This very much depends. Erlang 'multithreading' is at the Erlang > > process-level only (i.e. Erlang has its own process scheduler). If > Erlang > > calls a driver, then by default the OS thread running the erlang process > > scheduler is blocked until the driver returns. > > > > That's fine for short operations, but e.g. if parsing a really huge JSON > > object, you don't want to block the Erlang scheduler for tens/hundreds of > > milliseconds (literally the entire VM is stalled, or part of the VM in > SMP > > mode, when there are multiple scheduler OS threads). > > > > Drivers can use driver_async() to run work in a separate thread-pool, to > > avoid blocking the scheduler. However, other Erlang drivers use that > thread > > pool for significant slow tasks, e.g. file IO. > > > > EDTK implements private thread-pools to work around that problem. My > plan > > was to test the size of the input JSON document and do a blocking > operation > > if it is small (say a < 100KB) and a threadpool operation otherwise. > > > > > >>>With the current code the driver gets loaded only once. > > > > That's fine. > > > > > >>>Therefore on a multicore machine only one CPU gets really used. > > > > If you are not running Erlang in SMP mode then it will only use a single > CPU > > for driver operations unless you use the driver_async() feature or > private > > threadpools like EDTK. > > > > If you are running in SMP mode with more than one scheduler OS thread, > then > > the level of driver concurrency depends on the 'locking mode' for the > > driver. By default conservative 'driver-level' locking is used, as many > > drivers were written before SMP was implemented and are not thread-safe. > > However, if your driver is thread-safe then you can easily switch to > > port-level locking, and if multiple Erlang processes each have their own > > open port using the driver, then Erlang scheduler threads can call the > > driver simultaneously. However, if you do this you still need to worry > > about the effects of blocking the Erlang VM schedulers for any > significant > > amount of time. That's why private threadpools are still important. > > > > From http://www.erlang.org/doc/man/erl_driver.html > > > > "In the runtime system with SMP support, drivers are locked either on > > driver level or port level (driver instance level). By default driver > level > > locking will be used, i.e., only one emulator thread will execute code in > > the driver at a time. If port level locking is used, multiple emulator > > threads may execute code in the driver at the same time. There will only > be > > one thread at a time calling driver call-backs corresponding to the same > > port, though. In order to enable port level locking set the > > ERL_DRV_FLAG_USE_PORT_LOCKING driver flag in the driver_entry used by the > > driver. When port level locking is used it is the responsibility of the > > driver writer to synchronize all accesses to data shared by the ports > > (driver instances)." > > > > Yeah, this one bit me in the ass by not realizing what the flag meant. > Turns out zero means lock harder, not no locking... > > > I hope this helps, > > > > Chris > > > > Thanks for your help. At some point I'll poke at changing the control > -> outputv call back to see if there's a noticeable speedup. If so > then I imagine it'd be time to look at working on the yajl internals > to save time when unicode is a factor. > > Thanks again, > Paul Davis > > > > > On Sun, Jan 25, 2009 at 1:49 PM, Enrico Thierbach > > wrote: > >> > >> Hi guys, > >> > >> I have just finished what I would call the first stage of the native > >> JSON parser implementation. This is the state as of now at > >> http://github.com/pboy/eep0018/, Please see the readme file. > >> > >> In short, this is the status: > >> > >> - I parse everything that comes along like mochijson2 and rabbitmq > >> - optionally I can parse according to eep0018 > >> - my code runs 6 times as fast as mochijson2/rabbitmq at JSON input > >> of a certain size, and is usally not slower on very small JSON input. > >> > >> jan tried the module along with couchdb, and find one issue regarding > >> UTF8 characters; besides of that everything seemed to run fine and > >> much faster. The utf8 parsing issue is resolved (or better: worked > >> around: the JSON parser and the CouchDB tests have different ideas on > >> what is valid UTF8). > >> > >> What would be next? > >> > >> 1. I would like to invite you all to review and try the code. > >> > >> 2. I need some hints regarding "parallel execution". The native driver > >> does not support multithreading (and why should it? It only > >> complicates things where OTP can do that kind of stuff by itself > >> already.) With the current code the driver gets loaded only once. > >> Therefore on a multicore machine only one CPU gets really used. Is it > >> somehow possible to load the driver multiple times? The only way I see > >> so far is having the driver compiled and installed multiple times with > >> different names; but I guess there is a better way. The code itself > >> should luckily run in a parallel situation. > >> > >> 3. and finally I'll have to tackle the Erlang->JSON issue. I don't > >> expect a speedup as big. > >> > >> Please see my next mail for some comments on EEP0018. > >> > >> /eno > >> > >> ==================================================================== > >> A wee piece of ruby every monday: http://1rad.wordpress.com/ > >> _______________________________________________ > >> erlang-questions mailing list > >> erlang-questions@REDACTED > >> http://www.erlang.org/mailman/listinfo/erlang-questions > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sysop@REDACTED Tue Jan 27 07:53:25 2009 From: sysop@REDACTED (Matt Stancliff) Date: Mon, 26 Jan 2009 22:53:25 -0800 Subject: [erlang-questions] EEP0018/native JSON parsing In-Reply-To: <781dd98c0901261936h7274089ar21945fe3cadcd33d@mail.gmail.com> References: <781dd98c0901261752w18c32fb9s84e411b1b2e99b09@mail.gmail.com> <781dd98c0901261936h7274089ar21945fe3cadcd33d@mail.gmail.com> Message-ID: Chris, On Jan 26, 2009, at 7:36 PM, Chris Newcombe wrote: > EDTK only works on Linux at the moment. Some people made a lot of > progress with an OS-X port, but I never heard if it was finished. A > Win32 port is feasible, esp. now that R12B exposes portable variants > of the pthread primitives, but would be a fair amount of work. Good news everyone! I finished getting EDTK+BDB working on OS X. My BDB tests now pass with the same results under Linux and OS X. The EDTK installer is at http://bitbucket.org/mattsta/edtk-installer I tested the installer on my iMac (OS X 10.5.5 x86) and my Linux box (also x86). Andy Gross had it working on OS X x86_64 at one point with some Makefile modifications. While we're on the topic of EDTK, do you and/or Scott have plans to update BDB support beyond 4.5.20? Sincerely, -Matt -- Matt Stancliff San Jose, CA AIM: seijimr iPhone: 678-591-9337 "The best way to predict the future is to invent it." --Alan Kay From bengt.kleberg@REDACTED Tue Jan 27 12:18:56 2009 From: bengt.kleberg@REDACTED (Bengt Kleberg) Date: Tue, 27 Jan 2009 12:18:56 +0100 Subject: [erlang-questions] Unexpected behavior by io:fread. In-Reply-To: <00163613a40a34acb504612f546a@google.com> References: <00163613a40a34acb504612f546a@google.com> Message-ID: <1233055136.4772.6.camel@seasc1137.dyn.rnd.as.sw.ericsson.se> Greetings, I modified your program to skip white space before reading the first item. Like this: read_file(File) -> io:fread(File, "", " "), read_file(File, []). Now the behavior is consistently wrong in the same way: [5973, 4152, 40, 926, 53, 6, 3410, 51, 87, 86, 8161, 95, 66, 57, 25, 6890, 81, 80, 38, 92, 67, 7330, 28, 51, 76, 81, 18, 75, 44] This is for erl -version Erlang (ASYNC_THREADS,HIPE) (BEAM) emulator version 5.5.5 bengt On Sat, 2009-01-24 at 00:10 +0000, cayle.spandon@REDACTED wrote: > I have run into some unexpected behavior by io:fread. > > I was wondering if someone could check whether there is something > wrong with the way I use io:fread or whether there is a bug in > io:fread. > > I have a text file which contains a "triangle of numbers"as follows: > >
> 59
> 73 41
> 52 40 09
> 26 53 06 34
> 10 51 87 86 81
> 61 95 66 57 25 68
> 90 81 80 38 92 67 73
> 30 28 51 76 81 18 75 44
> ...
> 
> > There is a single space between each pair of numbers and each line > ends with a carriage-return new-line pair. > > I use the following Erlang program to read this file into a list. > >
> -module(euler67).
> -author('Cayle Spandon').
> 
> -export([solve/0]).
> 
> solve() ->
> {ok, File} = file:open("triangle.txt", [read]),
> Data = read_file(File),
> ok = file:close(File),
> Data.
> 
> read_file(File) ->
> read_file(File, []).
> 
> read_file(File, Data) ->
> case io:fread(File, "", "~d") of
> {ok, [N]} -> 
> read_file(File, [N | Data]);
> eof ->
> lists:reverse(Data)
> end.
> 
> > The output of this program is: > >
> (erlide@REDACTED)30> euler67:solve().
> [59,73,41,52,40,9,26,53,6,3410,51,87,86,8161,95,66,57,25,
> 6890,81,80,38,92,67,7330,28,51,76,81|...]
> 
> > Note how the last number of the fourth line (34) and the first number > of the fifth line (10) have been merged into a single number 3410. > > When I dump the text file using "od" there is nothing special about > those lines; they end with cr-nl just like any other line: > >
> > od -t a triangle.txt
> 0000000 5 9 cr nl 7 3 sp 4 1 cr nl 5 2 sp 4 0
> 0000020 sp 0 9 cr nl 2 6 sp 5 3 sp 0 6 sp 3 4
> 0000040 cr nl 1 0 sp 5 1 sp 8 7 sp 8 6 sp 8 1
> 0000060 cr nl 6 1 sp 9 5 sp 6 6 sp 5 7 sp 2 5
> 0000100 sp 6 8 cr nl 9 0 sp 8 1 sp 8 0 sp 3 8
> 0000120 sp 9 2 sp 6 7 sp 7 3 cr nl 3 0 sp 2 8
> 0000140 sp 5 1 sp 7 6 sp 8 1 sp 1 8 sp 7 5 sp
> 0000160 4 4 cr nl 8 4 sp 1 4 sp 9 5 sp 8 7 sp
> 
> > One interesting observation is that some of the numbers for which the > problem occurs happen to be on 16-byte boundary in the text file (but > not all, for example 6890). > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From enrico.thierbach@REDACTED Tue Jan 27 12:48:49 2009 From: enrico.thierbach@REDACTED (Enrico Thierbach) Date: Tue, 27 Jan 2009 12:48:49 +0100 Subject: [erlang-questions] EEP0018/native JSON parsing In-Reply-To: References: <781dd98c0901261752w18c32fb9s84e411b1b2e99b09@mail.gmail.com> <781dd98c0901261936h7274089ar21945fe3cadcd33d@mail.gmail.com> Message-ID: > > > > >>>2, I actually hacked yajl a bit to decode utf-8 data into the same > buffer > >>> it's reading from > > specifically to avoid any memcpy stuff. The downside is that this > > destroys the original binary term. > > > > I wonder if that is safe on the data you get from control(). The docs > don't > > seem to say. The pointer is a char* not a const char*, but that might > > simply be oversight. > > > > Absolutely no idea. From the stuff I read there was very little of the > over view type of info that can be important. > I bet there is something bad about destroying that content. This is erlnag after all, so each object should be immutable once created. > > > > >>>With some more hacking on yajl, it's possible that we could change > around > >>> the > > original unicode buffer stuff to decode all unicode strings into a > > single buffer and then reference that buffer etc. > > > > Yes you could allocate a single driver binary of conservative size, > > incrementally fill it with data (using sub-binary references in the > > constructed term) and then realloc the binary to the final size (if it is > > too large) at the end. Good idea. I thought I read somewhere that > Yajl > > will only copy strings that have unicode characters, so this method would > > presumably only copy those strings. All ascii/latin1 strings (most I > would > > imagine) wouldn't need to be copied (if outputv were used). > > > Before implementing anything complicated I would suggest to return the data from within the originating binary if yajl didn't have to convert anything (which it doesn't do if the input is UTF-8), and only in those other cases to make a new binary. The erl-driver doc says something about a BINARY_FROM_BUFFER thingy and suggests that as pretty fast. I would like to see how well that would work. >>>I hadn't heard of EDTK prior to now, I'll take a look in the near future. > > It's the Erlang Driver Toolkit. It would b nice to have known that before :) From what I read here it seems a bit overcomplicated for what we want to achive, I would say. /eno -- ==================================================================== A wee piece of ruby every monday: http://1rad.wordpress.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven.charles.davis@REDACTED Tue Jan 27 13:41:33 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Tue, 27 Jan 2009 06:41:33 -0600 Subject: [erlang-questions] float_to_binary? Message-ID: <497F00FD.6020509@gmail.com> I'm probably being dumb, but I am stuck... to_binary(X) when is_integer(X) -> <>; to_binary(X) when is_float(X) -> ??. ...btw attempting to use erlang:float_to_binary(X, 64) turned out to be a very bad idea (computer just went POP!). Thanks for any assistance! /s From gleber.p@REDACTED Tue Jan 27 13:52:10 2009 From: gleber.p@REDACTED (Gleb Peregud) Date: Tue, 27 Jan 2009 13:52:10 +0100 Subject: [erlang-questions] float_to_binary? In-Reply-To: <497F00FD.6020509@gmail.com> References: <497F00FD.6020509@gmail.com> Message-ID: <14f0e3620901270452g655259cby1df384bad5ef8500@mail.gmail.com> to_binary(X) when is_integer(X) -> <>; %% it will give you 1-byte binary, truncating integer to range 0..255 (i.e. byte) to_binary(X) when is_float(X) -> <>. %% it will give you a 8-bytes binary (i.e. 64-bits float) On Tue, Jan 27, 2009 at 1:41 PM, Steve Davis wrote: > I'm probably being dumb, but I am stuck... > > to_binary(X) when is_integer(X) -> <>; > to_binary(X) when is_float(X) -> ??. > > ...btw attempting to use erlang:float_to_binary(X, 64) turned out to be > a very bad idea (computer just went POP!). > > Thanks for any assistance! > /s > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- Gleb Peregud http://gleber.pl/ Every minute is to be grasped. Time waits for nobody. -- Inscription on a Zen Gong From saleyn@REDACTED Tue Jan 27 14:00:35 2009 From: saleyn@REDACTED (Serge Aleynikov) Date: Tue, 27 Jan 2009 08:00:35 -0500 Subject: [erlang-questions] float_to_binary? In-Reply-To: <497F00FD.6020509@gmail.com> References: <497F00FD.6020509@gmail.com> Message-ID: <497F0573.3020703@gmail.com> 1> Float = 1.0. 1.0 2> <>. <<63,240,0,0,0,0,0,0>> If you need that float to be encoded in the external format, uou can use term_to_binary(Float, [{minor_version, 1}]) for IEEE 754 encoding: 3> term_to_binary(Float, [{minor_version, 1}]). <<131,70,63,240,0,0,0,0,0,0>> Serge Steve Davis wrote: > I'm probably being dumb, but I am stuck... > > to_binary(X) when is_integer(X) -> <>; > to_binary(X) when is_float(X) -> ??. > > ...btw attempting to use erlang:float_to_binary(X, 64) turned out to be > a very bad idea (computer just went POP!). > > Thanks for any assistance! > /s > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From steven.charles.davis@REDACTED Tue Jan 27 14:18:24 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Tue, 27 Jan 2009 07:18:24 -0600 Subject: [erlang-questions] float_to_binary? In-Reply-To: <497F00FD.6020509@gmail.com> References: <497F00FD.6020509@gmail.com> Message-ID: <497F09A0.90409@gmail.com> Oh yea :) ... the bit syntax is wonderful. Thanks both for the responses and the extra tips. Here's what I now have... binary(X) when is_integer(X) -> <>; binary(X) when is_float(X) -> <>; % 64-bit IEEE ...which covers the base cases for me. Best regards, Steve From exta7@REDACTED Tue Jan 27 14:22:01 2009 From: exta7@REDACTED (Zvi) Date: Tue, 27 Jan 2009 05:22:01 -0800 (PST) Subject: [erlang-questions] float_to_binary? In-Reply-To: <497F00FD.6020509@gmail.com> References: <497F00FD.6020509@gmail.com> Message-ID: <21685174.post@talk.nabble.com> there is no erlang:float_to_binary ... 1> Pi = math:pi(). 3.141592653589793 2> <>. <<64,9,33,251,84,68,45,24>> so to_binary(X) when is_integer(X) -> <>; to_binary(X) when is_float(X) -> <>. Zvi Steve Davis-5 wrote: > > I'm probably being dumb, but I am stuck... > > to_binary(X) when is_integer(X) -> <>; > to_binary(X) when is_float(X) -> ??. > > ...btw attempting to use erlang:float_to_binary(X, 64) turned out to be > a very bad idea (computer just went POP!). > > Thanks for any assistance! > /s > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > > -- View this message in context: http://www.nabble.com/float_to_binary--tp21684748p21685174.html Sent from the Erlang Questions mailing list archive at Nabble.com. From mikpe@REDACTED Tue Jan 27 14:31:28 2009 From: mikpe@REDACTED (Mikael Pettersson) Date: Tue, 27 Jan 2009 14:31:28 +0100 Subject: [erlang-questions] float_to_binary? In-Reply-To: <497F00FD.6020509@gmail.com> References: <497F00FD.6020509@gmail.com> Message-ID: <18815.3248.397546.220751@harpo.it.uu.se> Steve Davis writes: > ...btw attempting to use erlang:float_to_binary(X, 64) turned out to be > a very bad idea (computer just went POP!). I assume by POP you meant a serious crash not just an Erlang-level error. If so, have you reported that to erlang-bugs, preferably together with a test case and some basic info about the system where this occurred? From steven.charles.davis@REDACTED Tue Jan 27 14:46:44 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Tue, 27 Jan 2009 07:46:44 -0600 Subject: [erlang-questions] float_to_binary? In-Reply-To: <18815.3248.397546.220751@harpo.it.uu.se> References: <497F00FD.6020509@gmail.com> <18815.3248.397546.220751@harpo.it.uu.se> Message-ID: <497F1044.5040407@gmail.com> I will report this to erlang-bugs just in case... I'm not sure if it's reproducible, but honestly I don't want to risk repro'ing it... (the winxp laptop I was on actually "blue screened" for the first time in over 3 years). Regards, Steve Mikael Pettersson wrote: > Steve Davis writes: > > ...btw attempting to use erlang:float_to_binary(X, 64) turned out to be > > a very bad idea (computer just went POP!). > > I assume by POP you meant a serious crash not just an > Erlang-level error. > > If so, have you reported that to erlang-bugs, preferably > together with a test case and some basic info about the > system where this occurred? > From steven.charles.davis@REDACTED Tue Jan 27 14:49:54 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Tue, 27 Jan 2009 05:49:54 -0800 (PST) Subject: [erlang-questions] float_to_binary? In-Reply-To: <21685174.post@talk.nabble.com> References: <497F00FD.6020509@gmail.com> <21685174.post@talk.nabble.com> Message-ID: <659cefc0-6c8c-406c-8e3c-96e6042fffd7@v18g2000pro.googlegroups.com> On Jan 27, 7:22?am, Zvi wrote: > there is no erlang:float_to_binary ... > Not any more, but there was, and I think the c driver code is still in there. It did carry a warning not to use it outside OTP apps... From bgustavsson@REDACTED Tue Jan 27 15:06:44 2009 From: bgustavsson@REDACTED (Bjorn Gustavsson) Date: Tue, 27 Jan 2009 15:06:44 +0100 Subject: [erlang-questions] A couple of questions about constructing and matching binaries In-Reply-To: References: Message-ID: <6672d0160901270606p7ffca30amc689cf850271431f@mail.gmail.com> On Mon, Jan 26, 2009 at 11:47 PM, Sergey S wrote: > Hello. > > The following questions arose while I was reading Efficiency Guide / 4 > Constructing and matching binaries: > > #1 Please, take a look at the following quote (from 4.2 Constructing binaries): > > -----------------8<--------------- > Bin0 = <<0>>, %% 1 > Bin1 = <>, %% 2 > %% Lines 3 to 6 have > been skippped > > "The first line (marked with the %% 1 comment), assigns a heap binary > to the variable Bin0. > > The second line is an append operation. Since Bin0 has not been > involved in an append operation, >>> a new refc binary will be created > <<< and the contents of Bin0 will be copied into it." > ----------------->8--------------- > > Why has Bin1 become reference-counted binary, not the heap one? It's > still too small (smaller than 64 bytes) to be stored outside of the > heap. Bin1 has been involved in an append operation. (It was created by appending to a copy of the contents of Bin0.) The run-time system optimistically assumes that there will be more appends to the same binary, so it allocates it as a reference-counted binary. (It is not possible to append to heap binaries.) > I don't understand why "Since Bin0 has not been involved in an append > operation" is the reason of moving the binary to the storage of refc > binaries :/ The CONTENTS of Bin0 has been involved in an append operation, but not the binary itself. Bin0 is unchanged. > > #2 Here is another quote, which is also not so clear to me: > > -----------------8<--------------- > The optimization of the binary append operation requires that there is > a single ProcBin and a single reference to the ProcBin for the binary. > ----------------->8--------------- > > What does "reference to the ProcBin" mean? > It is means a reference from a sub binary. (I agree that this is not clear from context and not mentioned.) > For example we have code like this: > > Bin1 = Bin2 = Bin3 = list_to_binary(lists:duplicate(128, $A)) > > Has that code created three ProcBins (Bin1, Bin2 and Bin3) or there is > only one ProcBin and three references to it? > There is one ProcBin, one sub binary, and three references to the sub binary. I might do some revisions to the text in the R13 release. I am not sure how much I should try to explain. The text could get quite long if I tried to explain all details and tricks done under the hood. /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB From andreas.hillqvist@REDACTED Tue Jan 27 18:03:15 2009 From: andreas.hillqvist@REDACTED (Andreas Hillqvist) Date: Tue, 27 Jan 2009 18:03:15 +0100 Subject: [erlang-questions] How should one specify compiler options when compiling from emacs erlang-mode? In-Reply-To: <44ed5e0f0901241340u12a1e181v7d3039acae0329f0@mail.gmail.com> References: <44ed5e0f0901241340u12a1e181v7d3039acae0329f0@mail.gmail.com> Message-ID: <8268eea30901270903q5dee004cg5e12a93321128759@mail.gmail.com> Hi. Have you tried an Emakefile (http://erlang.org/doc/man/make.htm)? {'*',[{i,"../foo"}]}. It might do the trick but I do not know. ;-) Kind regards Andreas Hillqvist 2009/1/24 David Cabana : > What is the accepted way to specify compiler options when using emacs > erlang-mode? I want to specify an include path, without randomly > hacking up erlang.el in non-maintainable ways. > Thank you, > drc > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From colm.dougan@REDACTED Tue Jan 27 19:03:11 2009 From: colm.dougan@REDACTED (Colm Dougan) Date: Tue, 27 Jan 2009 18:03:11 +0000 Subject: [erlang-questions] application:stop(mnesia) blocking Message-ID: <24d4f39c0901271003t1e923677sc5592a27e1e368d1@mail.gmail.com> Hi list, I've got a strange problem with mnesia:stop that is driving me nuts. I'm sure it must be something trivial I've done wrong but I can't seem to figure it out. I have a trivial application called "foo" which contains a gen_server called foo_main. The gen_server does an application:start(mnesia) in its init callback and an application:stop(mnesia) in the terminate callback. For some reason the latter seems to block until it eventually gets killed by the supervisor. I'd be very grateful if someone could look at my code and point out the inevitably dumb thing I'm doing wrong : http://github.com/gardenia/sandbox/tree/de2b36089f1d7928de3161fe7f9d6b78f0b840bd/mnesia_hang_on_shutdown Thanks, Colm From drcabana@REDACTED Tue Jan 27 20:00:52 2009 From: drcabana@REDACTED (David Cabana) Date: Tue, 27 Jan 2009 14:00:52 -0500 Subject: [erlang-questions] How should one specify compiler options when compiling from emacs erlang-mode? In-Reply-To: <8268eea30901270903q5dee004cg5e12a93321128759@mail.gmail.com> References: <44ed5e0f0901241340u12a1e181v7d3039acae0329f0@mail.gmail.com> <8268eea30901270903q5dee004cg5e12a93321128759@mail.gmail.com> Message-ID: <44ed5e0f0901271100j1f84a0cfm77a159c6af33ba5f@mail.gmail.com> Andreas, Thanks for the reply. I have working makefiles already; compilation is not the issue. My real goal is to create an emacs erlang shell that is aware of the correct include paths (relative to the code being edited), so that flymake-mode will work correctly. Flymake does on-the-fly syntax analysis of code in an edit buffer. It normally works well, but breaks in the presence of unresolved -include() directives. I hope to find some way to make the erlang shell (and hence flymake-mode ??) aware of include paths. The erlang.el code contains a variable that looked like it might be useful (can't recall it offhand, something about inferior mode machine options), but have not had time to experiment. drc On Tue, Jan 27, 2009 at 12:03 PM, Andreas Hillqvist wrote: > Have you tried an Emakefile (http://erlang.org/doc/man/make.htm)? > {'*',[{i,"../foo"}]}. From steven.charles.davis@REDACTED Wed Jan 28 00:37:31 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Tue, 27 Jan 2009 17:37:31 -0600 Subject: [erlang-questions] I Hate Unit Testing... Message-ID: <497F9ABB.4030905@gmail.com> Hi all, I really hate writing code to test my code. I have noticed that most people must also hate writing test code since the unit test code included in almost every project I've ever seen is... well, scanty, at best. But it came to me that *there's a way out of this* thanks to Erlang, since: - all functions in Erlang are deterministic, i.e. for a certain input you are guaranteed one and only one output, and so a simple MFA apply should always give a predictable result. - reading in terms to feed to apply/3 is trivial. So I got to hacking something together today to see how/if this idea would work. I'm posting the results of this experiment here to see if anyone thinks the idea is interesting and has legs. Hopefully I may get a few pointers on improving my naive and diabolical code as I'm definitely a "learner". Familiarity is utmost so I just borrowed/subverted the term structure used for .app files, like this... ----- my_app.test ------ %% utest test specification {utest, my_app, [{description, ""}, {version, "0.1"}, {flags, [verbose]}, %% only [verbose] or [] supported {applications, [kernel, stdlib, crypto]}, %% dependencies {tests, [ % Tests are specified as Module, Function, ArgumentList, ExpectedResult % i.e. {M, F, A, R} {my_module, hex, [2], "2"}, {my_module, hex, [255], "ff"}, {my_module, hex, [55551], "d8ff"} ]} ]}. ...after a few hours hacking around I had a simple demo module that produces output like this... ---- Sample Console Session ---- 3> utest:run("../test/my_module.test"). UNIT TEST Application: my_app Version: "0.1" Description: "" Unit Tests: 3 Depends on: [kernel,stdlib,crypto] Starting crypto...ok Running tests... [FAIL] my_module:hex(2) -> 50 EXPECTED "2" [OK] my_module:hex(255) -> "ff" [OK] my_module:hex(55551) -> "d8ff" ***FAILURE: There were 1 test failures {fail,{tests,3},{errors,1}} 4> ...now I'll grit my teeth and post the code in case anyone wishes to try it out (or help me by giving me style pointers - which I know I need!) ---- utest.erl ---- %% Simple Unit Testing without writing code! -module(utest). -vsn("0.1"). -author('steven.charles.davis@REDACTED'). -record(utest, {package="unknown", version="0.0", description="", flags=[], depends=[], tests=[]}). -export([run/1]). %% File is a ".test" spec file run(File) -> {ok, [Utest]} = file:consult(File), {utest, Package, Options} = Utest, R = #utest{package=Package}, R1 = get_options(Options, R), io:format("UNIT TEST~n Application: ~p~n", [R#utest.package]), N = length(R1#utest.tests), io:format(" Version: ~p~n Description: ~p~n Depends on: ~p~n Unit Tests: ~p~n", [R1#utest.version, R1#utest.description, R1#utest.depends, N]), ensure(R1#utest.depends), case R1#utest.flags of [verbose] -> V = true; _ -> V = false end, io:format("Running tests...~n", []), {X, E} = do_tests(R1#utest.tests, 0, V), {X, {tests, N}, {errors, E}}. %% get_options([H|T], R) -> case H of {version, Value} -> R1 = R#utest{version=Value}; {description, Value} -> R1 = R#utest{description=Value}; {flags, Value} -> R1 = R#utest{flags=Value}; {applications, Value} -> R1 = R#utest{depends=Value}; {tests, Value} -> R1 = R#utest{tests=Value}; _ -> R1 = R end, get_options(T, R1); get_options([], R) -> R. %% ensure(Apps) -> ensure(Apps, application:which_applications()). %% ensure([App|Rest], Running) -> case lists:keysearch(App, 1, Running) of {value, {App, _, _}} -> ok; false -> io:format("Starting ~p...", [App]), ok = application:start(App), io:format("ok~n", []) end, ensure(Rest, Running); ensure([], _) -> application:which_applications(). %% do_tests([H|T], E, V) -> {M, F, A, R} = H, R1 = apply(M, F, A), S = lists:flatten(io_lib:format("~w", [A])), S1 = string:sub_string(S, 2, length(S) - 1), case R1 of R -> E1 = E, case V of true -> io:format(" [OK] ~p:~p(" ++ S1 ++ ") -> ~p~n", [M, F, R1]); false -> ok end; _ -> E1 = E + 1, io:format(" [FAIL] ~p:~p(" ++ S1 ++ ") -> ~p EXPECTED ~p~n", [M, F, R1, R]) end, do_tests(T, E1, V); do_tests([], E, V) -> case V of true when E =:= 0 -> io:format("SUCCESS! All tests completed successfully~n", []), {ok, E}; true when E > 0 -> io:format("***FAILURE: There were ~p test failures~n", [E]), {fail, E}; false when E =:= 0 -> {ok, E}; false when E > 0 -> {fail, E}; _ -> {error, E} end. Well, that's the basic idea -- there's a heap of improvements that could be made of course, but thanks for reading this far, I look forward to any comments you may have! BR, /scd From nick@REDACTED Wed Jan 28 00:54:48 2009 From: nick@REDACTED (Nick Gerakines) Date: Tue, 27 Jan 2009 15:54:48 -0800 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: <497F9ABB.4030905@gmail.com> References: <497F9ABB.4030905@gmail.com> Message-ID: I think you'll find that you aren't alone. I've talked to several people who feel the same way and ultimately came up with my own solution. A short while back I took over an Erlang project called etap with the purpose of creating a unit testing facility that produces TAP output. It gives you more flexibility when writing unit tests because your test code is executed in whichever order you write it in as long as your tests match your plan. The project is open source under the MIT license and is available on GitHub. We are using it regularly here at EA and have been actively updating the project in regular intervals. http://github.com/ngerakines/etap You can also use it to create code coverage reports and do things like pipe your test results into Perl's TAP::Harness module. Several of my open source projects (like erlang_protobuffs) use it and working examples can be found there. Hope that helps a bit. # Nick Gerakines On Tue, Jan 27, 2009 at 3:37 PM, Steve Davis wrote: > Hi all, > > I really hate writing code to test my code. I have noticed that most > people must also hate writing test code since the unit test code > included in almost every project I've ever seen is... well, scanty, at > best. > > But it came to me that *there's a way out of this* thanks to Erlang, since: > - all functions in Erlang are deterministic, i.e. for a certain input > you are guaranteed one and only one output, and so a simple MFA apply > should always give a predictable result. > - reading in terms to feed to apply/3 is trivial. > > So I got to hacking something together today to see how/if this idea > would work. I'm posting the results of this experiment here to see if > anyone thinks the idea is interesting and has legs. Hopefully I may get > a few pointers on improving my naive and diabolical code as I'm > definitely a "learner". > > Familiarity is utmost so I just borrowed/subverted the term structure > used for .app files, like this... > ----- my_app.test ------ > %% utest test specification > {utest, my_app, > [{description, ""}, > {version, "0.1"}, > {flags, [verbose]}, %% only [verbose] or [] supported > {applications, [kernel, stdlib, crypto]}, %% dependencies > {tests, [ > % Tests are specified as Module, Function, ArgumentList, ExpectedResult > % i.e. {M, F, A, R} > {my_module, hex, [2], "2"}, > {my_module, hex, [255], "ff"}, > {my_module, hex, [55551], "d8ff"} > ]} > ]}. > > ...after a few hours hacking around I had a simple demo module that > produces output like this... > ---- Sample Console Session ---- > 3> utest:run("../test/my_module.test"). > UNIT TEST > Application: my_app > Version: "0.1" > Description: "" > Unit Tests: 3 > Depends on: [kernel,stdlib,crypto] > Starting crypto...ok > Running tests... > [FAIL] my_module:hex(2) -> 50 EXPECTED "2" > [OK] my_module:hex(255) -> "ff" > [OK] my_module:hex(55551) -> "d8ff" > ***FAILURE: There were 1 test failures > {fail,{tests,3},{errors,1}} > 4> > > ...now I'll grit my teeth and post the code in case anyone wishes to try > it out (or help me by giving me style pointers - which I know I need!) > ---- utest.erl ---- > %% Simple Unit Testing without writing code! > -module(utest). > -vsn("0.1"). > -author('steven.charles.davis@REDACTED'). > > -record(utest, {package="unknown", version="0.0", description="", > flags=[], depends=[], tests=[]}). > > -export([run/1]). > > %% File is a ".test" spec file > run(File) -> > {ok, [Utest]} = file:consult(File), > {utest, Package, Options} = Utest, > R = #utest{package=Package}, > R1 = get_options(Options, R), > io:format("UNIT TEST~n Application: ~p~n", [R#utest.package]), > N = length(R1#utest.tests), > io:format(" Version: ~p~n Description: ~p~n Depends on: ~p~n Unit > Tests: ~p~n", > [R1#utest.version, R1#utest.description, R1#utest.depends, N]), > ensure(R1#utest.depends), > case R1#utest.flags of > [verbose] -> V = true; > _ -> V = false > end, > io:format("Running tests...~n", []), > {X, E} = do_tests(R1#utest.tests, 0, V), > {X, {tests, N}, {errors, E}}. > > %% > get_options([H|T], R) -> > case H of > {version, Value} -> R1 = R#utest{version=Value}; > {description, Value} -> R1 = R#utest{description=Value}; > {flags, Value} -> R1 = R#utest{flags=Value}; > {applications, Value} -> R1 = R#utest{depends=Value}; > {tests, Value} -> R1 = R#utest{tests=Value}; > > _ -> R1 = R > end, > get_options(T, R1); > get_options([], R) -> > R. > > %% > ensure(Apps) -> > ensure(Apps, application:which_applications()). > %% > ensure([App|Rest], Running) -> > case lists:keysearch(App, 1, Running) of > {value, {App, _, _}} -> > ok; > false -> > io:format("Starting ~p...", [App]), > ok = application:start(App), > io:format("ok~n", []) > end, > ensure(Rest, Running); > ensure([], _) -> > application:which_applications(). > > %% > do_tests([H|T], E, V) -> > {M, F, A, R} = H, > R1 = apply(M, F, A), > S = lists:flatten(io_lib:format("~w", [A])), > S1 = string:sub_string(S, 2, length(S) - 1), > case R1 of > R -> > E1 = E, > case V of > true -> io:format(" [OK] ~p:~p(" ++ S1 ++ ") -> ~p~n", [M, F, R1]); > false -> ok > end; > _ -> > E1 = E + 1, > io:format(" [FAIL] ~p:~p(" ++ S1 ++ ") -> ~p EXPECTED ~p~n", [M, F, > R1, R]) > end, > do_tests(T, E1, V); > do_tests([], E, V) -> > case V of > true when E =:= 0 -> io:format("SUCCESS! All tests completed > successfully~n", []), {ok, E}; > true when E > 0 -> io:format("***FAILURE: There were ~p test > failures~n", [E]), {fail, E}; > false when E =:= 0 -> {ok, E}; > false when E > 0 -> {fail, E}; > _ -> {error, E} > end. > > Well, that's the basic idea -- there's a heap of improvements that could > be made of course, but thanks for reading this far, I look forward to > any comments you may have! > > BR, > /scd > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From steven.charles.davis@REDACTED Wed Jan 28 01:28:33 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Tue, 27 Jan 2009 18:28:33 -0600 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: References: <497F9ABB.4030905@gmail.com> Message-ID: <497FA6B1.5060809@gmail.com> Nick Gerakines wrote: > A short while back I took over an Erlang project called etap with the > purpose of creating a unit testing facility that produces TAP output. Very nice, Nick... I'm sure it's a lot more capable that my idea ever could be... however, I do like the simplicity of just editing a text file and running it without the compile step. That way my dog can copy/paste and devise the unit tests... and, what's more, even I may actually bother to write some! Regs, /s From nick@REDACTED Wed Jan 28 01:32:45 2009 From: nick@REDACTED (Nick Gerakines) Date: Tue, 27 Jan 2009 16:32:45 -0800 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: <497FA6B1.5060809@gmail.com> References: <497F9ABB.4030905@gmail.com> <497FA6B1.5060809@gmail.com> Message-ID: On Tue, Jan 27, 2009 at 4:28 PM, Steve Davis wrote: > Nick Gerakines wrote: >> >> A short while back I took over an Erlang project called etap with the >> purpose of creating a unit testing facility that produces TAP output. > > Very nice, Nick... I'm sure it's a lot more capable that my idea ever could > be... however, I do like the simplicity of just editing a text file and > running it without the compile step. That way my dog can copy/paste and > devise the unit tests... and, what's more, even I may actually bother to > write some! > > Regs, > /s > It's on my immediate TODO list to allow you to write tests like you would in cucumber using etap. -- nkg From wde@REDACTED Wed Jan 28 03:20:23 2009 From: wde@REDACTED (wde) Date: Wed, 28 Jan 2009 03:20:23 +0100 Subject: [erlang-questions] I Hate Unit Testing... Message-ID: <200901280220.n0S2KUm3020813@morgoth.cslab.ericsson.net> Hello, you could try these pointers (in order to get new ideas maybe :+)) http://svn.process-one.net/contribs/trunk/eunit/doc/overview-summary.html http://trac.extremeforge.net/extremeforge http://pragdave.pragprog.com/pragdave/2007/04/testfirst_word_.html wde ======= le 28/01/2009, 01:32:45 vous ?criviez: ======= >On Tue, Jan 27, 2009 at 4:28 PM, Steve Davis > wrote: >> Nick Gerakines wrote: >>> >>> A short while back I took over an Erlang project called etap with the >>> purpose of creating a unit testing facility that produces TAP output. >> >> Very nice, Nick... I'm sure it's a lot more capable that my idea ever could >> be... however, I do like the simplicity of just editing a text file and >> running it without the compile step. That way my dog can copy/paste and >> devise the unit tests... and, what's more, even I may actually bother to >> write some! >> >> Regs, >> /s >> > >It's on my immediate TODO list to allow you to write tests like you >would in cucumber using etap. -- nkg >_______________________________________________ >erlang-questions mailing list >erlang-questions@REDACTED >http://www.erlang.org/mailman/listinfo/erlang-questions > = = = = = = = = = ========= = = = = = = = = = = wde wde@REDACTED 28/01/2009 From kaiduanx@REDACTED Wed Jan 28 05:00:10 2009 From: kaiduanx@REDACTED (Kaiduan Xie) Date: Tue, 27 Jan 2009 23:00:10 -0500 Subject: [erlang-questions] profile question Message-ID: Hi, all, I have a question on how to find the hot spot of large base Erlang system. For example, after running cprof.start(), cprof.pause(), cprof.analyze(), I got the following results (only the first item is listed below), {1847012003, [{io_lib_format,722457356, [{{io_lib_format,pcount,2},109483111}, {{io_lib_format,collect,2},109483111}, {{io_lib_format,build,3},109483111}, {{io_lib_format,iolist_to_chars,1},83312743}, {{io_lib_format,indentation,2},60014886}, {{io_lib_format,field_value,2},26618934}, {{io_lib_format,field_value,3},17824836}, {{io_lib_format,precision,2},17706522}, {{io_lib_format,pad_char,2},17706522}, {{io_lib_format,field_width,3},17706522}, {{io_lib_format,field_width,2},17706522}, {{io_lib_format,decr_pc,2},17706522}, {{io_lib_format,control,7},17706522}, {{io_lib_format,collect_cseq,2},17706522}, {{io_lib_format,collect_cc,2},17706522}, {{io_lib_format,print,7},14402937}, {{io_lib_format,chars,2},8912422}, {{io_lib_format,term,5},8912417}, {{io_lib_format,min|...},8912416}, {{io_lib_format|...},8912416}, {{...}|...}, {...}|...]}, So here comes the question, how can we find which part calls (io_lib_format,pcount,2) most? I tried to use fprof(), but it seems that you need to know the arguments of the function first. What is the best practice to address this problem? Or did I do something wrong? Thanks, kaiduan -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris.newcombe@REDACTED Wed Jan 28 05:30:04 2009 From: chris.newcombe@REDACTED (Chris Newcombe) Date: Tue, 27 Jan 2009 20:30:04 -0800 Subject: [erlang-questions] EEP0018/native JSON parsing In-Reply-To: References: <781dd98c0901261752w18c32fb9s84e411b1b2e99b09@mail.gmail.com> <781dd98c0901261936h7274089ar21945fe3cadcd33d@mail.gmail.com> Message-ID: <781dd98c0901272030n21d4815bp36cbd585a7321206@mail.gmail.com> >> Good news everyone! I finished getting EDTK+BDB working on OS X. My BDB tests now pass with the same results under Linux and OS X. Excellent! Thanks very much indeed. Scott (if you're reading), perhaps we could add this to a read-me on the EDTK download site? >> While we're on the topic of EDTK, do you and/or Scott have plans to update BDB support beyond 4.5.20? It looks like this is finally going to happen. Someone is looking at updating it to 4.7 now. With testing, we think it may be ready in around 4 weeks (unless schedules/priorities change). I'll post an update here when it's done. Chris On Mon, Jan 26, 2009 at 10:53 PM, Matt Stancliff wrote: > Chris, > > On Jan 26, 2009, at 7:36 PM, Chris Newcombe wrote: > >> EDTK only works on Linux at the moment. Some people made a lot of >> progress with an OS-X port, but I never heard if it was finished. A Win32 >> port is feasible, esp. now that R12B exposes portable variants of the >> pthread primitives, but would be a fair amount of work. >> > > > Good news everyone! I finished getting EDTK+BDB working on OS X. My BDB > tests now pass with the same results under Linux and OS X. > The EDTK installer is at http://bitbucket.org/mattsta/edtk-installer > > I tested the installer on my iMac (OS X 10.5.5 x86) and my Linux box (also > x86). Andy Gross had it working on OS X x86_64 at one point with some > Makefile modifications. > > While we're on the topic of EDTK, do you and/or Scott have plans to update > BDB support beyond 4.5.20? > > > Sincerely, > > -Matt > -- > Matt Stancliff San Jose, CA > AIM: seijimr iPhone: 678-591-9337 > "The best way to predict the future is to invent it." --Alan Kay > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mikael.lixenstrand@REDACTED Wed Jan 28 08:54:02 2009 From: mikael.lixenstrand@REDACTED (Mikael Lixenstrand) Date: Wed, 28 Jan 2009 08:54:02 +0100 Subject: [erlang-questions] : sctp_peer_addr_params In-Reply-To: <20090122105816.GA5043@erix.ericsson.se> References: <20090122075351.GA622@erix.ericsson.se> <20090122105816.GA5043@erix.ericsson.se> Message-ID: Thank you. This helped me a great deal. I had some compilation problems with R12B-5 but when i solved that i worked perfect. / Mikael 2009/1/22 Raimo Niskanen > > On Thu, Jan 22, 2009 at 08:53:51AM +0100, Raimo Niskanen wrote: > > On Wed, Jan 21, 2009 at 07:52:56AM +0100, Mikael Lixenstrand wrote: > > > I'm trying to change the sack delay in gen_sctp > > > > > > {ok,Socket} = gen_sctp:open([{ip, ServerIPAddress}, {port, > ServerPort}] > > > ++ [{sctp_peer_addr_params, #sctp_paddrparams{ assoc_id = 0, address > = > > > {ServerIPAddress ,ServerPort} ,sackdelay = 400}}, > > > {mode, binary}, > > > {active, false}, > > > {sctp_events,#sctp_event_subscribe{address_event = false, > > > shutdown_event=false}}]), > > > > > > I tried several approaches but with the same result: > > > > > > Error in process <0.7100.1> on node 'mikael@REDACTED' with exit value: > > > > {badarg,[{gen_sctp,open,[[{ip,{10,70,160,17}},{port,3868},{sctp_peer_addr_params,{sctp_paddrparams,0,{{10,70,160,17},3868},200,5,600,400,[]}},{mode,binary},{active,false},{sctp_events,{sctp_event_subscribe,undefined,undefined,false,undefined,undefined... > > > > > > I'm running R12B-0 on rhel 5.2 > > > > > > > Congratulations, you have found a bug! > > > > You have dived down to the untested parts of the SCTP code. > > It is still something we have left to do to write thorough > > test cases for gen_sctp. Unfortunately there are a _lot_ > > of options and functionality to test so it is a big task. > > > > Nevertheless.. > > > > The decoding in the inet driver for #sctp_paddrparams{address={IP,P}} > > is wrong; it does not expect the address family byte that it gets > > and detects a parameter length mismatch. > > > > I had a small patch yesterday, but I could not set default > > sctp_peer_addr_params for future associations, so I started > > to read the spec, and indeed it should be possible. > > > > So yesterdays 2 character patch of inet_drv.c now is a patch > > for erts/configure.in, inet_drv.c and prim_inet.erl. I will > > do some more testing and post a patch hopefully during the day. > > Here is the patch. Unfortunately it is a minimal path for the > current development branch so it will not be applied cleanly > to R12B-5 or any other released source. But applying it manually > should be no problem for the initiated user. > > erts/configure.in: Spelling error `ssh_data' -> `ssf_data' > To do this manually to its autoconf result erts/configure > change all occurences of `ssh_data' to `ssf_data' while > preserving case. I have searched and there are > no false occurences. > > erts/emulator/drivers/common/inet_drv.c: > Two changes of inet_set_address -> inet_set_faddress. > A few changes of HAVE_SCTP_* -> HAVE_STRUCT_SCTP_*. > Use the patch to find the places. > > erts/preloaded/src/prim_inet.erl: > This file has moved in our development branch; > I think it was in lib/kernerl/src in R12B-5. > > With these patches it appears to work. Note that it is the > peers address and port you use in the option! To set it > on future associations you must not specify the peer > address or association id. This is now possible thanks > to the prim_inet.erl patch. Without that patch you > could use address={{0,0,0,0},0} and assoc_id=0. > See http://tools.ietf.org/html/draft-ietf-tsvwg-sctpsocket-13#section-7 > just before section 7.1, and > http://tools.ietf.org/html/draft-ietf-tsvwg-sctpsocket-13#section-7.1.13 > > In one erlang shell: > > Erlang R13A (erts-5.7) [64-bit] [smp:4] [async-threads:0] > [kernel-poll:false] > > Eshell V5.7 (abort with ^G) > 1> gen_sctp:open([{ip,loopback}]). > {ok,#Port<0.444>} > 2> {ok,S} = v(-1). > {ok,#Port<0.444>} > 3> gen_sctp:listen(S, true). > ok > 4> inet:port(S). > {ok,32850} > > And then the action in another erlang shell: > > Erlang R13A (erts-5.7) [64-bit] [smp:4] [async-threads:0] > [kernel-poll:false] > > Eshell V5.7 (abort with ^G) > 1> rr(inet). > [connect_opts,hostent,listen_opts,sctp_adaptation_event, > sctp_assoc_change,sctp_assoc_value,sctp_assocparams, > sctp_event_subscribe,sctp_initmsg,sctp_opts, > sctp_paddr_change,sctp_paddrinfo,sctp_paddrparams, > sctp_pdapi_event,sctp_prim,sctp_remote_error,sctp_rtoinfo, > sctp_send_failed,sctp_setadaptation,sctp_setpeerprim, > sctp_shutdown_event,sctp_sndrcvinfo,sctp_status,udp_opts] > 2> {ok,S} = gen_sctp:open([{sctp_peer_addr_params, > #sctp_paddrparams{sackdelay=400,flags=[sackdelay_enable]}}]). > {ok,#Port<0.456>} > 3> gen_sctp:connect(S, localhost, 32850, []). > {ok,#sctp_assoc_change{state = comm_up,error = 0, > outbound_streams = 10,inbound_streams = 10, > assoc_id = 1}} > 4> inet:setopts(S, [{sctp_peer_addr_params, > #sctp_paddrparams{sackdelay=500,flags=[sackdelay_enable],assoc_id=1,address={loopback,32850}}}]). > ok > 5> inet:getopts(S, [sctp_peer_addr_params]). > {ok,[{sctp_peer_addr_params, > #sctp_paddrparams{ > assoc_id = 0, > address = {{0,0,0,0},0}, > hbinterval = 30000,pathmaxrxt = 5,pathmtu = 0, > sackdelay = 400, > flags = [hb_enable,pmtud_enable,sackdelay_enable]}}]} > 6> inet:getopts(S, [{sctp_peer_addr_params, > #sctp_paddrparams{assoc_id=1,address={loopback,32850}}}]). > {ok,[{sctp_peer_addr_params, > #sctp_paddrparams{ > assoc_id = 1, > address = {{127,0,0,1},32850}, > hbinterval = 30000,pathmaxrxt = 5,pathmtu = 16436, > sackdelay = 500, > flags = [hb_enable,pmtud_enable,sackdelay_enable]}}]} > > > > > > > Thanks > > > > > _______________________________________________ > > > erlang-questions mailing list > > > erlang-questions@REDACTED > > > http://www.erlang.org/mailman/listinfo/erlang-questions > > > > -- > > > > / Raimo Niskanen, Erlang/OTP, Ericsson AB > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions@REDACTED > > http://www.erlang.org/mailman/listinfo/erlang-questions > > -- > > / Raimo Niskanen, Erlang/OTP, Ericsson AB > -------------- next part -------------- An HTML attachment was scrubbed... URL: From raimo+erlang-questions@REDACTED Wed Jan 28 09:17:25 2009 From: raimo+erlang-questions@REDACTED (Raimo Niskanen) Date: Wed, 28 Jan 2009 09:17:25 +0100 Subject: [erlang-questions] profile question In-Reply-To: References: Message-ID: <20090128081725.GA5702@erix.ericsson.se> On Tue, Jan 27, 2009 at 11:00:10PM -0500, Kaiduan Xie wrote: > Hi, all, > > I have a question on how to find the hot spot of large base Erlang system. > For example, after running cprof.start(), cprof.pause(), cprof.analyze(), I > got the following results (only the first item is listed below), > > {1847012003, > [{io_lib_format,722457356, > [{{io_lib_format,pcount,2},109483111}, > {{io_lib_format,collect,2},109483111}, > {{io_lib_format,build,3},109483111}, > {{io_lib_format,iolist_to_chars,1},83312743}, > {{io_lib_format,indentation,2},60014886}, > {{io_lib_format,field_value,2},26618934}, > {{io_lib_format,field_value,3},17824836}, > {{io_lib_format,precision,2},17706522}, > {{io_lib_format,pad_char,2},17706522}, > {{io_lib_format,field_width,3},17706522}, > {{io_lib_format,field_width,2},17706522}, > {{io_lib_format,decr_pc,2},17706522}, > {{io_lib_format,control,7},17706522}, > {{io_lib_format,collect_cseq,2},17706522}, > {{io_lib_format,collect_cc,2},17706522}, > {{io_lib_format,print,7},14402937}, > {{io_lib_format,chars,2},8912422}, > {{io_lib_format,term,5},8912417}, > {{io_lib_format,min|...},8912416}, > {{io_lib_format|...},8912416}, > {{...}|...}, > {...}|...]}, > > So here comes the question, how can we find which part calls > (io_lib_format,pcount,2) most? I tried to use fprof(), but it seems that you > need to know the arguments of the function first. > > What is the best practice to address this problem? Or did I do something > wrong? No, you are on track. This is the curse of cprof - it only gives you the call count but with minimal strain on your system. The curse of fprof is that it gives you lots of information for the price of a very high system load. Now you can read some code. The module io_lib_format is an internal module for io_lib and io. So the user code calls either io:format/1,2,3, io:fwrite/1,2,3, io_lib:format/2 or io_lib:fwrite/2. You can search for those in your source and see which are suspicious. You can also hand craft a trace by tracing only the io and io_lib functions in the previous paragraph using the match spec function {caller}. This you might do with the dbg module, maybe some other trace tool, or write one yourself. That would give you an idea of who is to blame. > > Thanks, > > kaiduan > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions -- / Raimo Niskanen, Erlang/OTP, Ericsson AB From mikael.lixenstrand@REDACTED Wed Jan 28 10:20:25 2009 From: mikael.lixenstrand@REDACTED (Mikael Lixenstrand) Date: Wed, 28 Jan 2009 10:20:25 +0100 Subject: [erlang-questions] : sctp_peer_addr_params In-Reply-To: References: <20090122075351.GA622@erix.ericsson.se> <20090122105816.GA5043@erix.ericsson.se> Message-ID: I got another problem with some settings now that used to work with the unpatched R12B-0 {badarg,[{gen_sctp,open,[[{ip,{10,70,128,108}},{mode,binary},{active,false},{sctp_events,{sctp_event_subscribe,undefined,undefined,false,undefined,undefined,false,undefined,undefined}}]]} {sctp_events,#sctp_event_subscribe{address_event = false, shutdown_event=false} Not as big problem as before but might be something you are intrested in. / Mikael 2009/1/28 Mikael Lixenstrand > Thank you. > > This helped me a great deal. I had some compilation problems with R12B-5 > but when i solved that i worked perfect. > > / Mikael > > 2009/1/22 Raimo Niskanen > > > >> On Thu, Jan 22, 2009 at 08:53:51AM +0100, Raimo Niskanen wrote: >> > On Wed, Jan 21, 2009 at 07:52:56AM +0100, Mikael Lixenstrand wrote: >> > > I'm trying to change the sack delay in gen_sctp >> > > >> > > {ok,Socket} = gen_sctp:open([{ip, ServerIPAddress}, {port, >> ServerPort}] >> > > ++ [{sctp_peer_addr_params, #sctp_paddrparams{ assoc_id = 0, address >> = >> > > {ServerIPAddress ,ServerPort} ,sackdelay = 400}}, >> > > {mode, binary}, >> > > {active, false}, >> > > {sctp_events,#sctp_event_subscribe{address_event = false, >> > > shutdown_event=false}}]), >> > > >> > > I tried several approaches but with the same result: >> > > >> > > Error in process <0.7100.1> on node 'mikael@REDACTED' with exit value: >> > > >> {badarg,[{gen_sctp,open,[[{ip,{10,70,160,17}},{port,3868},{sctp_peer_addr_params,{sctp_paddrparams,0,{{10,70,160,17},3868},200,5,600,400,[]}},{mode,binary},{active,false},{sctp_events,{sctp_event_subscribe,undefined,undefined,false,undefined,undefined... >> > > >> > > I'm running R12B-0 on rhel 5.2 >> > > >> > >> > Congratulations, you have found a bug! >> > >> > You have dived down to the untested parts of the SCTP code. >> > It is still something we have left to do to write thorough >> > test cases for gen_sctp. Unfortunately there are a _lot_ >> > of options and functionality to test so it is a big task. >> > >> > Nevertheless.. >> > >> > The decoding in the inet driver for #sctp_paddrparams{address={IP,P}} >> > is wrong; it does not expect the address family byte that it gets >> > and detects a parameter length mismatch. >> > >> > I had a small patch yesterday, but I could not set default >> > sctp_peer_addr_params for future associations, so I started >> > to read the spec, and indeed it should be possible. >> > >> > So yesterdays 2 character patch of inet_drv.c now is a patch >> > for erts/configure.in, inet_drv.c and prim_inet.erl. I will >> > do some more testing and post a patch hopefully during the day. >> >> Here is the patch. Unfortunately it is a minimal path for the >> current development branch so it will not be applied cleanly >> to R12B-5 or any other released source. But applying it manually >> should be no problem for the initiated user. >> >> erts/configure.in: Spelling error `ssh_data' -> `ssf_data' >> To do this manually to its autoconf result erts/configure >> change all occurences of `ssh_data' to `ssf_data' while >> preserving case. I have searched and there are >> no false occurences. >> >> erts/emulator/drivers/common/inet_drv.c: >> Two changes of inet_set_address -> inet_set_faddress. >> A few changes of HAVE_SCTP_* -> HAVE_STRUCT_SCTP_*. >> Use the patch to find the places. >> >> erts/preloaded/src/prim_inet.erl: >> This file has moved in our development branch; >> I think it was in lib/kernerl/src in R12B-5. >> >> With these patches it appears to work. Note that it is the >> peers address and port you use in the option! To set it >> on future associations you must not specify the peer >> address or association id. This is now possible thanks >> to the prim_inet.erl patch. Without that patch you >> could use address={{0,0,0,0},0} and assoc_id=0. >> See http://tools.ietf.org/html/draft-ietf-tsvwg-sctpsocket-13#section-7 >> just before section 7.1, and >> http://tools.ietf.org/html/draft-ietf-tsvwg-sctpsocket-13#section-7.1.13 >> >> In one erlang shell: >> >> Erlang R13A (erts-5.7) [64-bit] [smp:4] [async-threads:0] >> [kernel-poll:false] >> >> Eshell V5.7 (abort with ^G) >> 1> gen_sctp:open([{ip,loopback}]). >> {ok,#Port<0.444>} >> 2> {ok,S} = v(-1). >> {ok,#Port<0.444>} >> 3> gen_sctp:listen(S, true). >> ok >> 4> inet:port(S). >> {ok,32850} >> >> And then the action in another erlang shell: >> >> Erlang R13A (erts-5.7) [64-bit] [smp:4] [async-threads:0] >> [kernel-poll:false] >> >> Eshell V5.7 (abort with ^G) >> 1> rr(inet). >> [connect_opts,hostent,listen_opts,sctp_adaptation_event, >> sctp_assoc_change,sctp_assoc_value,sctp_assocparams, >> sctp_event_subscribe,sctp_initmsg,sctp_opts, >> sctp_paddr_change,sctp_paddrinfo,sctp_paddrparams, >> sctp_pdapi_event,sctp_prim,sctp_remote_error,sctp_rtoinfo, >> sctp_send_failed,sctp_setadaptation,sctp_setpeerprim, >> sctp_shutdown_event,sctp_sndrcvinfo,sctp_status,udp_opts] >> 2> {ok,S} = gen_sctp:open([{sctp_peer_addr_params, >> #sctp_paddrparams{sackdelay=400,flags=[sackdelay_enable]}}]). >> {ok,#Port<0.456>} >> 3> gen_sctp:connect(S, localhost, 32850, []). >> {ok,#sctp_assoc_change{state = comm_up,error = 0, >> outbound_streams = 10,inbound_streams = 10, >> assoc_id = 1}} >> 4> inet:setopts(S, [{sctp_peer_addr_params, >> #sctp_paddrparams{sackdelay=500,flags=[sackdelay_enable],assoc_id=1,address={loopback,32850}}}]). >> ok >> 5> inet:getopts(S, [sctp_peer_addr_params]). >> {ok,[{sctp_peer_addr_params, >> #sctp_paddrparams{ >> assoc_id = 0, >> address = {{0,0,0,0},0}, >> hbinterval = 30000,pathmaxrxt = 5,pathmtu = 0, >> sackdelay = 400, >> flags = [hb_enable,pmtud_enable,sackdelay_enable]}}]} >> 6> inet:getopts(S, [{sctp_peer_addr_params, >> #sctp_paddrparams{assoc_id=1,address={loopback,32850}}}]). >> {ok,[{sctp_peer_addr_params, >> #sctp_paddrparams{ >> assoc_id = 1, >> address = {{127,0,0,1},32850}, >> hbinterval = 30000,pathmaxrxt = 5,pathmtu = 16436, >> sackdelay = 500, >> flags = [hb_enable,pmtud_enable,sackdelay_enable]}}]} >> >> >> > >> > > Thanks >> > >> > > _______________________________________________ >> > > erlang-questions mailing list >> > > erlang-questions@REDACTED >> > > http://www.erlang.org/mailman/listinfo/erlang-questions >> > >> > -- >> > >> > / Raimo Niskanen, Erlang/OTP, Ericsson AB >> > _______________________________________________ >> > erlang-questions mailing list >> > erlang-questions@REDACTED >> > http://www.erlang.org/mailman/listinfo/erlang-questions >> >> -- >> >> / Raimo Niskanen, Erlang/OTP, Ericsson AB >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From raimo+erlang-questions@REDACTED Wed Jan 28 11:13:45 2009 From: raimo+erlang-questions@REDACTED (Raimo Niskanen) Date: Wed, 28 Jan 2009 11:13:45 +0100 Subject: [erlang-questions] : : sctp_peer_addr_params In-Reply-To: References: <20090122075351.GA622@erix.ericsson.se> <20090122105816.GA5043@erix.ericsson.se> Message-ID: <20090128101345.GA7041@erix.ericsson.se> On Wed, Jan 28, 2009 at 10:20:25AM +0100, Mikael Lixenstrand wrote: > I got another problem with some settings now that used to work with the > unpatched R12B-0 > > {badarg,[{gen_sctp,open,[[{ip,{10,70,128,108}},{mode,binary},{active,false},{sctp_events,{sctp_event_subscribe,undefined,undefined,false,undefined,undefined,false,undefined,undefined}}]]} > > {sctp_events,#sctp_event_subscribe{address_event = false, > shutdown_event=false} > > Not as big problem as before but might be something you are intrested in. No problem, this time I can get away with blaiming the user (you), more or less :-) You are most probably running code that was compiled for R12B-0 (inet_sctp.hrl), that header file got a new field authentication_event in R12B-1. You need to recompile with the new header file. The {sctp_event_subscribe,...} tuple above is missing one element. The curse of compile time dependencies... > / Mikael > 2009/1/28 Mikael Lixenstrand > > > Thank you. > > > > This helped me a great deal. I had some compilation problems with R12B-5 > > but when i solved that i worked perfect. > > > > / Mikael > > > > 2009/1/22 Raimo Niskanen > > > > > > >> On Thu, Jan 22, 2009 at 08:53:51AM +0100, Raimo Niskanen wrote: > >> > On Wed, Jan 21, 2009 at 07:52:56AM +0100, Mikael Lixenstrand wrote: > >> > > I'm trying to change the sack delay in gen_sctp > >> > > > >> > > {ok,Socket} = gen_sctp:open([{ip, ServerIPAddress}, {port, > >> ServerPort}] > >> > > ++ [{sctp_peer_addr_params, #sctp_paddrparams{ assoc_id = 0, address > >> = > >> > > {ServerIPAddress ,ServerPort} ,sackdelay = 400}}, > >> > > {mode, binary}, > >> > > {active, false}, > >> > > {sctp_events,#sctp_event_subscribe{address_event = false, > >> > > shutdown_event=false}}]), > >> > > > >> > > I tried several approaches but with the same result: > >> > > > >> > > Error in process <0.7100.1> on node 'mikael@REDACTED' with exit value: > >> > > > >> {badarg,[{gen_sctp,open,[[{ip,{10,70,160,17}},{port,3868},{sctp_peer_addr_params,{sctp_paddrparams,0,{{10,70,160,17},3868},200,5,600,400,[]}},{mode,binary},{active,false},{sctp_events,{sctp_event_subscribe,undefined,undefined,false,undefined,undefined... > >> > > > >> > > I'm running R12B-0 on rhel 5.2 > >> > > > >> > > >> > Congratulations, you have found a bug! > >> > > >> > You have dived down to the untested parts of the SCTP code. > >> > It is still something we have left to do to write thorough > >> > test cases for gen_sctp. Unfortunately there are a _lot_ > >> > of options and functionality to test so it is a big task. > >> > > >> > Nevertheless.. > >> > > >> > The decoding in the inet driver for #sctp_paddrparams{address={IP,P}} > >> > is wrong; it does not expect the address family byte that it gets > >> > and detects a parameter length mismatch. > >> > > >> > I had a small patch yesterday, but I could not set default > >> > sctp_peer_addr_params for future associations, so I started > >> > to read the spec, and indeed it should be possible. > >> > > >> > So yesterdays 2 character patch of inet_drv.c now is a patch > >> > for erts/configure.in, inet_drv.c and prim_inet.erl. I will > >> > do some more testing and post a patch hopefully during the day. > >> > >> Here is the patch. Unfortunately it is a minimal path for the > >> current development branch so it will not be applied cleanly > >> to R12B-5 or any other released source. But applying it manually > >> should be no problem for the initiated user. > >> > >> erts/configure.in: Spelling error `ssh_data' -> `ssf_data' > >> To do this manually to its autoconf result erts/configure > >> change all occurences of `ssh_data' to `ssf_data' while > >> preserving case. I have searched and there are > >> no false occurences. > >> > >> erts/emulator/drivers/common/inet_drv.c: > >> Two changes of inet_set_address -> inet_set_faddress. > >> A few changes of HAVE_SCTP_* -> HAVE_STRUCT_SCTP_*. > >> Use the patch to find the places. > >> > >> erts/preloaded/src/prim_inet.erl: > >> This file has moved in our development branch; > >> I think it was in lib/kernerl/src in R12B-5. > >> > >> With these patches it appears to work. Note that it is the > >> peers address and port you use in the option! To set it > >> on future associations you must not specify the peer > >> address or association id. This is now possible thanks > >> to the prim_inet.erl patch. Without that patch you > >> could use address={{0,0,0,0},0} and assoc_id=0. > >> See http://tools.ietf.org/html/draft-ietf-tsvwg-sctpsocket-13#section-7 > >> just before section 7.1, and > >> http://tools.ietf.org/html/draft-ietf-tsvwg-sctpsocket-13#section-7.1.13 > >> > >> In one erlang shell: > >> > >> Erlang R13A (erts-5.7) [64-bit] [smp:4] [async-threads:0] > >> [kernel-poll:false] > >> > >> Eshell V5.7 (abort with ^G) > >> 1> gen_sctp:open([{ip,loopback}]). > >> {ok,#Port<0.444>} > >> 2> {ok,S} = v(-1). > >> {ok,#Port<0.444>} > >> 3> gen_sctp:listen(S, true). > >> ok > >> 4> inet:port(S). > >> {ok,32850} > >> > >> And then the action in another erlang shell: > >> > >> Erlang R13A (erts-5.7) [64-bit] [smp:4] [async-threads:0] > >> [kernel-poll:false] > >> > >> Eshell V5.7 (abort with ^G) > >> 1> rr(inet). > >> [connect_opts,hostent,listen_opts,sctp_adaptation_event, > >> sctp_assoc_change,sctp_assoc_value,sctp_assocparams, > >> sctp_event_subscribe,sctp_initmsg,sctp_opts, > >> sctp_paddr_change,sctp_paddrinfo,sctp_paddrparams, > >> sctp_pdapi_event,sctp_prim,sctp_remote_error,sctp_rtoinfo, > >> sctp_send_failed,sctp_setadaptation,sctp_setpeerprim, > >> sctp_shutdown_event,sctp_sndrcvinfo,sctp_status,udp_opts] > >> 2> {ok,S} = gen_sctp:open([{sctp_peer_addr_params, > >> #sctp_paddrparams{sackdelay=400,flags=[sackdelay_enable]}}]). > >> {ok,#Port<0.456>} > >> 3> gen_sctp:connect(S, localhost, 32850, []). > >> {ok,#sctp_assoc_change{state = comm_up,error = 0, > >> outbound_streams = 10,inbound_streams = 10, > >> assoc_id = 1}} > >> 4> inet:setopts(S, [{sctp_peer_addr_params, > >> #sctp_paddrparams{sackdelay=500,flags=[sackdelay_enable],assoc_id=1,address={loopback,32850}}}]). > >> ok > >> 5> inet:getopts(S, [sctp_peer_addr_params]). > >> {ok,[{sctp_peer_addr_params, > >> #sctp_paddrparams{ > >> assoc_id = 0, > >> address = {{0,0,0,0},0}, > >> hbinterval = 30000,pathmaxrxt = 5,pathmtu = 0, > >> sackdelay = 400, > >> flags = [hb_enable,pmtud_enable,sackdelay_enable]}}]} > >> 6> inet:getopts(S, [{sctp_peer_addr_params, > >> #sctp_paddrparams{assoc_id=1,address={loopback,32850}}}]). > >> {ok,[{sctp_peer_addr_params, > >> #sctp_paddrparams{ > >> assoc_id = 1, > >> address = {{127,0,0,1},32850}, > >> hbinterval = 30000,pathmaxrxt = 5,pathmtu = 16436, > >> sackdelay = 500, > >> flags = [hb_enable,pmtud_enable,sackdelay_enable]}}]} > >> > >> > >> > > >> > > Thanks > >> > > >> > > _______________________________________________ > >> > > erlang-questions mailing list > >> > > erlang-questions@REDACTED > >> > > http://www.erlang.org/mailman/listinfo/erlang-questions > >> > > >> > -- > >> > > >> > / Raimo Niskanen, Erlang/OTP, Ericsson AB > >> > _______________________________________________ > >> > erlang-questions mailing list > >> > erlang-questions@REDACTED > >> > http://www.erlang.org/mailman/listinfo/erlang-questions > >> > >> -- > >> > >> / Raimo Niskanen, Erlang/OTP, Ericsson AB > >> > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions -- / Raimo Niskanen, Erlang/OTP, Ericsson AB From steven.charles.davis@REDACTED Wed Jan 28 12:58:38 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Wed, 28 Jan 2009 05:58:38 -0600 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: References: <497F9ABB.4030905@gmail.com> <497FA6B1.5060809@gmail.com> Message-ID: <4980486E.9030603@gmail.com> Thanks, both - interesting stuff. However, since I'm too lazy to write test code, I'm definitely too lazy to read much about writing test code and even less likely to bother to learn a whole framework. I have my hands/head full learning the Erlang/OTP libraries as it is. All I want to say is, e.g. hex(4) = "4" ...and be done with it forever (unless I break my code such that hex(4) is no longer "4"). I just can't be doing with "assert", "assert_ne" and all that BlahUnit stuff bloating out my code (and head). As a result, you've convinced me that my simple experiment is actually MUCH TOO COMPLICATED!! It's inspired me to try another version of "utest" that does stuff more like the following: 1) For the test suite, drop the idea of a test spec file and just pull that data from the existing .app file (since I already had to write that). I can then figure out what modules to test and what dependencies to run as well as grab all the info stuff. So for the user... --->>> Linecount: 0, Filecount: 0. 2) Have utest look for the module test cases as mymodule.test files which I'll probably dump into an app subfolder called...um... "test". -->>> Linecount: 1 per test, Filecount: 1 TEXT file per module 3) Make the syntax of the test (text) files as close to erlang semantically as possible without being too sensitive to syntax... that way I barely have to change brain-gear from coding to testing and so I may even bother to add test cases (i.e. lines) to the test file as i go along... ----- my_module.test ---- hex(4) = "4" hex(5) /= "6" hex(3) =:= "3" dehex($3) > 20 ..etc... Since I'm using erlang operators I might just as well allow boolean operators too... and, or, orelse, andalso... and then we can start getting fancy with our test cases... start(80) = {ok, _} and get_port() =:= 80 and myapp_control:get_started() = 1 I guess I could make utest a parameterized module to set the config up, so all in all a console session could then end up looking something like this... 1>Test = utest:new(myapp, terse). 2>Test:run(). [FAIL] my_module:hex(4) -> 52 EXPECTED "4" {fail, [{tests, 294}, (errors, 1}]} 3>c(my_module). {ok, my_module} 4>Test:run(). {ok, [{tests, 294}, (errors, 0}]} 5> What do you think? :) /s From erlang@REDACTED Wed Jan 28 13:16:52 2009 From: erlang@REDACTED (Joe Armstrong) Date: Wed, 28 Jan 2009 13:16:52 +0100 Subject: [erlang-questions] Lightweight test driven development and unit testing Message-ID: <9b08084c0901280416o2285d17et95abeb878989ec23@mail.gmail.com> The question of unit testing often crops up in this group. I've written a short article describing how I do test driven development in Erlang. http://armstrongonsoftware.blogspot.com/2009/01/micro-lightweight-unit-testing.html This follows Uncle Bobs' advice on test driven development. http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd I heard Bob Martin give a lecture at the 2008 QCon in London and felt inspired to work in the way he suggests. /Joe Armstrong From watson.timothy@REDACTED Wed Jan 28 13:31:43 2009 From: watson.timothy@REDACTED (Tim Watson) Date: Wed, 28 Jan 2009 12:31:43 +0000 Subject: [erlang-questions] I Hate Unit Testing... Message-ID: <8fa878b90901280431sb9dd1e2o6a1ff51cd4f05dd9@mail.gmail.com> > Familiarity is utmost so I just borrowed/subverted the term structure > used for .app files, like this... > ----- my_app.test ------ > %% utest test specification > {utest, my_app, > [{description, ""}, > {version, "0.1"}, > {flags, [verbose]}, %% only [verbose] or [] supported > {applications, [kernel, stdlib, crypto]}, %% dependencies > {tests, [ > % Tests are specified as Module, Function, ArgumentList, ExpectedResult > % i.e. {M, F, A, R} > {my_module, hex, [2], "2"}, > {my_module, hex, [255], "ff"}, > {my_module, hex, [55551], "d8ff"} > ]} > ]}. > I do like the declarative approach to defining tests. In Haskell, the QuickCheck tool assumes a similar idea (http://www.haskell.org/haskellwiki/QuickCheck_as_a_test_set_generator), albeit less tied to specific inputs/outputs. One thing I would like to make note of, is that this doesn't actually test the parts of your code that are likely to go wrong. In a language/platform that provides referential transparency, you can certainly provide 'proofs' about the behavior of your *pure* functions and have these automatically asserted/verified. The more problematic area, and the one on in which you're more likely to run in to issues, is that of impure functions (i.e. those with side effects). Hitting the file system, network I/O, talking to other (erlang) nodes and most importantly I would think - processes sending and receiving messages and responding to them. In this area, all kinds of things can happen - what order do messages come in vs. get processed, how are servers/services contacted and 'looked up', is registration synchronized correctly, do gen_servers get started up in the correct order, etc. These latter points seem more likely candidates for testing IMO, and having a "mock gen_server" and other associated tools at your disposal make this much easier. From ext@REDACTED Wed Jan 28 13:40:15 2009 From: ext@REDACTED (David Sveningsson) Date: Wed, 28 Jan 2009 13:40:15 +0100 Subject: [erlang-questions] erl_parse:abstract on a fun Message-ID: <4980522F.9000803@sidvind.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I recently ran into an issue where I am calling erl_parse:abstract on a fun which fails with function_clause. What I need is to convert any term to abstract form and in this case it was a stacktrace containing a fun. Now I see two alternatives for solving this: 1) Try to convert the fun to abstract form for and wrap it somehow. 2) Replace the fun with erlang:fun_to_list/1 or similar, and live having the "string representation". Either way seems a bit difficult as it would involve traversing an unknown term and replacing funs as needed. Is this possible to do? Or is there a simpler way? -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkmAUi8ACgkQ6pa1H/H5pqXsQACfaFQCUueG6O66kpHzS3iYynXR tlcAoOHYQckpDWX+8OlQ3dHmyuS94bBv =PCO6 -----END PGP SIGNATURE----- From richardc@REDACTED Wed Jan 28 13:45:56 2009 From: richardc@REDACTED (Richard Carlsson) Date: Wed, 28 Jan 2009 13:45:56 +0100 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: <4980486E.9030603@gmail.com> References: <497F9ABB.4030905@gmail.com> <497FA6B1.5060809@gmail.com> <4980486E.9030603@gmail.com> Message-ID: <49805384.6090707@it.uu.se> Steve Davis wrote: > What do you think? :) Honestly? You'll be adding features until you have yet another framework. As an alternative, here is a suggestion for the simplest possible use of eunit for the terminally lazy: If you have a module foo.erl (and you only want to test its exported functions), create another module foo_tests.erl (under src/ or test/ or wherever, depending on your build structure; just see to it that the foo_tests.beam file is available in your Erlang code path). In foo_tests.erl, write: -include_lib("eunit/include/eunit.hrl"). my_test() -> "4" = hex(4), true = (hex(5) =/= "6"), true = (hex(3) =:= "3"), true = (dehex($3) > 20). and so on. You just use plain Erlang code and write it so that it crashes (raises an exception, such as a 'badmatch' caused by '=') if the test does not succeed. Learning curve: practically flat. Just name your test functions ..._test(), and the -include_lib() declaration shown above will do all the rest for you: just compile. To run the tests, call eunit:test(foo) - it will look for the foo_tests module as well as any tests in foo itself if you have any. (You can also say eunit:test(foo_tests) if you want to skip those in foo.) You'll notice that it becomes easier to spot the test that failed if you don't put them all in the same test function, so separating them a bit will help: first_test() -> ... second_test() -> ... third_test() -> ... etc. Each function can test as much or as little as you like. >From there on, you can learn more features of eunit as you go. The first thing you might want to use is the ?assertMatch() and ?assert() macros, so that you can do the same kind of tests as above, but with much more informative error reports. Just write: my_test() -> ?assertMatch("4", hex(4)) %% match pattern against expression ?assert(hex(5) =/= "6"), %% test for true or false ?assert(hex(3) =:= "3"), ?assert(dehex($3) > 20). Try it and you'll see the difference when you trigger an error. This will get you pretty far, and you can still be as lazy as you want. Of course, any suggestions that might help make eunit even easier to use are very welcome, /Richard From masklinn@REDACTED Wed Jan 28 13:51:57 2009 From: masklinn@REDACTED (Masklinn) Date: Wed, 28 Jan 2009 13:51:57 +0100 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: <8fa878b90901280431sb9dd1e2o6a1ff51cd4f05dd9@mail.gmail.com> References: <8fa878b90901280431sb9dd1e2o6a1ff51cd4f05dd9@mail.gmail.com> Message-ID: <23FBDC8A-45C1-45B5-AB15-4AD3098CA5BA@masklinn.net> On 28 Jan 2009, at 13:31 , Tim Watson wrote: >> Familiarity is utmost so I just borrowed/subverted the term structure >> used for .app files, like this... >> ----- my_app.test ------ >> %% utest test specification >> {utest, my_app, >> [{description, ""}, >> {version, "0.1"}, >> {flags, [verbose]}, %% only [verbose] or [] supported >> {applications, [kernel, stdlib, crypto]}, %% dependencies >> {tests, [ >> % Tests are specified as Module, Function, ArgumentList, >> ExpectedResult >> % i.e. {M, F, A, R} >> {my_module, hex, [2], "2"}, >> {my_module, hex, [255], "ff"}, >> {my_module, hex, [55551], "d8ff"} >> ]} >> ]}. >> > > I do like the declarative approach to defining tests. In Haskell, the > QuickCheck tool assumes a similar idea > (http://www.haskell.org/haskellwiki/ > QuickCheck_as_a_test_set_generator), > albeit less tied to specific inputs/outputs. There is an Erlang QuickCheck, but it's a commercial product by Quviq. From steven.charles.davis@REDACTED Wed Jan 28 15:12:29 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Wed, 28 Jan 2009 08:12:29 -0600 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: <49805384.6090707@it.uu.se> References: <497F9ABB.4030905@gmail.com> <497FA6B1.5060809@gmail.com> <4980486E.9030603@gmail.com> <49805384.6090707@it.uu.se> Message-ID: <498067CD.6020904@gmail.com> Hi Richard, Thanks very much for your thoughts. Richard Carlsson wrote: > Honestly? Honesty is always at the heart of the most useful feedback! > simplest possible use of eunit for the terminally lazy... I've used JUnit and NUnit and indeed EUnit too. The real issue is "how much" I use them... or don't. All these frameworks are super-powerful and well featured BUT they all require coding (including Quviq's solution). That *is the barrier* to me (and apparently most coders) bothering with unit tests when stuck in the heat of things. I really am that lazy (or maybe just that stupid) that I don't want to change gear into writing (and debugging) a test module. Even when I do actually pull my finger out, I generally delay doing it by which time I have forgotten half of what the module was really intended to do (i.e. the detail of the spec), and so I have to remember all that and it becomes a big chore. OTOH, I *may* be bothered to add to a text file: hex(4) = "4" But from experience, I know that I'll just not bother to write: -module(test_myapp). -include_lib("eunit/include/eunit.hrl"). my_test() -> "4" = hex(4), ...etc On another note, someone mentioned Cucumber... well hmmph. That's all very nice for your corporate stakeholders, but it's waaaaayyy too verbose for any developer I know to be bothered with. With respect, /s From vladdu55@REDACTED Wed Jan 28 15:26:36 2009 From: vladdu55@REDACTED (Vlad Dumitrescu) Date: Wed, 28 Jan 2009 15:26:36 +0100 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: <498067CD.6020904@gmail.com> References: <497F9ABB.4030905@gmail.com> <497FA6B1.5060809@gmail.com> <4980486E.9030603@gmail.com> <49805384.6090707@it.uu.se> <498067CD.6020904@gmail.com> Message-ID: <95be1d3b0901280626t14e8507hfb43672000be9a21@mail.gmail.com> Hi, Sorry if I'm just being obtuse... On Wed, Jan 28, 2009 at 15:12, Steve Davis wrote: > OTOH, I *may* be bothered to add to a text file: > hex(4) = "4" > > But from experience, I know that I'll just not bother to write: > -module(test_myapp). > -include_lib("eunit/include/eunit.hrl"). > > my_test() -> > "4" = hex(4), In the simplest case that Richard described, the top three rows are only to be written once. Many environments (maybe only vi doesn't?) may be taught to enter that at the press of a key combination. The actual data will be almost the same, only one extra comma... The only difference is for the examples you don't mention above, for example hex(5) =/= "6" vs true = (hex(5) =/= "6") Is that so big a difference? best regards, Vlad From steven.charles.davis@REDACTED Wed Jan 28 15:40:38 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Wed, 28 Jan 2009 06:40:38 -0800 (PST) Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: <8fa878b90901280431sb9dd1e2o6a1ff51cd4f05dd9@mail.gmail.com> References: <8fa878b90901280431sb9dd1e2o6a1ff51cd4f05dd9@mail.gmail.com> Message-ID: <2812075d-1b28-40b8-b5e6-7cd1412c91f4@v39g2000pro.googlegroups.com> Yep, interesting and valid points, and there's a distinction to be made. My suggestion is for Unit Tests and so really doesn't cover System/ Subsystem Tests where the issues you describe will certainly become major considerations. For that kind of testing, I have other ideas cooking around - in particular there's big inspiration to be had from Joe's UBF contracts... BR, /s On Jan 28, 6:31?am, Tim Watson wrote: > One thing I would like to make note of, is that this doesn't actually > test the parts of your code that are likely to go wrong. In a > language/platform that provides referential transparency, you can > certainly provide 'proofs' about the behavior of your *pure* functions > and have these automatically asserted/verified. The more problematic > area, and the one on in which you're more likely to run in to issues, > is that of impure functions (i.e. those with side effects). Hitting > the file system, network I/O, talking to other (erlang) nodes and most > importantly I would think - processes sending and receiving messages > and responding to them. In this area, all kinds of things can happen - > what order do messages come in vs. get processed, how are > servers/services contacted and 'looked up', is registration > synchronized correctly, do gen_servers get started up in the correct > order, etc. These latter points seem more likely candidates for > testing IMO, and having a "mock gen_server" and other associated tools > at your disposal make this much easier. > _______________________________________________ > erlang-questions mailing list > erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions From dan.milstein@REDACTED Wed Jan 28 15:30:46 2009 From: dan.milstein@REDACTED (Dan Milstein) Date: Wed, 28 Jan 2009 09:30:46 -0500 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: <498067CD.6020904@gmail.com> References: <497F9ABB.4030905@gmail.com> <497FA6B1.5060809@gmail.com> <4980486E.9030603@gmail.com> <49805384.6090707@it.uu.se> <498067CD.6020904@gmail.com> Message-ID: <4A1904D8-73FC-4667-9E4B-7C91ACE816E4@appingo.com> Maybe I'm even lazier, but I just write my tests in the same file as the module under test, so then the boilerplate is (within the file you're testing, and therefore already compiling): -include_lib("eunit/include/eunit.hrl"). So then, when you re-compile the module, instead of, well, whatever else you were doing, just do: > module:test(). [If putting tests in that same module is somehow Wrong And Terrible, world, please let me know why... ] In addition, eunit's ?debugVal() macro is incredibly useful -- it's like the keystroke-friendly print stmt that Erlang doesn't have. In other words, one of your tests fail -- want to look at what's going on inside the middle of a function somewhere? Just wrap a line in ? debugVal() and you get a *great* info message, with full line number and everything. It's so useful I sometimes -include eunit just to get access to that during my dev process. Just my $.02 as a test-obsessed programmer: eunit is as impressively close to the ideal of As Simple As Possible as anything I've ever seen. (Speaking of which, Richard, eunit is absolutely the bomb -- I adore it). -Dan M On Jan 28, 2009, at 9:12 AM, Steve Davis wrote: > Hi Richard, > > Thanks very much for your thoughts. > > Richard Carlsson wrote: >> Honestly? > > Honesty is always at the heart of the most useful feedback! > >> simplest possible use of eunit for the terminally lazy... > > I've used JUnit and NUnit and indeed EUnit too. The real issue is "how > much" I use them... or don't. All these frameworks are super-powerful > and well featured BUT they all require coding (including Quviq's > solution). > > That *is the barrier* to me (and apparently most coders) bothering > with > unit tests when stuck in the heat of things. > > I really am that lazy (or maybe just that stupid) that I don't want to > change gear into writing (and debugging) a test module. Even when I do > actually pull my finger out, I generally delay doing it by which > time I > have forgotten half of what the module was really intended to do (i.e. > the detail of the spec), and so I have to remember all that and it > becomes a big chore. > > OTOH, I *may* be bothered to add to a text file: > hex(4) = "4" > > But from experience, I know that I'll just not bother to write: > -module(test_myapp). > -include_lib("eunit/include/eunit.hrl"). > > my_test() -> > "4" = hex(4), > ...etc > > On another note, someone mentioned Cucumber... well hmmph. That's all > very nice for your corporate stakeholders, but it's waaaaayyy too > verbose for any developer I know to be bothered with. > > With respect, > > /s > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From richardc@REDACTED Wed Jan 28 15:44:41 2009 From: richardc@REDACTED (Richard Carlsson) Date: Wed, 28 Jan 2009 15:44:41 +0100 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: <498067CD.6020904@gmail.com> References: <497F9ABB.4030905@gmail.com> <497FA6B1.5060809@gmail.com> <4980486E.9030603@gmail.com> <49805384.6090707@it.uu.se> <498067CD.6020904@gmail.com> Message-ID: <49806F59.70005@it.uu.se> Steve Davis wrote: > I really am that lazy (or maybe just that stupid) that I don't want to > change gear into writing (and debugging) a test module. Even when I do > actually pull my finger out, I generally delay doing it by which time I > have forgotten half of what the module was really intended to do (i.e. > the detail of the spec), and so I have to remember all that and it > becomes a big chore. > > OTOH, I *may* be bothered to add to a text file: > hex(4) = "4" > > But from experience, I know that I'll just not bother to write: > -module(test_myapp). > -include_lib("eunit/include/eunit.hrl"). > > my_test() -> > "4" = hex(4), > ...etc Hmm. But if you compare the approaches, they are almost the same. In both cases you create a file to keep the tests in; in both cases you still have to write the actual assertions/properties; and in both cases you have to change gear, if ever so little. Writing those two measly extra lines at the top of the file (when you create it) becomes less of an obstacle once you've done it a couple of times. What you _get_ from doing this, however, is much more flexibility in what sort of properties you can test. If you're not actually writing code, but merely lists of inputs and outputs, you cannot do any computations. (That's when you might start to "extend" the input syntax with expressions, and end up with yet another language...). And yet, your .app-file examples are practically as verbose as just writing the tests with eunit. So really, I don't see where you will be able to save any effort or mental task switching here. If you want to save the step of creating a separate file, then by all means place the tests directly in the module you're writing, as you think of them. Just a simple line of another_test() -> ?assert(myreverse("abc") =:= "cba"). and you're done. That's about as much work as inserting a comment. Add the include directive while you're having some coffee, compile, and run the tests. However, some direct eunit support for reading a comma-separated list of functions and input/output values could be handy. I'll add that to my feature list. /Richard From chsu79@REDACTED Wed Jan 28 15:37:58 2009 From: chsu79@REDACTED (Christian) Date: Wed, 28 Jan 2009 15:37:58 +0100 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: <498067CD.6020904@gmail.com> References: <497F9ABB.4030905@gmail.com> <497FA6B1.5060809@gmail.com> <4980486E.9030603@gmail.com> <49805384.6090707@it.uu.se> <498067CD.6020904@gmail.com> Message-ID: On Wed, Jan 28, 2009 at 15:12, Steve Davis wrote: > > > simplest possible use of eunit for the terminally lazy... > > I've used JUnit and NUnit and indeed EUnit too. The real issue is "how > much" I use them... or don't. All these frameworks are super-powerful > and well featured BUT they all require coding (including Quviq's solution). > > That *is the barrier* to me (and apparently most coders) bothering with > unit tests when stuck in the heat of things. So you intend to write a new testing framework for each project when stuck in this heat-of-things? Later when you need to supply a hot-fix and unit-test that, in the head-of-things, you have this old undocumented, semi-complete framework to dig up and understand? *Sounds great* :-] eunit is simple. no where close to test_server and ct in complexity. eunit is now included in otp. eunit is therefore, or will become, the "defacto standard" for unit tests. To richard: the documentation of eunit is great. But it is that kind of documentation that is great after you "have seen eunit in the wild, and understood it". The docs answers all the questions then. I remember feeling a little bit confused on how it should be used in a typical project. I believe it is a case of how cognition begins with understanding the concrete, first then moves on to the abstract. Currently I have my test/ dir compile all source from ../src/* into ./ using an Emakefile that sets TEST to true. This is because I compile production code without the eunit tests auto-exported, and thus i have my eunit include and test-functions wrapped in -ifdef-endifs. From steven.charles.davis@REDACTED Wed Jan 28 16:04:42 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Wed, 28 Jan 2009 09:04:42 -0600 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: <49806F59.70005@it.uu.se> References: <497F9ABB.4030905@gmail.com> <497FA6B1.5060809@gmail.com> <4980486E.9030603@gmail.com> <49805384.6090707@it.uu.se> <498067CD.6020904@gmail.com> <49806F59.70005@it.uu.se> Message-ID: <4980740A.7030302@gmail.com> Richard Carlsson wrote: > Hmm. But if you compare the approaches, they are almost the same. Almost, but significantly... not quite. No compile step. > you might start to "extend" the input > syntax with expressions, and end up with yet another language...). Hopefully not. See my post from 6am that I believe shows why... > And yet, your .app-file examples are practically as verbose as just > writing the tests with eunit. ...in that post I also ditched the idea of the app-style config file. > If you want to save the step of creating a separate file, then by > all means place the tests directly in the module you're writing, ...that could be a bit of a problem for version control (and code-bloat). Imagine wishing to add new tests after delivery (and the customer bitching about a bug you hadn't considered) ...how would you test their *same* build/codebase? All in all, test code *inside* the module is a **very-big-and-bad** idea... even evil. > However, some direct eunit support for reading a comma-separated list > of functions and input/output values could be handy. I'll add that to > my feature list. Very cool! BR, Steve From richardc@REDACTED Wed Jan 28 16:13:41 2009 From: richardc@REDACTED (Richard Carlsson) Date: Wed, 28 Jan 2009 16:13:41 +0100 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: <4A1904D8-73FC-4667-9E4B-7C91ACE816E4@appingo.com> References: <497F9ABB.4030905@gmail.com> <497FA6B1.5060809@gmail.com> <4980486E.9030603@gmail.com> <49805384.6090707@it.uu.se> <498067CD.6020904@gmail.com> <4A1904D8-73FC-4667-9E4B-7C91ACE816E4@appingo.com> Message-ID: <49807625.5060904@it.uu.se> Dan Milstein wrote: > [If putting tests in that same module is somehow Wrong And Terrible, > world, please let me know why... ] How terrible it is depends on who you ask, but: A) when you get a lot of test code, it tends to clutter up the module - but for testing the nonexported stuff, it must be in the same module (if you get a big chunk of fairly independent code with lots of tests, it is probably a sign that it should be broken out into another module); and B) it means it's not real "black-box" testing, hence it's instictively frowned upon by some - the problem being that you might not test the right things because you can peek at how it seems to work. It's mostly a matter of knowing what you are doing (and what you might possibly not be doing). > In addition, eunit's ?debugVal() macro is incredibly useful -- it's > like the keystroke-friendly print stmt that Erlang doesn't have. In > other words, one of your tests fail -- want to look at what's going on > inside the middle of a function somewhere? Just wrap a line in ? > debugVal() and you get a *great* info message, with full line number > and everything. It's so useful I sometimes -include eunit just to get > access to that during my dev process. I was thinking that the debug macros and the plain assert macros should probably be made available directly from their own respective header files as well, but haven't got around to doing that yet. > Just my $.02 as a test-obsessed programmer: eunit is as impressively > close to the ideal of As Simple As Possible as anything I've ever seen. > > (Speaking of which, Richard, eunit is absolutely the bomb -- I adore > it). Thanks! :-) I'm currently trying to rework some of the internals regarding the handling of progress information, timeouts, etc., and it's pretty tricky. In fact, eunit might look simple on the outside, but the process handling is definitely the hairiest concurrent stuff I've ever written - there's a lot of effort needed to be as transparent as possible with respect to the code under test. My brain hurts! /Richard From steven.charles.davis@REDACTED Wed Jan 28 16:14:25 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Wed, 28 Jan 2009 07:14:25 -0800 (PST) Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: References: <497F9ABB.4030905@gmail.com> <497FA6B1.5060809@gmail.com> <4980486E.9030603@gmail.com> <49805384.6090707@it.uu.se> <498067CD.6020904@gmail.com> Message-ID: <9ebe6564-b9b6-4a34-ba17-dda75d31123e@a12g2000pro.googlegroups.com> On Jan 28, 8:37?am, Christian wrote: > So you intend to write a new testing framework for each project when > stuck in this heat-of-things? Not at all - where did that one come from? :) It's just one text file per module. /s From r.b.lists@REDACTED Wed Jan 28 15:23:12 2009 From: r.b.lists@REDACTED (Roland Braito) Date: Wed, 28 Jan 2009 15:23:12 +0100 Subject: [erlang-questions] Lightweight test driven development and unit testing In-Reply-To: <9b08084c0901280416o2285d17et95abeb878989ec23@mail.gmail.com> References: <9b08084c0901280416o2285d17et95abeb878989ec23@mail.gmail.com> Message-ID: <20090128142312.79000@gmx.net> Thanks for that contribution! It is often the simple rules which have the most positive impact. Best regards, Roland -------- Original-Nachricht -------- > Datum: Wed, 28 Jan 2009 13:16:52 +0100 > Von: Joe Armstrong > An: erlang-questions > Betreff: [erlang-questions] Lightweight test driven development and unit testing > The question of unit testing often crops up in this group. > > I've written a short article describing how I do test driven > development in Erlang. > > http://armstrongonsoftware.blogspot.com/2009/01/micro-lightweight-unit-testing.html > > This follows Uncle Bobs' advice on test driven development. > > http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd > > I heard Bob Martin give a lecture at the 2008 QCon in London and > felt inspired to work in the way he suggests. > > /Joe Armstrong > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions -- Psssst! Schon vom neuen GMX MultiMessenger geh?rt? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger From devdoer2@REDACTED Wed Jan 28 17:03:01 2009 From: devdoer2@REDACTED (devdoer bird) Date: Thu, 29 Jan 2009 00:03:01 +0800 Subject: [erlang-questions] How to config mochiweb to support gzip/deflate encoding? Message-ID: HI: Any one konw how to config mochiweb to support gzip/deflate encoding? Or there's any patch to add this function. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From richardc@REDACTED Wed Jan 28 17:46:47 2009 From: richardc@REDACTED (Richard Carlsson) Date: Wed, 28 Jan 2009 17:46:47 +0100 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: <4980740A.7030302@gmail.com> References: <497F9ABB.4030905@gmail.com> <497FA6B1.5060809@gmail.com> <4980486E.9030603@gmail.com> <49805384.6090707@it.uu.se> <498067CD.6020904@gmail.com> <49806F59.70005@it.uu.se> <4980740A.7030302@gmail.com> Message-ID: <49808BF7.7090503@it.uu.se> Steve Davis wrote: > Almost, but significantly... not quite. No compile step. Hm, well, you've heard of this nifty thing called "make"? But agreed, it is an additional step. >> If you want to save the step of creating a separate file, then by >> all means place the tests directly in the module you're writing, > > ...that could be a bit of a problem for version control (and > code-bloat). Imagine wishing to add new tests after delivery (and the > customer bitching about a bug you hadn't considered) ...how would you > test their *same* build/codebase? All in all, test code *inside* the > module is a **very-big-and-bad** idea... even evil. Yes. I generally recommend that the functions that test your exported API are placed in a separate module, but it tends to depend on what kind of software you are writing, how you ship it to customers, etc. >> However, some direct eunit support for reading a comma-separated list >> of functions and input/output values could be handy. I'll add that to >> my feature list. > > Very cool! One thing, though: In my opinion, the best kind of tests are those that avoid hard-coded values (apart from specific boundary values), and instead express the properties in terms of "doing this should give the same result as doing that", and similar. The problem with a table (both as a sequence of copy/pasted microtests in the code, with a few selected inputs and results, or as a file that lists the corresponding inputs/results), is that unless you can quote a good reference document for those values (such as a physics handbook), they have a tendency to get modified over time, to make the tests pass, and the whys and wherefores of those changes get quickly forgotten. It is much more difficult to tweak a test on a whim to make it pass, if the test just says something like "this algorithm should give the same result as that one from the standard library", or "for a bunch of randomly selected inputs n in the range [x,y] where x References: <497F9ABB.4030905@gmail.com> <497FA6B1.5060809@gmail.com> <4980486E.9030603@gmail.com> <49805384.6090707@it.uu.se> <498067CD.6020904@gmail.com> <49806F59.70005@it.uu.se> <4980740A.7030302@gmail.com> <49808BF7.7090503@it.uu.se> Message-ID: <32b2acd6-7c22-41e2-8fd1-6028e5ddc7bd@y1g2000pra.googlegroups.com> Hi Richard, Thank you for that wonderfully thoughtful and thought-provoking response! BR /s From twoggle@REDACTED Wed Jan 28 18:50:35 2009 From: twoggle@REDACTED (Tim Fletcher) Date: Wed, 28 Jan 2009 09:50:35 -0800 (PST) Subject: [erlang-questions] How to config mochiweb to support gzip/deflate encoding? In-Reply-To: References: Message-ID: > Any one konw how to config ?mochiweb to support gzip/deflate encoding? Or > there's any patch to add this function. http://groups.google.com/group/mochiweb/browse_thread/thread/bb5c1816cdb9a374 From kaiduanx@REDACTED Wed Jan 28 18:55:43 2009 From: kaiduanx@REDACTED (Kaiduan Xie) Date: Wed, 28 Jan 2009 12:55:43 -0500 Subject: [erlang-questions] profile question In-Reply-To: <20090128081725.GA5702@erix.ericsson.se> References: <20090128081725.GA5702@erix.ericsson.se> Message-ID: Thanks a lot, Raimo for the help. More questions, 1. From my understanding, Erlang trace is not targeted to find performance bottleneck, it is used to help you understand how function is executed. I can not figure out how to use trace to find which function calls the io_lib_format:pcount in my case most. (In my case, io_lib:format is dispersed in the code almost everywhere.) 2. For fprof, how to profile a function without specifying the arguments? For example, I want to fprof io_lib:format, but I want to profile all calls on io_lib:format regardless of the real arguments. 3. In C, we can use gprof to achieve what I want in 2). Although gprof increases the system load substantially. What is the counter-part of gprof in Erlang. 4. What is the tool you guys in Ericsson use to profile a high-load system without degrading the performance dramatically, at the same time, we can still get gprof like output? Thanks, kaiduan On Wed, Jan 28, 2009 at 3:17 AM, Raimo Niskanen < raimo+erlang-questions@REDACTED > wrote: > On Tue, Jan 27, 2009 at 11:00:10PM -0500, Kaiduan Xie wrote: > > Hi, all, > > > > I have a question on how to find the hot spot of large base Erlang > system. > > For example, after running cprof.start(), cprof.pause(), cprof.analyze(), > I > > got the following results (only the first item is listed below), > > > > {1847012003, > > [{io_lib_format,722457356, > > [{{io_lib_format,pcount,2},109483111}, > > {{io_lib_format,collect,2},109483111}, > > {{io_lib_format,build,3},109483111}, > > {{io_lib_format,iolist_to_chars,1},83312743}, > > {{io_lib_format,indentation,2},60014886}, > > {{io_lib_format,field_value,2},26618934}, > > {{io_lib_format,field_value,3},17824836}, > > {{io_lib_format,precision,2},17706522}, > > {{io_lib_format,pad_char,2},17706522}, > > {{io_lib_format,field_width,3},17706522}, > > {{io_lib_format,field_width,2},17706522}, > > {{io_lib_format,decr_pc,2},17706522}, > > {{io_lib_format,control,7},17706522}, > > {{io_lib_format,collect_cseq,2},17706522}, > > {{io_lib_format,collect_cc,2},17706522}, > > {{io_lib_format,print,7},14402937}, > > {{io_lib_format,chars,2},8912422}, > > {{io_lib_format,term,5},8912417}, > > {{io_lib_format,min|...},8912416}, > > {{io_lib_format|...},8912416}, > > {{...}|...}, > > {...}|...]}, > > > > So here comes the question, how can we find which part calls > > (io_lib_format,pcount,2) most? I tried to use fprof(), but it seems that > you > > need to know the arguments of the function first. > > > > What is the best practice to address this problem? Or did I do something > > wrong? > > No, you are on track. This is the curse of cprof - it only gives you > the call count but with minimal strain on your system. The curse of > fprof is that it gives you lots of information for the price of > a very high system load. > > Now you can read some code. The module io_lib_format is an internal > module for io_lib and io. So the user code calls either io:format/1,2,3, > io:fwrite/1,2,3, io_lib:format/2 or io_lib:fwrite/2. You can search > for those in your source and see which are suspicious. > > You can also hand craft a trace by tracing only the io and io_lib functions > in the previous paragraph using the match spec function {caller}. > This you might do with the dbg module, maybe some other trace tool, > or write one yourself. That would give you an idea of who is to blame. > > > > > Thanks, > > > > kaiduan > > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions@REDACTED > > http://www.erlang.org/mailman/listinfo/erlang-questions > > -- > > / Raimo Niskanen, Erlang/OTP, Ericsson AB > -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter@REDACTED Wed Jan 28 18:26:29 2009 From: peter@REDACTED (Peter Sabaini) Date: Wed, 28 Jan 2009 18:26:29 +0100 Subject: [erlang-questions] fprof error Message-ID: <200901281826.35599.peter@sabaini.at> Hello list, I'm trying to profile an application and every time I run fprof:profile() I get this error: > fprof:profile(). Reading trace data... ..................... =ERROR REPORT==== 28-Jan-2009::18:22:04 === Error in process <0.107.0> on node 'emkuushell@REDACTED' with exit value: {badarg, [{erlang,binary_to_term,[<<0 bytes>>]},{dbg,read_term,3},{dbg,'-mk_reader/2- fun-0-',2},{dbg,tc_loop,3}]} {error,{badarg,[{erlang,binary_to_term,[<<>>]}, {dbg,read_term,3}, {dbg,'-mk_reader/2-fun-0-',2}, {dbg,tc_loop,3}]}} I can run fprof:analyse() afterwards though, and the results don't seem to be completely off. Should I ignore this error? I'm starting fprof in the source of the main routine with fprof:trace(start) btw. thx, peter. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part. URL: From daveb@REDACTED Wed Jan 28 20:14:44 2009 From: daveb@REDACTED (Dave Bryson) Date: Wed, 28 Jan 2009 13:14:44 -0600 Subject: [erlang-questions] Upcoming conferences... Message-ID: Does anyone know of any scheduled or planned Erlang related conferences this year in the U.S.? Thanks, Dave From raould@REDACTED Wed Jan 28 20:39:03 2009 From: raould@REDACTED (Raoul Duke) Date: Wed, 28 Jan 2009 11:39:03 -0800 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: <49808BF7.7090503@it.uu.se> References: <497F9ABB.4030905@gmail.com> <497FA6B1.5060809@gmail.com> <4980486E.9030603@gmail.com> <49805384.6090707@it.uu.se> <498067CD.6020904@gmail.com> <49806F59.70005@it.uu.se> <4980740A.7030302@gmail.com> <49808BF7.7090503@it.uu.se> Message-ID: <91a2ba3e0901281139l312e62b8o3703d86757adcdf7@mail.gmail.com> > But I don't dispute your right to prefer testing via tables, and there > are some quite legitimate cases of this, where one generates the tables > automatically in a separate step (perhaps from specification documents), > so I think some built-in support could be good. misc e.g. http://open.ncsu.edu/se/tutorials/fit/ From francesco@REDACTED Wed Jan 28 20:48:19 2009 From: francesco@REDACTED (Francesco Cesarini (Erlang Training and Consulting)) Date: Wed, 28 Jan 2009 19:48:19 +0000 Subject: [erlang-questions] Upcoming conferences... In-Reply-To: References: Message-ID: <4980B683.50900@erlang-consulting.com> Yes, Dave, you must have read our mind or heard rumours (for once, probably founded)... The official announcement will be made next week, as we are working round the clock to launch the website, preparing its content, booking hotels, etc. We have a 2-day Erlang event planned in Palo Alto April 30th and May 1st, expecting to have 2 to 3 tracks each day. We have some really great speakers signed up, with many more tentative ones in the pipeline. The conference will be preceded by a 3 day University (April 27th - 29th), where we will be offering Erlang, OTP, Couch DB and Quick Check courses. Stay tuned! Francesco -- http://www.erlang-consulting.com Dave Bryson wrote: > Does anyone know of any scheduled or planned Erlang related > conferences this year in the U.S.? > > Thanks, > Dave > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From daveb@REDACTED Wed Jan 28 21:04:44 2009 From: daveb@REDACTED (Dave Bryson) Date: Wed, 28 Jan 2009 14:04:44 -0600 Subject: [erlang-questions] Upcoming conferences... In-Reply-To: <4980B683.50900@erlang-consulting.com> References: <4980B683.50900@erlang-consulting.com> Message-ID: Excellent. Look forward to the official announcement. Dave On Jan 28, 2009, at 1:48 PM, Francesco Cesarini (Erlang Training and Consulting) wrote: > Yes, Dave, you must have read our mind or heard rumours (for once, > probably founded)... The official announcement will be made next > week, as we are working round the clock to launch the website, > preparing its content, booking hotels, etc. > > We have a 2-day Erlang event planned in Palo Alto April 30th and May > 1st, expecting to have 2 to 3 tracks each day. We have some really > great speakers signed up, with many more tentative ones in the > pipeline. The conference will be preceded by a 3 day University > (April 27th - 29th), where we will be offering Erlang, OTP, Couch DB > and Quick Check courses. > > Stay tuned! > > Francesco > -- > http://www.erlang-consulting.com > > Dave Bryson wrote: >> Does anyone know of any scheduled or planned Erlang related >> conferences this year in the U.S.? >> >> Thanks, >> Dave >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions@REDACTED >> http://www.erlang.org/mailman/listinfo/erlang-questions >> From ad.sergey@REDACTED Wed Jan 28 22:13:53 2009 From: ad.sergey@REDACTED (Sergey S) Date: Wed, 28 Jan 2009 13:13:53 -0800 Subject: [erlang-questions] A couple of questions about constructing and matching binaries In-Reply-To: <6672d0160901270606p7ffca30amc689cf850271431f@mail.gmail.com> References: <6672d0160901270606p7ffca30amc689cf850271431f@mail.gmail.com> Message-ID: Hello. Thanks for your explanations! -- Sergey From frederick.grim@REDACTED Wed Jan 28 22:53:45 2009 From: frederick.grim@REDACTED (Frederick Grim) Date: Wed, 28 Jan 2009 16:53:45 -0500 Subject: [erlang-questions] port_command returns badarg in long binary input Message-ID: <4980D3E9.3060104@rgemonitor.com> Hello List, So I have been fighting with the following problem. I have a port that I feed in data to and most of the time it works fine. However for longer data of the form [ pipeline, { atom(), [ { atom(), string() }, { atom(), string() },...]}] it dies with the following error: =ERROR REPORT==== 28-Jan-2009::16:36:29 === caught exception {badarg,[{erlang,port_command, [#Port<0.102>, <<131,108,0,0,0,1,100,0,5,114,101,115,101, 116,106>>]}, {pipeline_bridge,send_msg,2}, {pipeline_bridge,get_response,1}, {pipeline_bridge,call_port,2}, {pipeline_bridge,handle_call,3}, {gen_server,handle_msg,5}, {proc_lib,init_p,5}]} I have attached the pipeline_bridge.erl file. I am sort of at a loss here. The problem is entirely related to the size of the data. The bigger it is, past some threshold I for sure get this sort of failure. Could it be a character encoding issue? The strings could, potentially, be some sort of non-ascii codec. Thanks for the time. Fred -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: pipeline_bridge.erl URL: From colm.dougan@REDACTED Wed Jan 28 23:34:47 2009 From: colm.dougan@REDACTED (Colm Dougan) Date: Wed, 28 Jan 2009 22:34:47 +0000 Subject: [erlang-questions] application:stop(mnesia) blocking In-Reply-To: <24d4f39c0901271003t1e923677sc5592a27e1e368d1@mail.gmail.com> References: <24d4f39c0901271003t1e923677sc5592a27e1e368d1@mail.gmail.com> Message-ID: <24d4f39c0901281434od26e49i750fc0fc64938d4e@mail.gmail.com> On Tue, Jan 27, 2009 at 6:03 PM, Colm Dougan wrote: > Hi list, > > I've got a strange problem with mnesia:stop that is driving me nuts. > I'm sure it must be something trivial I've done wrong but I can't seem > to figure it out. I have a trivial application called "foo" which > contains a gen_server called foo_main. The gen_server does an > application:start(mnesia) in its init callback and an > application:stop(mnesia) in the terminate callback. For some reason > the latter seems to block until it eventually gets killed by the > supervisor. > > I'd be very grateful if someone could look at my code and point out > the inevitably dumb thing I'm doing wrong : > > http://github.com/gardenia/sandbox/tree/de2b36089f1d7928de3161fe7f9d6b78f0b840bd/mnesia_hang_on_shutdown I decided to try and rule out mnesia and so I tried using crypto insteand and got exactly the same behavior. Is there some inherent problem with doing application:stop(something) in a gen_server terminate? Where is the correct place to stop applications like crypto/mnesia when following OTP principles? Thanks, Colm From mrad-direct-erlang@REDACTED Wed Jan 28 23:56:12 2009 From: mrad-direct-erlang@REDACTED (Michael Radford) Date: Wed, 28 Jan 2009 14:56:12 -0800 Subject: [erlang-questions] application:stop(mnesia) blocking In-Reply-To: <24d4f39c0901281434od26e49i750fc0fc64938d4e@mail.gmail.com> References: <24d4f39c0901271003t1e923677sc5592a27e1e368d1@mail.gmail.com> <24d4f39c0901281434od26e49i750fc0fc64938d4e@mail.gmail.com> Message-ID: <20090128225612.GA9931@herbie> I'm not 100% sure about this, but I think we figured out that the application controller is not reentrant, i.e., you can't call application:stop from within another application:stop. (Which is probably where your gen_server's terminate is being called.) Following OTP principles, you should not start or stop other applications from within another application, unless you specifically note the application as "included" and start its top-level supervisor directly. Instead, you should manage applications using a boot script, or something like erlrc [shameless plug]: http://code.google.com/p/erlrc/ There's typically no need to stop applications while a system is running, except when the node is shutting down, during a release upgrade, etc. Mike Colm Dougan writes: > I decided to try and rule out mnesia and so I tried using crypto > insteand and got exactly the same behavior. Is there some inherent > problem with doing application:stop(something) in a gen_server > terminate? Where is the correct place to stop applications like > crypto/mnesia when following OTP principles? > > Thanks, > Colm > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From watson.timothy@REDACTED Wed Jan 28 23:57:52 2009 From: watson.timothy@REDACTED (pax) Date: Wed, 28 Jan 2009 22:57:52 +0000 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: References: Message-ID: <990F1E42-C056-4429-B4AA-C756682AFA05@gmail.com> > However, since I'm too lazy to write test code, I'm definitely too > lazy > to read much about writing test code and even less likely to bother to > learn a whole framework. I have my hands/head full learning the > Erlang/OTP libraries as it is. In my experience of TDD, writing the tests is the best way to learn the language, it's APIs and the platform in general. I like tinkering around, but I'm just as busy as the next guy, so extended debugging sessions are out, and much as a love dbg:tracer and its wares, trawling through the traces to find a bug isn't my idea of fun. > MUCH TOO COMPLICATED!! It's inspired me to try another version of > "utest" that does stuff more like the following: > What do you think? :) Looks good - I'd use it. I'm currently using common_test, and although everyone seems averse to it because of some imputed complexity (it actually seems very simple to me), I find it an excellent tool. In particular I like that it compiles my tests for me, deals with code coverage, producing reasonable test/coverage reports in html and has some utility libraries for working with various managed protocols. The way it handles configuration and test data takes a bit of getting used to, but once you're over the hump (and have some handy scripts to automate things you can't be bothered to remember), it's all good really. Incidentally, the main reason I use common_test in favor of eunit, is that it can be configured/modified to run as a continuous build+test environment and has good support for running master/slave nodes. It effectively acts as a continuous integration server. > There is an Erlang QuickCheck, but it's a commercial product by Quviq. Yes this looks promising (I wouldn't leave home without the Haskell version) but I'm on a tight budget! :) > I really am that lazy (or maybe just that stupid) that I don't want to > change gear into writing (and debugging) a test module. Even when I do > actually pull my finger out, I generally delay doing it by which > time I > have forgotten half of what the module was really intended to do (i.e. > the detail of the spec), and so I have to remember all that and it > becomes a big chore. I hope I'm not going to come across as a zealot here. I too write code without testing it - when I'm prototyping (spiking as it were) and mucking around learning new things. When it comes to writing production code though, the only tests I leave until after I've written the module/application is the integration tests - which I also use common_test for. This has more to do with your choice of process/ discipline than tools I think. The TDD approach is intended to get you thinking about the design/api from the onset, and writing the tests first forces you to do this. It also (if you stick to the method) stops you from writing code you "might need" at some point in the future. I like writing code, so I tend to tech-fest given half a chance. The "red, green, refactor" thing helps me to stay focussed - but that's a personality thing at best. > On another note, someone mentioned Cucumber... well hmmph. That's all > very nice for your corporate stakeholders, but it's waaaaayyy too > verbose for any developer I know to be bothered with. I have to foray into Ruby quite a bit a work, so I'm used to rspec and cucumber. Whilst I see the annoyance - having worked with quickcheck in Haskell, writing any kind of unit tests for referentially transparent code seems a pain - I think cucumber is a world of comfort compared to JUnit, NUnit, JMock and the like. > Yep, interesting and valid points, and there's a distinction to be > made. > > My suggestion is for Unit Tests and so really doesn't cover System/ > Subsystem Tests where the issues you describe will certainly become > major considerations. For that kind of testing, I have other ideas > cooking around - in particular there's big inspiration to be had from > Joe's UBF contracts... > Totally take your point about that. UBF looks very promising. I'm sure there are many ways to automate much of the repetition in defining systems/integration tests. From watson.timothy@REDACTED Thu Jan 29 00:18:05 2009 From: watson.timothy@REDACTED (pax) Date: Wed, 28 Jan 2009 23:18:05 +0000 Subject: [erlang-questions] I Hate Unit Testing... In-Reply-To: References: Message-ID: <4610C98E-D45C-4462-9665-380D23AF1D74@gmail.com> >> In addition, eunit's ?debugVal() macro is incredibly useful -- it's >> like the keystroke-friendly print stmt that Erlang doesn't have. In >> other words, one of your tests fail -- want to look at what's going >> on >> inside the middle of a function somewhere? Just wrap a line in ? >> debugVal() and you get a *great* info message, with full line number >> and everything. It's so useful I sometimes -include eunit just to >> get >> access to that during my dev process. > > I was thinking that the debug macros and the plain assert macros > should > probably be made available directly from their own respective header > files as well, but haven't got around to doing that yet. Oooooh - yes please. Although I use common_test exclusively (for reasons I mentioned in a previous post), I usually include the eunit header so I can make use of your plain assertions. More recently I've been writing test code that borrows the 'matcher' concept from hamcrest, so ?assertThrows(....) looks more like expect_that(fun() -> ... end, should_fail({throw, ExpectedData})). This just returns 'true' or {failed, Reason} however, so I wrap it in a macro that uses eunit ?assert anyway! ;) > Steve Davis wrote: >> Almost, but significantly... not quite. No compile step. > > Hm, well, you've heard of this nifty thing called "make"? > But agreed, it is an additional step. Agree with this and also using an Emakefile can keep things simple too. Another reason I use common_test is that it automatically compiles your test modules for you and you don't need to even bother with an Emakefile: erl -sname ct -pa ./ebin -s ct_run script_start -s erlang halt -I include -logdir ./test/logs -dir test -cover coverage.spec All the business of identifying which modules contain tests (those that follow the _SUITE convention or are listed in a test specification file), compiling them and so on, is done for me. Again this is why I'm slightly baffled that everyone thinks common_test is too complicated - it is the perfect complement to eunit IMO. From nick@REDACTED Thu Jan 29 00:41:07 2009 From: nick@REDACTED (Nick Gerakines) Date: Wed, 28 Jan 2009 15:41:07 -0800 Subject: [erlang-questions] SF Erlounge, hosted by Powerset/Microsoft Message-ID: The next SF Erlounge is just around the corner thanks to Powerset/Microsoft for providing the space. The event is open to the public. Erlang developers, functional programming folks and the curious are welcome to this social event. Light food and drinks will be provided. We will be deviating slightly by having a round of presentations. Powerset A Microsoft Company 475 Brannan Street, Suite 330 San Francisco, CA 94107 As always, we greatly appreciate it when you RSVP. Please direct any questions or comments to nick+sferlounge@REDACTED I can also be reached on my mobile phone, +1 (415) 963-1165. If you get lost or need directions, please call +1 (415) 848-7000 x1082. Plan on parking in the street or taking public transit. More information can be found on http://sferlounge.com/. From nick@REDACTED Thu Jan 29 01:23:44 2009 From: nick@REDACTED (Nick Gerakines) Date: Wed, 28 Jan 2009 16:23:44 -0800 Subject: [erlang-questions] SF Erlounge, hosted by Powerset/Microsoft In-Reply-To: References: Message-ID: This event is set for Thursday, February 26th, 2009. I don't know how that slid by. # Nick Gerakines On Wed, Jan 28, 2009 at 3:41 PM, Nick Gerakines wrote: > The next SF Erlounge is just around the corner thanks to Powerset/Microsoft > for providing the space. The event is open to the public. Erlang developers, > functional programming folks and the curious are welcome to this social event. > Light food and drinks will be provided. > > We will be deviating slightly by having a round of presentations. > > Powerset > A Microsoft Company > 475 Brannan Street, Suite 330 > San Francisco, CA 94107 > > As always, we greatly appreciate it when you RSVP. Please direct any questions > or comments to nick+sferlounge@REDACTED I can also be reached on my > mobile phone, +1 (415) 963-1165. If you get lost or need directions, please > call +1 (415) 848-7000 x1082. Plan on parking in the street or taking public > transit. > > More information can be found on http://sferlounge.com/. > From kaiduanx@REDACTED Thu Jan 29 04:08:34 2009 From: kaiduanx@REDACTED (Kaiduan Xie) Date: Wed, 28 Jan 2009 22:08:34 -0500 Subject: [erlang-questions] profile question In-Reply-To: References: <20090128081725.GA5702@erix.ericsson.se> Message-ID: Raimo, One more question, I have a running system, and a shell is open, how to profile the whole system using fprof? I tried the following without luck, (incomingproxy@REDACTED)1> fprof:start(). {ok,<0.150.0>} (incomingproxy@REDACTED)2> fprof:trace(start, "fprof.trace"). ok (incomingproxy@REDACTED)3> =PROGRESS REPORT==== 28-Jan-2009::21:16:37 === supervisor: {local,inet_gethost_native_sup} started: [{pid,<0.159.0>},{mfa,{inet_gethost_native,init,[[]]}}] =PROGRESS REPORT==== 28-Jan-2009::21:16:37 === supervisor: {local,kernel_safe_sup} started: [{pid,<0.158.0>}, {name,inet_gethost_native_sup}, {mfa,{inet_gethost_native,start_link,[]}}, {restart_type,temporary}, {shutdown,1000}, {child_type,worker}] (incomingproxy@REDACTED)3> fprof:trace(stop). ok (incomingproxy@REDACTED)4> fprof:analyse(). {error,no_profile} The manual and documentation on fprof does not show the example on this scenario. Can you point out what I did wrong? Thanks for help, kaiduan On Wed, Jan 28, 2009 at 12:55 PM, Kaiduan Xie wrote: > Thanks a lot, Raimo for the help. > > More questions, > > 1. From my understanding, Erlang trace is not targeted to find performance > bottleneck, it is used to help you understand how function is executed. I > can not figure out how to use trace to find which function calls the > io_lib_format:pcount in my case most. (In my case, io_lib:format is > dispersed in the code almost everywhere.) > > 2. For fprof, how to profile a function without specifying the arguments? > For example, I want to fprof io_lib:format, but I want to profile all calls > on io_lib:format regardless of the real arguments. > > 3. In C, we can use gprof to achieve what I want in 2). Although gprof > increases the system load substantially. What is the counter-part of gprof > in Erlang. > > 4. What is the tool you guys in Ericsson use to profile a high-load system > without degrading the performance dramatically, at the same time, we can > still get gprof like output? > > Thanks, > > kaiduan > > > On Wed, Jan 28, 2009 at 3:17 AM, Raimo Niskanen < > raimo+erlang-questions@REDACTED > > wrote: > >> On Tue, Jan 27, 2009 at 11:00:10PM -0500, Kaiduan Xie wrote: >> > Hi, all, >> > >> > I have a question on how to find the hot spot of large base Erlang >> system. >> > For example, after running cprof.start(), cprof.pause(), >> cprof.analyze(), I >> > got the following results (only the first item is listed below), >> > >> > {1847012003, >> > [{io_lib_format,722457356, >> > [{{io_lib_format,pcount,2},109483111}, >> > {{io_lib_format,collect,2},109483111}, >> > {{io_lib_format,build,3},109483111}, >> > {{io_lib_format,iolist_to_chars,1},83312743}, >> > {{io_lib_format,indentation,2},60014886}, >> > {{io_lib_format,field_value,2},26618934}, >> > {{io_lib_format,field_value,3},17824836}, >> > {{io_lib_format,precision,2},17706522}, >> > {{io_lib_format,pad_char,2},17706522}, >> > {{io_lib_format,field_width,3},17706522}, >> > {{io_lib_format,field_width,2},17706522}, >> > {{io_lib_format,decr_pc,2},17706522}, >> > {{io_lib_format,control,7},17706522}, >> > {{io_lib_format,collect_cseq,2},17706522}, >> > {{io_lib_format,collect_cc,2},17706522}, >> > {{io_lib_format,print,7},14402937}, >> > {{io_lib_format,chars,2},8912422}, >> > {{io_lib_format,term,5},8912417}, >> > {{io_lib_format,min|...},8912416}, >> > {{io_lib_format|...},8912416}, >> > {{...}|...}, >> > {...}|...]}, >> > >> > So here comes the question, how can we find which part calls >> > (io_lib_format,pcount,2) most? I tried to use fprof(), but it seems that >> you >> > need to know the arguments of the function first. >> > >> > What is the best practice to address this problem? Or did I do something >> > wrong? >> >> No, you are on track. This is the curse of cprof - it only gives you >> the call count but with minimal strain on your system. The curse of >> fprof is that it gives you lots of information for the price of >> a very high system load. >> >> Now you can read some code. The module io_lib_format is an internal >> module for io_lib and io. So the user code calls either io:format/1,2,3, >> io:fwrite/1,2,3, io_lib:format/2 or io_lib:fwrite/2. You can search >> for those in your source and see which are suspicious. >> >> You can also hand craft a trace by tracing only the io and io_lib >> functions >> in the previous paragraph using the match spec function {caller}. >> This you might do with the dbg module, maybe some other trace tool, >> or write one yourself. That would give you an idea of who is to blame. >> >> > >> > Thanks, >> > >> > kaiduan >> >> > _______________________________________________ >> > erlang-questions mailing list >> > erlang-questions@REDACTED >> > http://www.erlang.org/mailman/listinfo/erlang-questions >> >> -- >> >> / Raimo Niskanen, Erlang/OTP, Ericsson AB >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nc@REDACTED Thu Jan 29 10:54:55 2009 From: nc@REDACTED (Nicolas Charpentier) Date: Thu, 29 Jan 2009 10:54:55 +0100 Subject: [erlang-questions] Emake on a SMP VM Message-ID: <49817CEF.9050807@charpi.net> Hi, Is there any good reason why make:all/0 don't try to compile concurrently ? Spawning a process per file to compile could reduce the compile time on modern computer. If there isn't good reasons, a patch to make make:all/0 concurrent should be easy to publish. Regards, ---- Nicolas Charpentier http://charpi.net From adam@REDACTED Thu Jan 29 10:57:28 2009 From: adam@REDACTED (Adam Lindberg) Date: Thu, 29 Jan 2009 09:57:28 +0000 (GMT) Subject: [erlang-questions] How to structure EUnit tests [was: I Hate Unit Testing] In-Reply-To: <4492863.1561233222695071.JavaMail.root@zimbra> Message-ID: <2876188.1581233223047989.JavaMail.root@zimbra> Thought it might be beneficial to branch this to a side discussion. This is how I use EUnit at the moment. I always use debug compiling and define TEST whenever I want tests compiled into the code. In myapp/src/foo.erl I put a small header file inclusion: -ifdef(TEST). -include("foo_test.hrl"). -endif. And myapp/test/foo_tests.hrl looks like this: -include_lib("eunit/include/eunit.hrl"). foo_test_() -> [?_assertEqual(ok, public_function())]. bar_test_() -> [?_assertEqual(ok, private_function())]. The benefits of this are several * Production code and test code are separated * Production code can be compiled and distributed without test code * Private functions can be tested easily * Test code can grow large in a space where it doesn't matter It feels fairly "black box" since the tests are in another file. But I think the most important thing is that I can test private functions with unit tests. It is also easier to see when a module grows too large, since only production code exists in it. Cheers, Adam From bgustavsson@REDACTED Thu Jan 29 11:12:09 2009 From: bgustavsson@REDACTED (Bjorn Gustavsson) Date: Thu, 29 Jan 2009 11:12:09 +0100 Subject: [erlang-questions] Emake on a SMP VM In-Reply-To: <49817CEF.9050807@charpi.net> References: <49817CEF.9050807@charpi.net> Message-ID: <6672d0160901290212r44e43da5n9b72b65a1e2acd65@mail.gmail.com> On Thu, Jan 29, 2009 at 10:54 AM, Nicolas Charpentier wrote: > Hi, > > Is there any good reason why make:all/0 don't try to compile concurrently ? No. > Spawning a process per file to compile could reduce the compile time on > modern computer. > > > If there isn't good reasons, a patch to make make:all/0 concurrent > should be easy to publish. If we'll receive a patch of good quality, we will include it in a future release. /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB From bgustavsson@REDACTED Thu Jan 29 11:27:35 2009 From: bgustavsson@REDACTED (Bjorn Gustavsson) Date: Thu, 29 Jan 2009 11:27:35 +0100 Subject: [erlang-questions] Requests for comment on EEP 26 "Make andalso and orelse tail-recursive" Message-ID: <6672d0160901290227t2679552dj3b054fe4436d9c63@mail.gmail.com> We would like you to submit comments on EEP 26 "Make andalso and orelse tail-recursive" to the eeps@REDACTED mailing list. The EEP can be found here: http://www.erlang.org/eeps/eep-0026.html The deadline is February 8, 2009. After that, we will make our decision and if the EEP is approved the implementation will be included in R13A. NOTE: Comments should be sent ONLY to the eeps@REDACTED mailing list. /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB From vladdu55@REDACTED Thu Jan 29 12:35:23 2009 From: vladdu55@REDACTED (Vlad Dumitrescu) Date: Thu, 29 Jan 2009 12:35:23 +0100 Subject: [erlang-questions] tail-recursive functions Message-ID: <95be1d3b0901290335h25e862bfj33a6343456be8269@mail.gmail.com> Hi, Reading the new EEP 26 "Make andalso and orelse tail-recursive" (which I'm in favor for, btw) made me think of a side-effect: it will become less easy to see if a function is tail-recursive or not. I mean, one has to actively look at the operator and decide "it's andalso, it's tail-recursive" or "it's and, it's not tail-recursive". In addition, there were discussions about making other constructs tail-recursive too. So I wonder if it wouldn't be useful to add a compiler flag that will make it output warnings about functions that are not tail-recursive? Or something else, amounting to the same result. Alternatively, have a separate tool to check this (maybe even dialyzer, since it is a kind of static analysis). best regards, Vlad From chsu79@REDACTED Thu Jan 29 12:50:33 2009 From: chsu79@REDACTED (Christian) Date: Thu, 29 Jan 2009 12:50:33 +0100 Subject: [erlang-questions] Emake on a SMP VM In-Reply-To: <6672d0160901290212r44e43da5n9b72b65a1e2acd65@mail.gmail.com> References: <49817CEF.9050807@charpi.net> <6672d0160901290212r44e43da5n9b72b65a1e2acd65@mail.gmail.com> Message-ID: Is the compiler reentrant nowdays? I know the yaws code has (had?) a global:trans/2 around yaws module compilation because it was not. On Thu, Jan 29, 2009 at 11:12, Bjorn Gustavsson wrote: > On Thu, Jan 29, 2009 at 10:54 AM, Nicolas Charpentier wrote: >> Hi, >> >> Is there any good reason why make:all/0 don't try to compile concurrently ? > > No. > >> Spawning a process per file to compile could reduce the compile time on >> modern computer. >> >> >> If there isn't good reasons, a patch to make make:all/0 concurrent >> should be easy to publish. > > If we'll receive a patch of good quality, we will include it in a > future release. > > /Bjorn > > -- > Bj?rn Gustavsson, Erlang/OTP, Ericsson AB > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From mikpe@REDACTED Thu Jan 29 13:18:38 2009 From: mikpe@REDACTED (Mikael Pettersson) Date: Thu, 29 Jan 2009 13:18:38 +0100 Subject: [erlang-questions] tail-recursive functions In-Reply-To: <95be1d3b0901290335h25e862bfj33a6343456be8269@mail.gmail.com> References: <95be1d3b0901290335h25e862bfj33a6343456be8269@mail.gmail.com> Message-ID: <18817.40606.202456.405510@harpo.it.uu.se> Vlad Dumitrescu writes: > Hi, > > Reading the new EEP 26 "Make andalso and orelse tail-recursive" (which > I'm in favor for, btw) made me think of a side-effect: it will become > less easy to see if a function is tail-recursive or not. > I mean, one has to actively look at the operator and decide "it's > andalso, it's tail-recursive" or "it's and, it's not tail-recursive". > In addition, there were discussions about making other constructs > tail-recursive too. I don't follow this argument. It's always been the case that you have to look at a function's body to determine whether it's tail-recursive or not. Making andalso/orelse tail-recursive doesn't significantly change that. Even procedural languages have similar properties, c.f. short-circuited boolean operators like C's && and ||: you have to look at the operator to determine if the second operand is evaluated or not. /Mikael From bgustavsson@REDACTED Thu Jan 29 13:49:40 2009 From: bgustavsson@REDACTED (Bjorn Gustavsson) Date: Thu, 29 Jan 2009 13:49:40 +0100 Subject: [erlang-questions] Emake on a SMP VM In-Reply-To: References: <49817CEF.9050807@charpi.net> <6672d0160901290212r44e43da5n9b72b65a1e2acd65@mail.gmail.com> Message-ID: <6672d0160901290449t10a51767t968dd3dc643d6230@mail.gmail.com> On Thu, Jan 29, 2009 at 12:50 PM, Christian wrote: > Is the compiler reentrant nowdays? I know the yaws code has (had?) a > global:trans/2 around yaws module compilation because it was not. > As far as I know, it is reentrant in recent releases (and we will avoid doing anything that would make it non-reentrant). /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB From bohtvaroh@REDACTED Thu Jan 29 14:14:20 2009 From: bohtvaroh@REDACTED (Alexander Semenov) Date: Thu, 29 Jan 2009 15:14:20 +0200 Subject: [erlang-questions] Exceptions in guards are blocked. Why? Message-ID: <1233234860.2781.4.camel@tvaroh-laptop> Hi, folks, Can you explain me why exceptions are blocked in guards? For example I wrote this in erlang shell: F = fun(X) when (X == 0) or (X / 0 > 2) -> true; (_) -> false end. F(0). false Is this cause of 'side effects free' guards nature? -- Alexander Semenov From saleyn@REDACTED Thu Jan 29 14:35:56 2009 From: saleyn@REDACTED (Serge Aleynikov) Date: Thu, 29 Jan 2009 08:35:56 -0500 Subject: [erlang-questions] Exceptions in guards are blocked. Why? In-Reply-To: <1233234860.2781.4.camel@tvaroh-laptop> References: <1233234860.2781.4.camel@tvaroh-laptop> Message-ID: <4981B0BC.7020702@gmail.com> The evaluation order or (A or B) is not defined. In this case the second part of the guard is evaluated first and fails. Use orelse for deterministic order, or better (for reasons indicated here [1]), split it into two pattern matches: fun(X) when (X == 0) orelse (X / 0 > 2) -> true; (_) -> false end. or fun(0) -> ...; (X) when X / 0 > 2 -> ...; ... end. Note that since guard expressions don't have side effects, X / 0 > 2 will not throw an exception but the guard would invalidate the pattern match on X. You can verify it with: if X / 0 > 2 -> true; _ -> false end. Serge [1] http://www.erlang.org/eeps/eep-0017.html Alexander Semenov wrote: > Hi, folks, > > Can you explain me why exceptions are blocked in guards? > For example I wrote this in erlang shell: > > F = fun(X) when (X == 0) or (X / 0 > 2) -> true; (_) -> false end. > F(0). > false > > Is this cause of 'side effects free' guards nature? From bohtvaroh@REDACTED Thu Jan 29 14:44:55 2009 From: bohtvaroh@REDACTED (Alexander Semenov) Date: Thu, 29 Jan 2009 15:44:55 +0200 Subject: [erlang-questions] Exceptions in guards are blocked. Why? In-Reply-To: <4981B0BC.7020702@gmail.com> References: <1233234860.2781.4.camel@tvaroh-laptop> <4981B0BC.7020702@gmail.com> Message-ID: <1233236695.2781.7.camel@tvaroh-laptop> Thanks, that's all I would know. On Thu, 2009-01-29 at 08:35 -0500, Serge Aleynikov wrote: > The evaluation order or (A or B) is not defined. In this case the > second part of the guard is evaluated first and fails. Use orelse for > deterministic order, or better (for reasons indicated here [1]), split > it into two pattern matches: > > fun(X) when (X == 0) orelse (X / 0 > 2) -> true; (_) -> false end. > > or > > fun(0) -> ...; > (X) when X / 0 > 2 -> ...; > ... > end. > > Note that since guard expressions don't have side effects, X / 0 > 2 > will not throw an exception but the guard would invalidate the pattern > match on X. You can verify it with: > > if X / 0 > 2 -> true; > _ -> false > end. > > Serge > > [1] http://www.erlang.org/eeps/eep-0017.html > > Alexander Semenov wrote: > > Hi, folks, > > > > Can you explain me why exceptions are blocked in guards? > > For example I wrote this in erlang shell: > > > > F = fun(X) when (X == 0) or (X / 0 > 2) -> true; (_) -> false end. > > F(0). > > false > > > > Is this cause of 'side effects free' guards nature? > -- Alexander Semenov From rvirding@REDACTED Thu Jan 29 15:21:22 2009 From: rvirding@REDACTED (Robert Virding) Date: Thu, 29 Jan 2009 15:21:22 +0100 Subject: [erlang-questions] Exceptions in guards are blocked. Why? In-Reply-To: <1233234860.2781.4.camel@tvaroh-laptop> References: <1233234860.2781.4.camel@tvaroh-laptop> Message-ID: <3dbc6d1c0901290621h7fd5d57ch98841c47a4645272@mail.gmail.com> In guards it is defined that an exception in the guard means that the guard fails. It has basically been so since the beginning of (erlang) time. If you have a guard sequence: f(...) when ; ; ... -> then both failure and an exception in one of the guards means that just that that guard fails and the next is tested, and the clause may still be chosen. See http://erlang.org/doc/reference_manual/part_frame.html. This is one point where using a guard sequence differs from using 'or' or 'orelse'. So, while an exception in one guard above means that the next guard is tested, an exception in the following: f(...) when orelse orelse ... -> means that the whole guard will fail, and the clause not chosen. Robert 2009/1/29 Alexander Semenov > Hi, folks, > > Can you explain me why exceptions are blocked in guards? > For example I wrote this in erlang shell: > > F = fun(X) when (X == 0) or (X / 0 > 2) -> true; (_) -> false end. > F(0). > false > > Is this cause of 'side effects free' guards nature? > -- > Alexander Semenov > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan.milstein@REDACTED Thu Jan 29 15:38:36 2009 From: dan.milstein@REDACTED (Dan Milstein) Date: Thu, 29 Jan 2009 09:38:36 -0500 Subject: [erlang-questions] How to structure EUnit tests [was: I Hate Unit Testing] In-Reply-To: <2876188.1581233223047989.JavaMail.root@zimbra> References: <2876188.1581233223047989.JavaMail.root@zimbra> Message-ID: <9EF82EAC-1EA5-4CE6-B483-59736A365BA7@appingo.com> Love it! Going to steal this idea immediately. Totally agree on all your points -- I've always ended up with tests within the module, exactly because I don't want to export all my private functions. But a) my modules are thus getting a bit unwieldy, and b) I have some fears that whatever parse_transform magic is going within eunit will cause troubles some day in production. Thanks for passing this on... -Dan M On Jan 29, 2009, at 4:57 AM, Adam Lindberg wrote: > Thought it might be beneficial to branch this to a side discussion. > > > This is how I use EUnit at the moment. I always use debug compiling > and define TEST whenever I want tests compiled into the code. > > In myapp/src/foo.erl I put a small header file inclusion: > > -ifdef(TEST). > -include("foo_test.hrl"). > -endif. > > > And myapp/test/foo_tests.hrl looks like this: > > -include_lib("eunit/include/eunit.hrl"). > > > foo_test_() -> > [?_assertEqual(ok, public_function())]. > > bar_test_() -> > [?_assertEqual(ok, private_function())]. > > > > The benefits of this are several > * Production code and test code are separated > * Production code can be compiled and distributed without test code > * Private functions can be tested easily > * Test code can grow large in a space where it doesn't matter > > > It feels fairly "black box" since the tests are in another file. But > I think the most important thing is that I can test private > functions with unit tests. It is also easier to see when a module > grows too large, since only production code exists in it. > > > Cheers, > Adam > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From frederick.grim@REDACTED Thu Jan 29 17:09:41 2009 From: frederick.grim@REDACTED (Frederick Grim) Date: Thu, 29 Jan 2009 11:09:41 -0500 Subject: [erlang-questions] port_command returns badarg in long binary input In-Reply-To: <4980D3E9.3060104@rgemonitor.com> References: <4980D3E9.3060104@rgemonitor.com> Message-ID: <4981D4C5.6020804@rgemonitor.com> so I'll answer my own question. It turns out I was opening the port with the option {packet, 2}. the problem here is that if you then try and feed in a binary to port_command that is greater in size then can be encoded into the 2 byte header port_command fails with an unhelpful badarg error. Thanks all. Fred Frederick Grim wrote: > Hello List, > So I have been fighting with the following problem. I have a port > that I feed in data to and most of the time it works fine. However for > longer data of the form > > [ pipeline, { atom(), [ { atom(), string() }, { atom(), string() },...]}] > > it dies with the following error: > > =ERROR REPORT==== 28-Jan-2009::16:36:29 === > caught exception {badarg,[{erlang,port_command, > [#Port<0.102>, > > <<131,108,0,0,0,1,100,0,5,114,101,115,101, > 116,106>>]}, > {pipeline_bridge,send_msg,2}, > {pipeline_bridge,get_response,1}, > {pipeline_bridge,call_port,2}, > {pipeline_bridge,handle_call,3}, > {gen_server,handle_msg,5}, > {proc_lib,init_p,5}]} > I have attached the pipeline_bridge.erl file. I am sort of at a loss > here. The problem is entirely related to the size of the data. The > bigger it is, past some threshold I for sure get this sort of failure. > Could it be a character encoding issue? The strings could, potentially, > be some sort of non-ascii codec. Thanks for the time. > Fred > > > > ------------------------------------------------------------------------ > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From hubert.plociniczak@REDACTED Thu Jan 29 17:54:14 2009 From: hubert.plociniczak@REDACTED (Hubert Plociniczak) Date: Thu, 29 Jan 2009 16:54:14 +0000 Subject: [erlang-questions] erts tests Message-ID: <310adeca0901290854v2c496ff9w6e0ebebdc0a425fd@mail.gmail.com> Hi, I've been recently making some changes to the standard OTP/R12B-5 and erts, since I needed to add receive-like primitive and some BIFs. I made slight changes to the way how the mailbox is scanned and it seems to pass my tests. But then, I am not able to define all the corner cases for the old behaviour of the 'receive' primitive to make sure that I have backward compatibility and stable runtime. I was wondering if there are any tests available to specifically check erts ? Obviously the easiest thing is to compile the whole thing from scratch and indeed I was getting failures whenever I did something wrong. Still, it would be nice to verify my changes against some standard set of tests. Thanks for help, Hubert -------------- next part -------------- An HTML attachment was scrubbed... URL: From richardc@REDACTED Thu Jan 29 18:05:46 2009 From: richardc@REDACTED (Richard Carlsson) Date: Thu, 29 Jan 2009 18:05:46 +0100 Subject: [erlang-questions] How to structure EUnit tests [was: I Hate Unit Testing] In-Reply-To: <9EF82EAC-1EA5-4CE6-B483-59736A365BA7@appingo.com> References: <2876188.1581233223047989.JavaMail.root@zimbra> <9EF82EAC-1EA5-4CE6-B483-59736A365BA7@appingo.com> Message-ID: <4981E1EA.5050404@it.uu.se> Dan Milstein wrote: > I have some fears that whatever parse_transform magic is going > within eunit will cause troubles some day in production. This is actually very little: the parse transform only handles the automatic exporting of test functions (or stripping, when compiling with testing disabled). All the rest is done through macros and/or using run-time information. I felt it was important that the code did not become too dependent on eunit itself: in a pinch, you should be able to write your own dummy replacements for the eunit.hrl macros, and be able to compile and run the code anyway. And object files that have been created with eunit enabled are not dependent on having the eunit libraries around, neither for normal execution nor for running the test functions. (There are a couple of documented exceptions, when using the macros for running OS commands.) /Richard From raould@REDACTED Thu Jan 29 19:13:25 2009 From: raould@REDACTED (Raoul Duke) Date: Thu, 29 Jan 2009 10:13:25 -0800 Subject: [erlang-questions] tail-recursive functions In-Reply-To: <95be1d3b0901290335h25e862bfj33a6343456be8269@mail.gmail.com> References: <95be1d3b0901290335h25e862bfj33a6343456be8269@mail.gmail.com> Message-ID: <91a2ba3e0901291013s7494abb2y6c07b2535766b845@mail.gmail.com> > So I wonder if it wouldn't be useful to add a compiler flag that will > make it output warnings about functions that are not tail-recursive? > Or something else, amounting to the same result. > > Alternatively, have a separate tool to check this (maybe even > dialyzer, since it is a kind of static analysis). $0.02: disregarding the current specific context, it always seemed to me that it would be nice to have such features. i am under the impression that e.g. the o'caml compiler will tell you about non-tail-optimizable calls? sincerely. From ok@REDACTED Thu Jan 29 23:53:06 2009 From: ok@REDACTED (Richard O'Keefe) Date: Fri, 30 Jan 2009 11:53:06 +1300 Subject: [erlang-questions] tail-recursive functions In-Reply-To: <95be1d3b0901290335h25e862bfj33a6343456be8269@mail.gmail.com> References: <95be1d3b0901290335h25e862bfj33a6343456be8269@mail.gmail.com> Message-ID: <38CF3134-D310-4BCF-88A3-0BD51DA00F30@cs.otago.ac.nz> On 30 Jan 2009, at 12:35 am, Vlad Dumitrescu wrote: > Hi, > > Reading the new EEP 26 "Make andalso and orelse tail-recursive" (which > I'm in favor for, btw) made me think of a side-effect: it will become > less easy to see if a function is tail-recursive or not. > I mean, one has to actively look at the operator and decide "it's > andalso, it's tail-recursive" or "it's and, it's not tail-recursive". > In addition, there were discussions about making other constructs > tail-recursive too. Well, there's an improvement to Erlang that would fix this: eliminate the 'and' and 'or' operators entirely. This would also eliminate the possibility of someone accidentally using the "unsafe" version. Quoting the text of the SML Basis Library: "the language defines the special operators andalso and orelse, which provide short-circuit evaluation of the AND and OR of two boolean expressions. The semantics of strict AND and OR operators, which would evaluate both expressions before applying the operator, >>are rarely needed and can easily be obtained using the andalso and orelse operators." In a strict language, 'andalso' and 'orelse' aren't operators; they are control structures, every bit as much so as 'if' or 'case'. (In Haskell, I grant you, '&&' and '||' are definable as ordinary functions. But then except for syntax, so is 'if'.) Many functions aren't intended to be tail recursive; perhaps any check should be confined to functions that are explicitly declared so. From ok@REDACTED Thu Jan 29 23:56:46 2009 From: ok@REDACTED (Richard O'Keefe) Date: Fri, 30 Jan 2009 11:56:46 +1300 Subject: [erlang-questions] Exceptions in guards are blocked. Why? In-Reply-To: <1233234860.2781.4.camel@tvaroh-laptop> References: <1233234860.2781.4.camel@tvaroh-laptop> Message-ID: On 30 Jan 2009, at 2:14 am, Alexander Semenov wrote: > Hi, folks, > > Can you explain me why exceptions are blocked in guards? It is not that exceptions are *blocked* in guards, but that they signify *failure*. > For example I wrote this in erlang shell: > > F = fun(X) when (X == 0) or (X / 0 > 2) -> true; (_) -> false end. Why did you write that rather than F = fun (X) -> X == 0 orelse X/0 > 2 end > Is this cause of 'side effects free' guards nature? Not really. It's because guards aren't true or false; they succeed or fail. (Blurring this distinction was a really bad idea.) From kunthar@REDACTED Fri Jan 30 02:43:10 2009 From: kunthar@REDACTED (Kunthar) Date: Fri, 30 Jan 2009 03:43:10 +0200 Subject: [erlang-questions] Erlyvideo Message-ID: <9a09ca9a0901291743k1d8aad8do411f695db7d7c393@mail.gmail.com> Anyone saw this before? http://code.google.com/p/erlyvideo/ If creators monitors this list, wondering the status :) Peace Kunth From kaiduanx@REDACTED Fri Jan 30 03:37:34 2009 From: kaiduanx@REDACTED (Kaiduan Xie) Date: Thu, 29 Jan 2009 21:37:34 -0500 Subject: [erlang-questions] How to profile a running erlang production server with fprof? Message-ID: The production server is structured as an OTP application, and an Erlang shell is attached. How to profile the WHOLE system with fprof from the shell? Detailed command sequence is highly appreciated. Thanks a lot for help, kaiduan -------------- next part -------------- An HTML attachment was scrubbed... URL: From Jouni.Ryno@REDACTED Fri Jan 30 07:49:25 2009 From: Jouni.Ryno@REDACTED (Jouni Ryno) Date: Fri, 30 Jan 2009 08:49:25 +0200 Subject: [erlang-questions] net_adm:localhost() return value for -sname? Message-ID: <1233298165.18353.9.camel@adic.fmi.fi> The manual says about net_adm:localhost(): "Returns the name of the local host. If Erlang was started with the -name command line flag, Name is the fully qualified name." The manual is kind of correct, as at least in my Debian Lenny it gives the long name in both cases. But to me the wording kind of implies, that localhost could return the short name, if started with -sname. ryno@REDACTED:/proj/egse$ erl -name test Erlang (BEAM) emulator version 5.6.3 [source] [smp:2] [async-threads:0] [kernel-poll:false] Eshell V5.6.3 (abort with ^G) (test@REDACTED)1> net_adm:localhost(). "adic.fmi.fi" (test@REDACTED)2> ryno@REDACTED:/proj/egse$ erl -sname test Erlang (BEAM) emulator version 5.6.3 [source] [smp:2] [async-threads:0] [kernel-poll:false] Eshell V5.6.3 (abort with ^G) (test@REDACTED)1> net_adm:localhost(). "adic.fmi.fi" My /etc/hosts ryno@REDACTED:$ cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 adic.fmi.fi adic wondering, what was the intention? Jouni -- Jouni Ryn? mailto://Jouni.Ryno@REDACTED/ http://space.fmi.fi/~ryno/ Finnish Meteorological Institute http://www.fmi.fi/ P.O.BOX 503 Tel (+358)-9-19294656 FIN-00101 Helsinki FAX (+358)-9-19294603 Finland priv-GSM (+358)-50-5302903 "It's just zeros and ones, it cannot be hard" From csanto@REDACTED Fri Jan 30 08:45:34 2009 From: csanto@REDACTED (Corrado Santoro) Date: Fri, 30 Jan 2009 08:45:34 +0100 Subject: [erlang-questions] ANN: Amnesia: a DBMS wrapper for Erlang Message-ID: <4982B01E.5030504@diit.unict.it> Dear Erlangers, I would like to announce a new project started by Enzo Nicosia and myself: AMNESIA is a wrapper for SQL DBMSs which allows programmer to perform data storage and processing, through a DBMS, by handling only Erlang native datatypes and without requiring to write SQL statements and/or functions to trasform SQL dataset into meaningful Erlang types. By means of a proper driver layer, it can be used to seamlessly access potentially any DBMS. Currently only a support for MySQL is provided, but a driver for Postgres is under development. Contribs are surely welcome. Amnesia can be found at: http://amnesia.sourceforge.net Feel free to contact any of the authors for problems and/or suggestions. All the best, --Corrado -- ================================================================== Eng. Corrado Santoro, Ph.D. University of Catania - ITALY Dept. of Mathematics and Informatics VoIP: sip:7035@REDACTED ================================================================== From vladdu55@REDACTED Fri Jan 30 08:49:15 2009 From: vladdu55@REDACTED (Vlad Dumitrescu) Date: Fri, 30 Jan 2009 08:49:15 +0100 Subject: [erlang-questions] tail-recursive functions In-Reply-To: <38CF3134-D310-4BCF-88A3-0BD51DA00F30@cs.otago.ac.nz> References: <95be1d3b0901290335h25e862bfj33a6343456be8269@mail.gmail.com> <38CF3134-D310-4BCF-88A3-0BD51DA00F30@cs.otago.ac.nz> Message-ID: <95be1d3b0901292349o37845f41s7bf871b7b14014bc@mail.gmail.com> On Thu, Jan 29, 2009 at 23:53, Richard O'Keefe wrote: > Many functions aren't intended to be tail recursive; perhaps any > check should be confined to functions that are explicitly declared so. Hi, Actually, the problem that should be reported is with functions that are tail-recursive for all but one or two return paths. The probability that the function was meant to be fully tail-recursive is then large enough to make a warning welcome. In any case, if this is only a problem for me, then it needs no fix :-) regards, Vlad From nick@REDACTED Fri Jan 30 09:31:50 2009 From: nick@REDACTED (Niclas Eklund) Date: Fri, 30 Jan 2009 09:31:50 +0100 (CET) Subject: [erlang-questions] Ranking Message-ID: Hello! The text below you find via: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html "Other prominent languages of 2008 are Erlang (from #48 to #29), Powershell (from #59 to #32), and Euphoria (from #69 to #36). Powershell had a top 20 position for a couple of months in 2008 but couldn't keep that position." ... "Expected winners for 2009 are Python because of its strong growth in the webserver market, Erlang thanks to its language built-in support for multi-core systems and C# since it is currently at an all-time high and still growing. I think that the languages PHP (security issues) and Ruby (hype seems over) will have a hard time in 2009." /Niclas @ Erlang/OTP From Mike.French@REDACTED Fri Jan 30 09:33:40 2009 From: Mike.French@REDACTED (French, Mike) Date: Fri, 30 Jan 2009 08:33:40 -0000 Subject: [erlang-questions] Erlyvideo Message-ID: Also note that Adobe will release the RTMP spec 'real soon now': http://www.adobe.com/aboutadobe/pressroom/pressreleases/200901/012009RTMP.ht ml Mike > -----Original Message----- > From: erlang-questions-bounces@REDACTED > [mailto:erlang-questions-bounces@REDACTED]On Behalf Of Kunthar > Sent: 30 January 2009 01:43 > To: erlang-questions@REDACTED > Subject: [erlang-questions] Erlyvideo > > > Anyone saw this before? > http://code.google.com/p/erlyvideo/ > > If creators monitors this list, wondering the status :) > > Peace > Kunth > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > Thales UK Ltd (Wells) DISCLAIMER: The information contained in this e-mail is confidential. It may also be legally privileged. It is intended only for the stated addressee(s) and access to it by any other person is unauthorised. If you are not an addressee, you must not disclose, copy, circulate or in any other way use or rely on the information contained in this e-mail. Such unauthorised use may be unlawful. We may monitor all e-mail communications through our networks. If you have received this e-mail in error, please inform us immediately on sender's telephone number above and delete it and all copies from your system. We accept no responsibility for changes to any e-mail which occur after it has been sent. Attachments to this e-mail may contain software viruses which could damage your system. We therefore recommend you virus-check all attachments before opening. Thales UK Ltd. Registered Office: 2 Dashwood Lang Road, The Bourne Business Park, Addlestone, Weybridge, Surrey KT15 2NX Registered in England No. 868273 From kunthar@REDACTED Fri Jan 30 10:05:50 2009 From: kunthar@REDACTED (Kunthar) Date: Fri, 30 Jan 2009 11:05:50 +0200 Subject: [erlang-questions] Erlyvideo In-Reply-To: References: Message-ID: <9a09ca9a0901300105l4082eb7bk86d8cb14d541cc7e@mail.gmail.com> Also about rtmp : http://osflash.org/documentation/rtmp http://wiki.gnashdev.org/RTMP Thank you Mike > Also note that Adobe will release the RTMP spec 'real soon now': > http://www.adobe.com/aboutadobe/pressroom/pressreleases/200901/012009RTMP.html > Mike Peace Kunth >>Anyone saw this before? >>http://code.google.com/p/erlyvideo/ >>If creators monitors this list, wondering the status :) >>Peace >>Kunth From Philip.Fennell@REDACTED Fri Jan 30 12:06:17 2009 From: Philip.Fennell@REDACTED (Philip Fennell) Date: Fri, 30 Jan 2009 11:06:17 -0000 Subject: [erlang-questions] HTTP requests and the meaning of eaddrinuse Message-ID: Hello, I've been putting together some Erlang programmes to load a potential very large set of data into CouchDB and when using: http:request(put, {"http://192.168.192.10:5984/infax/00_CF07", [], "application/json", {"_id": "00_CF07", "SeriesTitle": "Harold Wilson", "FirstTransmissionDate": "2000-01-01"}}, [], []). as an example, I do get, from time-to-time when I'm recursing over a large and deep directory structure, an atom returned by http:request of: eaddrinuse However, I've been unable to find any reference to its meaning. Could someone tell me what the error eaddrinuse actually means, and for that matter why it might be happening. I'm using Erlang R12B-5 on Windows XP SP2 (but I'm sure that doesn't have anything to do with it). Regards Philip Fennell >XML Developer (The Forge) > >BBC Future Media & Technology >Media Village, 201 Wood Lane London W12 7TP >BC4 C4, Broadcast Centre > >T: 0208 0085318 http://www.bbc.co.uk/ This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated. If you have received it in error, please delete it from your system. Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately. Please note that the BBC monitors e-mails sent or received. Further communication will signify your consent to this. From rvirding@REDACTED Fri Jan 30 12:09:19 2009 From: rvirding@REDACTED (Robert Virding) Date: Fri, 30 Jan 2009 12:09:19 +0100 Subject: [erlang-questions] [eeps] Requests for comment on EEP 26 "Make andalso and orelse tail-recursive" In-Reply-To: <6672d0160901290227t2679552dj3b054fe4436d9c63@mail.gmail.com> References: <6672d0160901290227t2679552dj3b054fe4436d9c63@mail.gmail.com> Message-ID: <3dbc6d1c0901300309q3b15a47br975ad9815f56e4cb@mail.gmail.com> I support the EEP. What is the reason for not doing the full EEP-17? From what I could see the difference was in using andalso and orelse in guards. Robert 2009/1/29 Bjorn Gustavsson > We would like you to submit comments on EEP 26 "Make andalso and > orelse tail-recursive" > to the eeps@REDACTED mailing list. > > The EEP can be found here: http://www.erlang.org/eeps/eep-0026.html > > The deadline is February 8, 2009. After that, we will make our > decision and if the > EEP is approved the implementation will be included in R13A. > > NOTE: Comments should be sent ONLY to the eeps@REDACTED mailing list. > > /Bjorn > -- > Bj?rn Gustavsson, Erlang/OTP, Ericsson AB > _______________________________________________ > eeps mailing list > eeps@REDACTED > http://www.erlang.org/mailman/listinfo/eeps > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bgustavsson@REDACTED Fri Jan 30 12:33:50 2009 From: bgustavsson@REDACTED (Bjorn Gustavsson) Date: Fri, 30 Jan 2009 12:33:50 +0100 Subject: [erlang-questions] [eeps] Requests for comment on EEP 26 "Make andalso and orelse tail-recursive" In-Reply-To: <3dbc6d1c0901300309q3b15a47br975ad9815f56e4cb@mail.gmail.com> References: <6672d0160901290227t2679552dj3b054fe4436d9c63@mail.gmail.com> <3dbc6d1c0901300309q3b15a47br975ad9815f56e4cb@mail.gmail.com> Message-ID: <6672d0160901300333j13b21fccy2defa0b294a7dd0@mail.gmail.com> On Fri, Jan 30, 2009 at 12:09 PM, Robert Virding wrote: > I support the EEP. > > What is the reason for not doing the full EEP-17? From what I could see the > difference was in using andalso and orelse in guards. > The difference was that EEP-17 suggested that ';' and ',' should be allowed to be used nested inside parenthesis, and that ';' and 'orelse' should be equivalent. We want ';' to remain syntatic sugar for several clauses with the same body, that is foo(Patterns) when P1; P2 -> Body. works the same way as foo(Patterns) when P1 -> Body; foo(Patterns) when P2 -> Body. If P1 causes an exception, but P2 evalutes to true, the Body will be executed, but in foo(Patterns) when P1 orelse P2 -> Body. the Body will not be executed if P1 causes an exception. (EEP-17 also mentioned the bad quality of the code generated for andalso/orelse in guards, but that that is merely an implementation detail that need not be mentioned in an EEP. Bad code generation can be fixed at any time, and in fact I have already fixed that problem in the development branch for R13.) /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB From roux.viljoen@REDACTED Fri Jan 30 12:25:43 2009 From: roux.viljoen@REDACTED (Roux Viljoen) Date: Fri, 30 Jan 2009 11:25:43 +0000 (UTC) Subject: [erlang-questions] =?utf-8?q?How_to_profile_a_running_erlang_prod?= =?utf-8?q?uction=09server_with_fprof=3F?= References: Message-ID: Kaiduan Xie gmail.com> writes: > > The production server is structured as an OTP application, and an Erlang shell is attached. How to profile the WHOLE system with fprof from the shell? Detailed command sequence is highly appreciated.Thanks a lot for help,kaiduan > Kaiduan Xie, Fprof is part of the tools library found in OTP, so first you need to make sure its loaded with your application by adding it to your release. Add this to the list of applications in the release file, just change the version to match yours: {tools, '2.6.2'} Now you can use the fprof application. There is alot of ways to use fprof, but the following should be fine. First start a trace by entering: fprof:trace([start, {file, "/home/kaiduanxie/first.trace"}, verbose, {procs,all}]). Now you can run whichever processes you want to profile and then when you're done, stop the trace by entering: fprof:trace([stop]). The trace file can now be profiled and analyzed: fprof:profile({file, "/home/kaiduanxie/first.trace"}). fprof:analyse([totals, {dest, "/home/kaiduanxie/first.analysis"}]). This will produce the first.analysis file which will contain all the data you want. Just be aware that fprof has many configuration options available, this was just a simplistic example. Also, in this example we used the {procs,all} option when we started the trace, this allowed fprof to trace ALL processes. This can cause the trace and analysis files to be huge if you're gonna run alot of processes, so just make sure you have enough disk space. Please consult the documentation for the configuration options if this example does not produce the desired results. Good luck, Roux Viljoen Erlang Training & Consulting http://www.erlang-consulting.com From oscar@REDACTED Fri Jan 30 12:48:32 2009 From: oscar@REDACTED (=?ISO-8859-1?Q?Oscar_Hellstr=F6m?=) Date: Fri, 30 Jan 2009 11:48:32 +0000 Subject: [erlang-questions] HTTP requests and the meaning of eaddrinuse In-Reply-To: References: Message-ID: <4982E910.3080107@erlang-consulting.com> The error means that you've exhausted all available ports on a network interface. On Linux, an application without root privileges can only use ports > 1024, and up to 65535. This means that if you have 64511 open TCP connections, it's impossible to open a new outgoing connection. On windows I don't know how many sockets a user process can actually use, but I guess there is some kind of setting for this. Other applications using the network interface of course also affects this, since the ports are not unique per process. Philip Fennell wrote: > Hello, > > I've been putting together some Erlang programmes to load a potential > very large set of data into CouchDB and when using: > > http:request(put, {"http://192.168.192.10:5984/infax/00_CF07", [], > "application/json", {"_id": "00_CF07", "SeriesTitle": "Harold Wilson", > "FirstTransmissionDate": "2000-01-01"}}, [], []). > > as an example, I do get, from time-to-time when I'm recursing over a > large and deep directory structure, an atom returned by http:request of: > > eaddrinuse > > However, I've been unable to find any reference to its meaning. Could > someone tell me what the error eaddrinuse actually means, and for that > matter why it might be happening. > > I'm using Erlang R12B-5 on Windows XP SP2 (but I'm sure that doesn't > have anything to do with it). > > > Regards > > Philip Fennell > > >> XML Developer (The Forge) >> >> BBC Future Media & Technology >> Media Village, 201 Wood Lane London W12 7TP >> BC4 C4, Broadcast Centre >> >> T: 0208 0085318 >> > > http://www.bbc.co.uk/ > This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated. > If you have received it in error, please delete it from your system. > Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately. > Please note that the BBC monitors e-mails sent or received. > Further communication will signify your consent to this. > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > Best regards -- Oscar Hellstr?m, oscar@REDACTED Office: +44 20 7655 0337 Mobile: +44 798 45 44 773 Erlang Training and Consulting http://www.erlang-consulting.com/ From bohtvaroh@REDACTED Fri Jan 30 13:00:55 2009 From: bohtvaroh@REDACTED (Alexander Semenov) Date: Fri, 30 Jan 2009 14:00:55 +0200 Subject: [erlang-questions] Exceptions in guards are blocked. Why? In-Reply-To: References: <1233234860.2781.4.camel@tvaroh-laptop> Message-ID: <1233316855.10060.3.camel@tvaroh-laptop> Hi. On Fri, 2009-01-30 at 11:56 +1300, Richard O'Keefe wrote: > On 30 Jan 2009, at 2:14 am, Alexander Semenov wrote: > > > Hi, folks, > > > > Can you explain me why exceptions are blocked in guards? > > It is not that exceptions are *blocked* in guards, > but that they signify *failure*. > Nice point. > > For example I wrote this in erlang shell: > > > > F = fun(X) when (X == 0) or (X / 0 > 2) -> true; (_) -> false end. > > Why did you write that rather than > F = fun (X) -> X == 0 orelse X/0 > 2 end > I wrote this only as example, since Joe's book says, that such a guard fails but nothing was said about what does it mean "fail". Thank you for your explanation. > > Is this cause of 'side effects free' guards nature? > > Not really. It's because guards aren't true or false; > they succeed or fail. (Blurring this distinction was a > really bad idea.) > -- Alexander Semenov From bqt@REDACTED Fri Jan 30 14:11:20 2009 From: bqt@REDACTED (Johnny Billquist) Date: Fri, 30 Jan 2009 14:11:20 +0100 Subject: [erlang-questions] HTTP requests and the meaning of eaddrinuse In-Reply-To: <4982E910.3080107@erlang-consulting.com> References: <4982E910.3080107@erlang-consulting.com> Message-ID: <4982FC78.4080303@softjar.se> That don't make sense. If you exhaust all possible local ports, you should get something like resource not available, or something like that. Maybe enobufs. However, you will most probably hit the limit of the number of open file descriptors long before you exhaust all the local port numbers. By default on on my mac, the max file descriptors is 256 (per process). There is also a limit on the total number of file descriptors in the OS. Nowhere near the theoretical limit of 65536 ports in tcp. So that should give you enfile or emfile. eaddrinuse means that you are trying to make a connection using a local port that is already in use. I would assume that the system picks a local port number at random in this case. The port number used should have been checked to not already be in use, but there might be a problem there. Maybe a race condition in the system when trying to bind a socket. Johnny Oscar Hellstr?m wrote: > The error means that you've exhausted all available ports on a network > interface. > > On Linux, an application without root privileges can only use ports > > 1024, and up to 65535. This means that if you have 64511 open TCP > connections, it's impossible to open a new outgoing connection. On > windows I don't know how many sockets a user process can actually use, > but I guess there is some kind of setting for this. Other applications > using the network interface of course also affects this, since the ports > are not unique per process. > > Philip Fennell wrote: >> Hello, >> >> I've been putting together some Erlang programmes to load a potential >> very large set of data into CouchDB and when using: >> >> http:request(put, {"http://192.168.192.10:5984/infax/00_CF07", [], >> "application/json", {"_id": "00_CF07", "SeriesTitle": "Harold Wilson", >> "FirstTransmissionDate": "2000-01-01"}}, [], []). >> >> as an example, I do get, from time-to-time when I'm recursing over a >> large and deep directory structure, an atom returned by http:request of: >> >> eaddrinuse >> >> However, I've been unable to find any reference to its meaning. Could >> someone tell me what the error eaddrinuse actually means, and for that >> matter why it might be happening. >> >> I'm using Erlang R12B-5 on Windows XP SP2 (but I'm sure that doesn't >> have anything to do with it). >> >> >> Regards >> >> Philip Fennell >> >> >>> XML Developer (The Forge) >>> >>> BBC Future Media & Technology >>> Media Village, 201 Wood Lane London W12 7TP >>> BC4 C4, Broadcast Centre >>> >>> T: 0208 0085318 >>> >> http://www.bbc.co.uk/ >> This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated. >> If you have received it in error, please delete it from your system. >> Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately. >> Please note that the BBC monitors e-mails sent or received. >> Further communication will signify your consent to this. >> >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions@REDACTED >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > > Best regards > -- Johnny Billquist || "I'm on a bus || on a psychedelic trip email: bqt@REDACTED || Reading murder books pdp is alive! || tryin' to stay hip" - B. Idol From rklophaus@REDACTED Fri Jan 30 14:25:57 2009 From: rklophaus@REDACTED (Rusty Klophaus) Date: Fri, 30 Jan 2009 05:25:57 -0800 (PST) Subject: [erlang-questions] ANN: Amnesia: a DBMS wrapper for Erlang In-Reply-To: <4982B01E.5030504@diit.unict.it> References: <4982B01E.5030504@diit.unict.it> Message-ID: <8b32ecb1-64da-499a-97d1-38dae3575ab1@v42g2000yqj.googlegroups.com> Hi Corrado and Vincenzo, This looks great. Just read through the docs and some of the code... very clean interface. I'm excited to test it out. Thanks for creating it! Best, Rusty On Jan 30, 2:45?am, Corrado Santoro wrote: > Dear Erlangers, > > I would like to announce a new project started by Enzo Nicosia and > myself: AMNESIA is a wrapper for SQL DBMSs which allows programmer to > perform data storage and processing, through a DBMS, by handling only > Erlang native datatypes and without requiring to write SQL statements > and/or functions to trasform SQL dataset into meaningful Erlang types. > By means of a proper driver layer, it can be used to seamlessly access > potentially any DBMS. Currently only a support for MySQL is provided, > but a driver for Postgres is under development. Contribs are surely welcome. > > Amnesia can be found at:http://amnesia.sourceforge.net > > Feel free to contact any of the authors for problems and/or suggestions. > > All the best, > --Corrado > > -- > ================================================================== > Eng. Corrado Santoro, Ph.D. > University of Catania - ITALY > Dept. of Mathematics and Informatics > > VoIP: sip:7...@REDACTED > > ================================================================== > > _______________________________________________ > erlang-questions mailing list > erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions From sverker@REDACTED Fri Jan 30 15:15:41 2009 From: sverker@REDACTED (Sverker Eriksson) Date: Fri, 30 Jan 2009 15:15:41 +0100 Subject: [erlang-questions] HTTP requests and the meaning of eaddrinuse In-Reply-To: <4982FC78.4080303@softjar.se> References: <4982E910.3080107@erlang-consulting.com> <4982FC78.4080303@softjar.se> Message-ID: <49830B8D.3050302@erix.ericsson.se> Johnny Billquist wrote: > [...] you will most probably hit the limit of the number of open file > descriptors long before you exhaust all the local port numbers. By > default on on my mac, the max file descriptors is 256 (per process). > There is also a limit on the total number of file descriptors in the OS. > Nowhere near the theoretical limit of 65536 ports in tcp. So that should > give you enfile or emfile. > > The internal TIME_WAIT state of the TCP protocol may cause exhaustion of port numbers even though the file descriptor limit is much lower than 65536. Use the netstat command tool to view lingering connections in TIME_WAIT state. /Sverker, Erlang/OTP From cbenac@REDACTED Fri Jan 30 15:21:08 2009 From: cbenac@REDACTED (Clara Benac Earle) Date: Fri, 30 Jan 2009 15:21:08 +0100 Subject: [erlang-questions] CFP Erlang Workshop 2009 Message-ID: <49830CD4.7030802@fi.upm.es> Due to a mistake by the ICFP organizers we were given the wrong date for the Eighth ACM SIGPLAN Erlang Workshop. The Workshop will take place on the 5th of September. Please visit http://www.erlang.org/workshop/2009/ Best regards, Clara From bqt@REDACTED Fri Jan 30 16:00:08 2009 From: bqt@REDACTED (Johnny Billquist) Date: Fri, 30 Jan 2009 16:00:08 +0100 Subject: [erlang-questions] HTTP requests and the meaning of eaddrinuse In-Reply-To: <49830B8D.3050302@erix.ericsson.se> References: <4982E910.3080107@erlang-consulting.com> <4982FC78.4080303@softjar.se> <49830B8D.3050302@erix.ericsson.se> Message-ID: <498315F8.9060307@softjar.se> Sverker Eriksson wrote: > Johnny Billquist wrote: >> [...] you will most probably hit the limit of the number of open file >> descriptors long before you exhaust all the local port numbers. By >> default on on my mac, the max file descriptors is 256 (per process). >> There is also a limit on the total number of file descriptors in the OS. >> Nowhere near the theoretical limit of 65536 ports in tcp. So that should >> give you enfile or emfile. >> >> > > The internal TIME_WAIT state of the TCP protocol may cause exhaustion of > port numbers even though the file descriptor limit is much lower than > 65536. Use the netstat command tool to view lingering connections in > TIME_WAIT state. True, if the connections aren't closed properly. But yes, that could be it. I wonder if eaddrinuse really is returned in that case. TCP should still not even select a port that is already in use. But there aren't any explicit error code for telling that there are no "free" port numbers. Also, tcp will not grab any random port when requested to allocate one. In fact, on MAC OSX, for instance, this is controlled by net.inet.ip.portrange.hilast: 65535 net.inet.ip.portrange.hifirst: 49152 which gives you a range of "only" 16384 ports, from which a port number is allocated. Johnny -- Johnny Billquist || "I'm on a bus || on a psychedelic trip email: bqt@REDACTED || Reading murder books pdp is alive! || tryin' to stay hip" - B. Idol From kaiduanx@REDACTED Fri Jan 30 16:12:56 2009 From: kaiduanx@REDACTED (Kaiduan Xie) Date: Fri, 30 Jan 2009 10:12:56 -0500 Subject: [erlang-questions] How to profile a running erlang production server with fprof? In-Reply-To: References: Message-ID: Roux, This is really helpful. I got fprof included in the release file, and fprof was in the release. But I did not figure out how to profile the whole system. The user guide just shows how to profile a particular function. I tried fprof:trace(start), fprof:trace(stop), fprof:profile(), fprof:analyse() without luck. The server is a call server and spawning many processes. Thanks again for the detailed explanation. kaiduan On Fri, Jan 30, 2009 at 6:25 AM, Roux Viljoen < roux.viljoen@REDACTED> wrote: > Kaiduan Xie gmail.com> writes: > > > > > The production server is structured as an OTP application, and an Erlang > shell is attached. How to profile the WHOLE system with fprof from the > shell? > Detailed command sequence is highly appreciated.Thanks a lot for > help,kaiduan > > > > > Kaiduan Xie, > > Fprof is part of the tools library found in OTP, so first you need to make > sure > its loaded with your application by adding it to your release. > Add this to the list of applications in the release file, just change the > version to match yours: > {tools, '2.6.2'} > > Now you can use the fprof application. There is alot of ways to use fprof, > but > the following should be fine. First start a trace by entering: > > fprof:trace([start, {file, "/home/kaiduanxie/first.trace"}, verbose, > {procs,all}]). > > Now you can run whichever processes you want to profile and then when > you're > done, stop the trace by entering: > > fprof:trace([stop]). > > The trace file can now be profiled and analyzed: > > fprof:profile({file, "/home/kaiduanxie/first.trace"}). > fprof:analyse([totals, {dest, "/home/kaiduanxie/first.analysis"}]). > > This will produce the first.analysis file which will contain all the data > you want. Just be aware that fprof has many configuration options > available, > this was just a simplistic example. > > Also, in this example we used the {procs,all} option when we started the > trace, > this allowed fprof to trace ALL processes. This can cause the trace and > analysis files to be huge if you're gonna run alot of processes, so just > make > sure you have enough disk space. > > Please consult the documentation for the configuration options if this > example > does not produce the desired results. > > Good luck, > > > Roux Viljoen > Erlang Training & Consulting > http://www.erlang-consulting.com > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sverker@REDACTED Fri Jan 30 16:45:19 2009 From: sverker@REDACTED (Sverker Eriksson) Date: Fri, 30 Jan 2009 16:45:19 +0100 Subject: [erlang-questions] HTTP requests and the meaning of eaddrinuse In-Reply-To: <498315F8.9060307@softjar.se> References: <4982E910.3080107@erlang-consulting.com> <4982FC78.4080303@softjar.se> <49830B8D.3050302@erix.ericsson.se> <498315F8.9060307@softjar.se> Message-ID: <4983208F.5010301@erix.ericsson.se> Johnny Billquist wrote: > Sverker Eriksson wrote: >> Johnny Billquist wrote: >>> [...] you will most probably hit the limit of the number of open >>> file descriptors long before you exhaust all the local port numbers. >>> By default on on my mac, the max file descriptors is 256 (per >>> process). There is also a limit on the total number of file >>> descriptors in the OS. Nowhere near the theoretical limit of 65536 >>> ports in tcp. So that should give you enfile or emfile. >> The internal TIME_WAIT state of the TCP protocol may cause exhaustion >> of port numbers even though the file descriptor limit is much lower >> than 65536. Use the netstat command tool to view lingering >> connections in TIME_WAIT state. > True, if the connections aren't closed properly. Actually, kind of the opposite. The peer that actively closes the connection by calling close() will cause its "socket" into TIME_WAIT. It's like a quarantine to avoid late arriving packets of the old connection from being confused with a new connection using the same port. A major flaw of TCP if you ask me. > But yes, that could be it. I wonder if eaddrinuse really is returned > in that case. [...] I experienced this some time ago writing a benchmark on Linux. I'm quite sure it was eaddrinuse that I got when the port numbers where exhausted. /Sverker From rapsey@REDACTED Fri Jan 30 17:33:11 2009 From: rapsey@REDACTED (Rapsey) Date: Fri, 30 Jan 2009 17:33:11 +0100 Subject: [erlang-questions] Erlyvideo In-Reply-To: <9a09ca9a0901300105l4082eb7bk86d8cb14d541cc7e@mail.gmail.com> References: <9a09ca9a0901300105l4082eb7bk86d8cb14d541cc7e@mail.gmail.com> Message-ID: <97619b170901300833w60cf3fe0r70c8493a7763fcb3@mail.gmail.com> Well if you check the dates on svn commits, you will see that the project appears to be dead. Sergej On Fri, Jan 30, 2009 at 10:05 AM, Kunthar wrote: > Also about rtmp : > http://osflash.org/documentation/rtmp > http://wiki.gnashdev.org/RTMP > > Thank you Mike > > Also note that Adobe will release the RTMP spec 'real soon now': > > > http://www.adobe.com/aboutadobe/pressroom/pressreleases/200901/012009RTMP.html > > Mike > > Peace > Kunth > > > >>Anyone saw this before? > >>http://code.google.com/p/erlyvideo/ > > >>If creators monitors this list, wondering the status :) > > >>Peace > >>Kunth > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar@REDACTED Fri Jan 30 19:21:16 2009 From: oscar@REDACTED (=?ISO-8859-1?Q?Oscar_Hellstr=F6m?=) Date: Fri, 30 Jan 2009 18:21:16 +0000 Subject: [erlang-questions] HTTP requests and the meaning of eaddrinuse In-Reply-To: <4983208F.5010301@erix.ericsson.se> References: <4982E910.3080107@erlang-consulting.com> <4982FC78.4080303@softjar.se> <49830B8D.3050302@erix.ericsson.se> <498315F8.9060307@softjar.se> <4983208F.5010301@erix.ericsson.se> Message-ID: <4983451C.2010809@erlang-consulting.com> Sverker Eriksson wrote: > Johnny Billquist wrote: > >> Sverker Eriksson wrote: >> >>> Johnny Billquist wrote: >>> >>>> [...] you will most probably hit the limit of the number of open >>>> file descriptors long before you exhaust all the local port numbers. >>>> By default on on my mac, the max file descriptors is 256 (per >>>> process). There is also a limit on the total number of file >>>> descriptors in the OS. Nowhere near the theoretical limit of 65536 >>>> ports in tcp. So that should give you enfile or emfile. >>>> >>> The internal TIME_WAIT state of the TCP protocol may cause exhaustion >>> of port numbers even though the file descriptor limit is much lower >>> than 65536. Use the netstat command tool to view lingering >>> connections in TIME_WAIT state. >>> >> True, if the connections aren't closed properly. >> > Actually, kind of the opposite. The peer that actively closes the > connection by calling close() will cause its "socket" into TIME_WAIT. > It's like a quarantine to avoid late arriving packets of the old > connection from being confused with a new connection using the same > port. A major flaw of TCP if you ask me. > And I case of put, the inets HTTP client will close the connection after the response is received, since it is mixing up pipelining and keep alive []. We have seen this during load tests of our systems, in which case we implemented interface pools to get around the problem. >> But yes, that could be it. I wonder if eaddrinuse really is returned >> in that case. [...] >> > I experienced this some time ago writing a benchmark on Linux. I'm quite > sure it was eaddrinuse that I got when the port numbers where exhausted. > > > /Sverker > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- Oscar Hellstr?m, oscar@REDACTED Office: +44 20 7655 0337 Mobile: +44 798 45 44 773 Erlang Training and Consulting http://www.erlang-consulting.com/ From bqt@REDACTED Fri Jan 30 21:42:17 2009 From: bqt@REDACTED (Johnny Billquist) Date: Fri, 30 Jan 2009 21:42:17 +0100 Subject: [erlang-questions] HTTP requests and the meaning of eaddrinuse In-Reply-To: <4983208F.5010301@erix.ericsson.se> References: <4982E910.3080107@erlang-consulting.com> <4982FC78.4080303@softjar.se> <49830B8D.3050302@erix.ericsson.se> <498315F8.9060307@softjar.se> <4983208F.5010301@erix.ericsson.se> Message-ID: <49836629.3090400@softjar.se> Sverker Eriksson wrote: > Johnny Billquist wrote: >> Sverker Eriksson wrote: >>> Johnny Billquist wrote: >>>> [...] you will most probably hit the limit of the number of open >>>> file descriptors long before you exhaust all the local port numbers. >>>> By default on on my mac, the max file descriptors is 256 (per >>>> process). There is also a limit on the total number of file >>>> descriptors in the OS. Nowhere near the theoretical limit of 65536 >>>> ports in tcp. So that should give you enfile or emfile. >>> The internal TIME_WAIT state of the TCP protocol may cause exhaustion >>> of port numbers even though the file descriptor limit is much lower >>> than 65536. Use the netstat command tool to view lingering >>> connections in TIME_WAIT state. >> True, if the connections aren't closed properly. > Actually, kind of the opposite. The peer that actively closes the > connection by calling close() will cause its "socket" into TIME_WAIT. > It's like a quarantine to avoid late arriving packets of the old > connection from being confused with a new connection using the same > port. A major flaw of TCP if you ask me. Yes. The first side to do a close will end up in TIME_WAIT. The other side will never. You're right. >> But yes, that could be it. I wonder if eaddrinuse really is returned >> in that case. [...] > I experienced this some time ago writing a benchmark on Linux. I'm quite > sure it was eaddrinuse that I got when the port numbers where exhausted. Hmm. Not a good error code in that case (in my opinion). I should probably check if other systems apart from Linux do that... Anyone know? Johnny -- Johnny Billquist || "I'm on a bus || on a psychedelic trip email: bqt@REDACTED || Reading murder books pdp is alive! || tryin' to stay hip" - B. Idol From per@REDACTED Sat Jan 31 00:01:05 2009 From: per@REDACTED (Per Hedeland) Date: Sat, 31 Jan 2009 00:01:05 +0100 (CET) Subject: [erlang-questions] HTTP requests and the meaning of eaddrinuse In-Reply-To: <4983208F.5010301@erix.ericsson.se> Message-ID: <200901302301.n0UN15Fm095486@pluto.hedeland.org> Sverker Eriksson wrote: > >Johnny Billquist wrote: >> Sverker Eriksson wrote: >>> Johnny Billquist wrote: >>>> [...] you will most probably hit the limit of the number of open >>>> file descriptors long before you exhaust all the local port numbers. >>>> By default on on my mac, the max file descriptors is 256 (per >>>> process). There is also a limit on the total number of file >>>> descriptors in the OS. Nowhere near the theoretical limit of 65536 >>>> ports in tcp. So that should give you enfile or emfile. >>> The internal TIME_WAIT state of the TCP protocol may cause exhaustion >>> of port numbers even though the file descriptor limit is much lower >>> than 65536. Use the netstat command tool to view lingering >>> connections in TIME_WAIT state. >> True, if the connections aren't closed properly. >Actually, kind of the opposite. The peer that actively closes the >connection by calling close() will cause its "socket" into TIME_WAIT. Indeed, it is required by the spec. >It's like a quarantine to avoid late arriving packets of the old >connection from being confused with a new connection using the same >port. A major flaw of TCP if you ask me. Do you have a better solution to the problem? It is a pretty important thing to solve, since such packets could potentially cause a reset of the new session or even corrupt the data stream without any error indication. It could possibly be argued that the default time of (typically) 2 minutes is pretty huge. >> But yes, that could be it. I wonder if eaddrinuse really is returned >> in that case. [...] >I experienced this some time ago writing a benchmark on Linux. I'm quite >sure it was eaddrinuse that I got when the port numbers where exhausted. Yes, that's what you get (on connect()) on all Unices where I have seen it, and it does make some amount of sense I think - if there are no local ports left, any attempt to form a connection would have to use a port that is already "in use". The issue is actually a bit more complex than "running out of local ports" though - it is only the complete 4-tuple that has to be unique, i.e. multiple connections from the same local address and port is OK if either the remote address or the remote port differs. Checking for this uniqueness may be expensive, which could explain that you get this problem "unnecessarily" - the stack may optimistically use a local port that isn't actually free, on the assumption that you don't normally make all your connections to the same remote address/port, so it "should" work out. Except it doesn't when you are doing benchmarks and other things that do tons of connections to the same address/port. There are ways to tweak things in those cases though - the port range has already been mentioned and is normally configurable (/proc/sys/net/ipv4/ip_local_port_range on Linux) so you can actually use the ~ 64k theoretical max, on some OSes you may be able to tinker with the TIME_WAIT timeout (you know that packets won't hang around for 2 minutes on your LAN where you are doing the benchmark), and you may be able to use multiple local addresses in a round-robin fashion (same port on different local addresses will never cause a conflict). How any of this works on Windows I have no idea though. --Per Hedeland From per@REDACTED Sat Jan 31 00:16:50 2009 From: per@REDACTED (Per Hedeland) Date: Sat, 31 Jan 2009 00:16:50 +0100 (CET) Subject: [erlang-questions] HTTP requests and the meaning of eaddrinuse In-Reply-To: <200901302301.n0UN15Fm095486@pluto.hedeland.org> Message-ID: <200901302316.n0UNGo44095771@pluto.hedeland.org> Per Hedeland wrote: > >Checking for this uniqueness may be expensive, which could explain that >you get this problem "unnecessarily" - the stack may optimistically use >a local port that isn't actually free, on the assumption that you don't >normally make all your connections to the same remote address/port, so >it "should" work out. Except it doesn't when you are doing benchmarks >and other things that do tons of connections to the same address/port. > >There are ways to tweak things in those cases though Forgot one that I actually used recently on FreeBSD - it randomizes the selection of local port to make spoofing harder, and every now and then a test case that did a bunch of localhost connections would get the EADDRINUSE. Turning off the randomization (sysctl net.inet.ip.portrange.randomized 1 -> 0) made it cycle nicely through the available range => problem solved. A quick check on a Linux 2.6.20 system doesn't show any such randomization nor reveal a way to turn it on or off, but it may well be there somewhere... --Per From fritchie@REDACTED Sat Jan 31 05:43:01 2009 From: fritchie@REDACTED (Scott Lystig Fritchie) Date: Fri, 30 Jan 2009 22:43:01 -0600 Subject: [erlang-questions] erlang:md5/1 vs crypto:md5/1 difference: speed Message-ID: <11466.1233376981@snookles.snookles.com> Hi, all. Two years ago, Roberta Saccon asked a question of the difference between erlang:md5/1 vs crypto:md5/1. One answer was, "none." Another answer was, "You need to start the crypto application before calling crypto:md5/1." I've discovered a third answer: speed. On a newer Intel Xeon single CPU, dual-core box @ 2.33GHz, and on an AMD X2 single CPU, dual-core box, crypto:md5/1 is 3.0-3.5 times faster on a 64KByte blob than erlang:md5. On an older 3.4GHz single core Xeon, the difference is over almost 7x, and on a several-year-old Pentium M laptop @ 1.33GHz, the difference is 8x.(*) I'm curious ... do others see similar differences? Or is erlang:md5/1 faster on some platforms, e.g. PowerPC? -Scott (*) All of these builds have included OpenSSL 0.9.6something or 0.9.7a. Without it, the crypto app won't be built. From tpot@REDACTED Sat Jan 31 07:12:29 2009 From: tpot@REDACTED (Tim Potter) Date: Sat, 31 Jan 2009 17:12:29 +1100 Subject: [erlang-questions] ambigous_catch_try_state Message-ID: <1233382349.18556.5.camel@tigerella> Hi everyone. I was making some innocuous changes to some erlang code - wrapping some existing blocks in a try/catch and now receive the following error: repository: function handle_call/3+613: Internal consistency check failed - please report this bug. Instruction: {call,1,{f,45}} Error: ambigous_catch_try_state: I'm now reporting this bug, as requested. (-: I'm currently running the 1:11.b.5dfsg-11 Debian package of erlang on Ubuntu 8.04.2. What to do next? I suspect the answer is going one or both of upgrading my version of Erlang, or trying to narrow the bug down to a smaller test program. Does anyone have any suggestions? Tim. From tpot@REDACTED Sat Jan 31 07:12:29 2009 From: tpot@REDACTED (Tim Potter) Date: Sat, 31 Jan 2009 17:12:29 +1100 Subject: [erlang-questions] ambigous_catch_try_state Message-ID: <1233382349.18556.5.camel@tigerella> Hi everyone. I was making some innocuous changes to some erlang code - wrapping some existing blocks in a try/catch and now receive the following error: repository: function handle_call/3+613: Internal consistency check failed - please report this bug. Instruction: {call,1,{f,45}} Error: ambigous_catch_try_state: I'm now reporting this bug, as requested. (-: I'm currently running the 1:11.b.5dfsg-11 Debian package of erlang on Ubuntu 8.04.2. What to do next? I suspect the answer is going one or both of upgrading my version of Erlang, or trying to narrow the bug down to a smaller test program. Does anyone have any suggestions? Tim. From tpot@REDACTED Sat Jan 31 07:12:29 2009 From: tpot@REDACTED (Tim Potter) Date: Sat, 31 Jan 2009 17:12:29 +1100 Subject: [erlang-questions] ambigous_catch_try_state Message-ID: <1233382349.18556.5.camel@tigerella> Hi everyone. I was making some innocuous changes to some erlang code - wrapping some existing blocks in a try/catch and now receive the following error: repository: function handle_call/3+613: Internal consistency check failed - please report this bug. Instruction: {call,1,{f,45}} Error: ambigous_catch_try_state: I'm now reporting this bug, as requested. (-: I'm currently running the 1:11.b.5dfsg-11 Debian package of erlang on Ubuntu 8.04.2. What to do next? I suspect the answer is going one or both of upgrading my version of Erlang, or trying to narrow the bug down to a smaller test program. Does anyone have any suggestions? Tim. From tpot@REDACTED Sat Jan 31 07:12:29 2009 From: tpot@REDACTED (Tim Potter) Date: Sat, 31 Jan 2009 17:12:29 +1100 Subject: [erlang-questions] ambigous_catch_try_state Message-ID: <1233382349.18556.5.camel@tigerella> Hi everyone. I was making some innocuous changes to some erlang code - wrapping some existing blocks in a try/catch and now receive the following error: repository: function handle_call/3+613: Internal consistency check failed - please report this bug. Instruction: {call,1,{f,45}} Error: ambigous_catch_try_state: I'm now reporting this bug, as requested. (-: I'm currently running the 1:11.b.5dfsg-11 Debian package of erlang on Ubuntu 8.04.2. What to do next? I suspect the answer is going one or both of upgrading my version of Erlang, or trying to narrow the bug down to a smaller test program. Does anyone have any suggestions? Tim. From vlm@REDACTED Sat Jan 31 11:28:19 2009 From: vlm@REDACTED (Lev Walkin) Date: Sat, 31 Jan 2009 13:28:19 +0300 Subject: [erlang-questions] erlang:md5/1 vs crypto:md5/1 difference: speed In-Reply-To: <11466.1233376981@snookles.snookles.com> References: <11466.1233376981@snookles.snookles.com> Message-ID: <498427C3.7040105@lionet.info> Scott Lystig Fritchie wrote: > Hi, all. Two years ago, Roberta Saccon asked a question of the > difference between erlang:md5/1 vs crypto:md5/1. > > One answer was, "none." Another answer was, "You need to start the > crypto application before calling crypto:md5/1." > > I've discovered a third answer: speed. On a newer Intel Xeon single > CPU, dual-core box @ 2.33GHz, and on an AMD X2 single CPU, dual-core > box, crypto:md5/1 is 3.0-3.5 times faster on a 64KByte blob than > erlang:md5. On an older 3.4GHz single core Xeon, the difference is over > almost 7x, and on a several-year-old Pentium M laptop @ 1.33GHz, the > difference is 8x.(*) > > I'm curious ... do others see similar differences? Or is erlang:md5/1 > faster on some platforms, e.g. PowerPC? On PowerPC G4 (1.5 GHz) the difference is up to 10x in favor of crypto:md5/1. However, it seem to vary greatly depending on the input size. The following chart summarizes the findings. Blob size erlang:md5 crypto:md5 winner (bytes) (ops/seconds) (ops/second) 34 132778 98205 erlang ~35% faster 63 122425 92851 erlang 65 121247 93296 erlang 80 119739 93464 erlang 90 112531 92757 erlang 95 118074 94302 erlang 100 120783 99943 erlang ~28% faster 101 64845 97556 crypto ~51% faster 102 63076 93717 crypto 103 64369 95260 crypto 104 63359 92948 crypto 105 63638 95318 crypto 110 64147 98937 crypto 120 63961 92614 crypto 161 61173 94997 crypto ~55% faster 204 41394 92266 crypto ~120% faster 49242 304 2627 crypto ~750% faster 499242 29 265 crypto ~800% faster 4999242 ~3 23 crypto So it appears that erlang:md5/1 is up to 35% faster on data less than 100 bytes long, and crypto:md5/1 is up to 10x faster asymptotically. -- Lev Walkin vlm@REDACTED From tpot@REDACTED Sat Jan 31 07:12:29 2009 From: tpot@REDACTED (Tim Potter) Date: Sat, 31 Jan 2009 17:12:29 +1100 Subject: [erlang-questions] ambigous_catch_try_state Message-ID: <1233382349.18556.5.camel@tigerella> Hi everyone. I was making some innocuous changes to some erlang code - wrapping some existing blocks in a try/catch and now receive the following error: repository: function handle_call/3+613: Internal consistency check failed - please report this bug. Instruction: {call,1,{f,45}} Error: ambigous_catch_try_state: I'm now reporting this bug, as requested. (-: I'm currently running the 1:11.b.5dfsg-11 Debian package of erlang on Ubuntu 8.04.2. What to do next? I suspect the answer is going one or both of upgrading my version of Erlang, or trying to narrow the bug down to a smaller test program. Does anyone have any suggestions? Tim. From rvg@REDACTED Sat Jan 31 12:38:17 2009 From: rvg@REDACTED (Rudolph van Graan) Date: Sat, 31 Jan 2009 13:38:17 +0200 Subject: [erlang-questions] Help me reduce the complexity of this function please... (Possible Erlang Bug?) Message-ID: <20ED213A-E1E1-4053-9E47-D6B9E49AE78F@patternmatched.com> I get this error from erlang: > csn_rmcs_file_SUITE: function test_cancelling_file_process/1+2246: > An implementation limit was reached. > Try reducing the complexity of this function. > > Instruction: {test,bs_get_integer2, > {f,41}, > [{x,952}, > 1024, > {integer,8}, > 1, > {field_flags,[unsigned,big]}, > {x,1024}]} > > make: *** [csn_rmcs_file_SUITE.beam] Error 1 when I compile the file containing this function: test_cancelling_file_process(doc) -> ["Describe the main purpose of test case"]; test_cancelling_file_process(suite) -> []; test_cancelling_file_process(Config) when is_list(Config) -> ?line SourceID = params:fget(connid,Config), ?line SinkID = params:fget(sink_id,Config), ?line {ok,_SinkSim} = csn_rmcs_sink_simulator:start_link(SinkID, [{4406600104006823036,host_referral(150000,"N","Successfull"), {2008,1,1}}],pause), testhelper:set_test_app_env(crimson_rmcs_file,processing_concurrency,1), csn_rmcs_trans_util:'$reset_rrn_counter'(), testhelper:set_test_now_monitored({{2008,06,13},{10,10,10}}), ok = write_file("/tmp/inbox/RMCSTRANCOL01012008RMCS1.upload",[<<"H| RMCSTRANCOL|RMCS|1|2008/01/01">>, <<"C| 4406600104006823036|12345|319991001234|ProdID|1.00|debit|00031|test description|ref1||||||||||||||||||">>, <<"C| 4407600104006823036|12345|319991001234|ProdID|1.00|debit|00031|test description|ref2||||||||||||||||||">>, <<"C| 4407600104006823036|12345|319991001234|ProdID|0.50|credit|00031|test description|ref3||||||||||||||||||">>, <<"Q| 4407600104006823036|12345|319991001234|ProdID|1.00|debit|00031|test description|ref4||||||||||||||||||">>, <<"Q| 4407600104006823036|12345|319991001234|ProdID|1.00|debit|00031|test description|ref5||||||||||||||||||">>, <<"Q| 4407600104006823036|12345|319991001234|ProdID|1.00|debit|00031|test description|ref6||||||||||||||||||">>, <<"T| 2|1|3|2.00|0.50">>]), file:rename("/tmp/inbox/RMCSTRANCOL01012008RMCS1.upload","/tmp/ inbox/RMCSTRANCOL01012008RMCS1.ready"), ?line ok = testhelper:wait_until(5,500,fun() -> processing == get_csn_file_status("RMCSTRANCOL01012008RMCS1") end), ?line ok = recv_sim_and_ack(1000), ?line ok = recv_sim_and_ack(1000), ?line {ok,SourceConn} = isoconn:open(dirty,SourceID), ?line {atomic,{ok,_}} = gdb:transaction(fun() -> isoconn:update(isoconn:fset(SourceConn,enabled,false)) end), ?line catch ok = recv_sim_and_ack(1000), ?line ok = testhelper:wait_until(20,1000,fun() -> processed == get_csn_file_status("RMCSTRANCOL01012008RMCS1") end), {ok,[ <<"H|RMCSTRANRES|PMT|1|2008/01/01">>, <<"C|4406600104006823036|12345|319991001234|ProdID|1.00|debit| 00031|test description|ref1||unprocessed|ISO RESPONSE CODE: 92|| RM0613000001||||||||||||">>, <<"C|4406600104006823036|12345|319991001234|ProdID|1.00|debit| 00031|test description|ref2||paid|Successfull|2008/01/01|RM0613000002| 1006600100001206196|TLOURRA MR TSHEPIS|6122304055443083|1500.00| 0330000|0. <<"C|4406600104006823036|12345|319991001234|ProdID|0.50|credit| 00031|test description|ref3||unprocessed|ISO RESPONSE CODE: 900| 2008/01/01|RM0613000003|1006600100001206196|TLOURRA MR TSHEPIS| 6122304055443083 <<"Q|4406600104006823036|12345|319991001234|ProdID|1.00|debit| 00031|test description|ref4||unprocessed|ISO RESPONSE CODE: 900||||||||||||||">>, <<"Q|4406600104006823036|12345|319991001234|ProdID|1.00|debit| 00031|test description|ref5||unprocessed|ISO RESPONSE CODE: 900||||||||||||||">>, <<"Q|4406600104006823036|12345|319991001234|ProdID|1.00|debit| 00031|test description|ref6||unprocessed|ISO RESPONSE CODE: 900||||||||||||||">>, <<"T|2|1|3|2.00|0.50">>, <<>> ]} = read_file("/tmp/outbox/RMCSTRANRES01012008PMT1.ready"), ok. Thanks! Rudolph van Graan From kostis@REDACTED Sat Jan 31 13:06:58 2009 From: kostis@REDACTED (Kostis Sagonas) Date: Sat, 31 Jan 2009 14:06:58 +0200 Subject: [erlang-questions] ambigous_catch_try_state In-Reply-To: <1233382349.18556.5.camel@tigerella> References: <1233382349.18556.5.camel@tigerella> Message-ID: <49843EE2.2050606@cs.ntua.gr> Tim Potter wrote: > Hi everyone. I was making some innocuous changes to some erlang code - > wrapping some existing blocks in a try/catch and now receive the > following error: > > repository: function handle_call/3+613: > Internal consistency check failed - please report this bug. > Instruction: {call,1,{f,45}} > Error: ambigous_catch_try_state: > > I'm now reporting this bug, as requested. (-: I'm currently running > the 1:11.b.5dfsg-11 Debian package of erlang on Ubuntu 8.04.2. > > What to do next? I suspect the answer is going one or both of upgrading > my version of Erlang, or trying to narrow the bug down to a smaller test > program. > > Does anyone have any suggestions? My suggestion is a refinement of what you suggested yourself. Erlang/OTP R11B-5 is quite old by now. Try to get a newer version of Erlang/OTP (for example, Debian lenny comes with R12B-3), if possible the latest version (R12B-5) which is available at www.erlang.org. By getting a newer version, you'll be doing yourself a favor anyway. See if the problem persists and if so submit the program exhibiting the consistency check error here (or in erlang-bugs) Kostis From bqt@REDACTED Sat Jan 31 13:14:27 2009 From: bqt@REDACTED (Johnny Billquist) Date: Sat, 31 Jan 2009 13:14:27 +0100 Subject: [erlang-questions] HTTP requests and the meaning of eaddrinuse In-Reply-To: <200901302301.n0UN15Fm095486@pluto.hedeland.org> References: <200901302301.n0UN15Fm095486@pluto.hedeland.org> Message-ID: <498440A3.7070001@softjar.se> Per Hedeland wrote: > Sverker Eriksson wrote: >> Johnny Billquist wrote: >>> Sverker Eriksson wrote: >>>> Johnny Billquist wrote: >> It's like a quarantine to avoid late arriving packets of the old >> connection from being confused with a new connection using the same >> port. A major flaw of TCP if you ask me. > > Do you have a better solution to the problem? It is a pretty important > thing to solve, since such packets could potentially cause a reset of > the new session or even corrupt the data stream without any error > indication. It could possibly be argued that the default time of > (typically) 2 minutes is pretty huge. > >>> But yes, that could be it. I wonder if eaddrinuse really is returned >>> in that case. [...] >> I experienced this some time ago writing a benchmark on Linux. I'm quite >> sure it was eaddrinuse that I got when the port numbers where exhausted. > > Yes, that's what you get (on connect()) on all Unices where I have seen > it, and it does make some amount of sense I think - if there are no > local ports left, any attempt to form a connection would have to use a > port that is already "in use". Well, I think that it's a flaw in the design of the interface. If you use port 0 (ask the system to give you a port) you should never get eaddrinuse. That is sort of guaranteed by the call (the semantic is to give you a free port). But I can't see any good return value to give in case no free port was found, so I guess they might just have been "lazy". I wonder if all systems do this, or if different systems have different "solutions". If noone can tell for other systems than Linux I guess I'll have to go in and examine the source myself soon. :-) > The issue is actually a bit more complex than "running out of local > ports" though - it is only the complete 4-tuple that has to be unique, > i.e. multiple connections from the same local address and port is OK if > either the remote address or the remote port differs. True. > Checking for this uniqueness may be expensive, which could explain that > you get this problem "unnecessarily" - the stack may optimistically use > a local port that isn't actually free, on the assumption that you don't > normally make all your connections to the same remote address/port, so > it "should" work out. Except it doesn't when you are doing benchmarks > and other things that do tons of connections to the same address/port. Well, the problem is that when you create the local port, you still don't know which remote destination you will talk with, so you can't really tell if an existing port will be okay to reuse. You have the sockopt SO_REUSEADDR which circumvents this check. Is it possible to set that from Erlang? > There are ways to tweak things in those cases though - the port range > has already been mentioned and is normally configurable > (/proc/sys/net/ipv4/ip_local_port_range on Linux) so you can actually > use the ~ 64k theoretical max, on some OSes you may be able to tinker > with the TIME_WAIT timeout (you know that packets won't hang around for > 2 minutes on your LAN where you are doing the benchmark), and you may be > able to use multiple local addresses in a round-robin fashion (same port > on different local addresses will never cause a conflict). Good ideas. On BSD-like systems, you normally control this with sysctl. > How any of this works on Windows I have no idea though. Me neither. :-) Johnny -- Johnny Billquist || "I'm on a bus || on a psychedelic trip email: bqt@REDACTED || Reading murder books pdp is alive! || tryin' to stay hip" - B. Idol From bqt@REDACTED Sat Jan 31 13:16:31 2009 From: bqt@REDACTED (Johnny Billquist) Date: Sat, 31 Jan 2009 13:16:31 +0100 Subject: [erlang-questions] HTTP requests and the meaning of eaddrinuse In-Reply-To: <200901302316.n0UNGo44095771@pluto.hedeland.org> References: <200901302316.n0UNGo44095771@pluto.hedeland.org> Message-ID: <4984411F.9010702@softjar.se> Per Hedeland wrote: > Per Hedeland wrote: >> Checking for this uniqueness may be expensive, which could explain that >> you get this problem "unnecessarily" - the stack may optimistically use >> a local port that isn't actually free, on the assumption that you don't >> normally make all your connections to the same remote address/port, so >> it "should" work out. Except it doesn't when you are doing benchmarks >> and other things that do tons of connections to the same address/port. >> >> There are ways to tweak things in those cases though > > Forgot one that I actually used recently on FreeBSD - it randomizes the > selection of local port to make spoofing harder, and every now and then > a test case that did a bunch of localhost connections would get the > EADDRINUSE. Turning off the randomization (sysctl > net.inet.ip.portrange.randomized 1 -> 0) made it cycle nicely through > the available range => problem solved. A quick check on a Linux 2.6.20 > system doesn't show any such randomization nor reveal a way to turn it > on or off, but it may well be there somewhere... Whoa? It don't actually check that the random port is actually free before giving it to you??? That would be a serious design flaw. It means that any socket creation can potentially give EADDRINUSE even though it could actually have given you a free port number. Ick! Johnny -- Johnny Billquist || "I'm on a bus || on a psychedelic trip email: bqt@REDACTED || Reading murder books pdp is alive! || tryin' to stay hip" - B. Idol From saleyn@REDACTED Sat Jan 31 17:46:57 2009 From: saleyn@REDACTED (Serge Aleynikov) Date: Sat, 31 Jan 2009 11:46:57 -0500 Subject: [erlang-questions] otp.net In-Reply-To: <49223331.5060400@gmail.com> References: <49223331.5060400@gmail.com> Message-ID: <49848081.5030304@gmail.com> These changes are committed to jungerl. Serge Serge Aleynikov wrote: > I made several bug fixes and enhancements to the otp.net project in > jungerl, and would like to find out if this project is being used by > others before I commit my updates as not all modifications are backward > compatible. We had a discussion with the author (Vlad) and he didn't > seem to have objections. > > The changes are: > > - More robust error handling > - Added delegates for connection state changes > - Support for pid monitors > - Support for short node names > - Optional disabling of local epmd registration > - Support for local processing of io_request's > - RPC API extended to supply the pid of a local io server mailbox. > - Support for IEEE 754 double encoding/decoding > > Serge > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From steven.charles.davis@REDACTED Sat Jan 31 17:58:36 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Sat, 31 Jan 2009 08:58:36 -0800 (PST) Subject: [erlang-questions] -version or -vsn? Message-ID: <0e922b47-ccf3-42dc-9f37-5f2d52ac2988@v5g2000pre.googlegroups.com> I've noticed that if you use -version then -vsn is still recorded in Module:module_info(attributes) apparently as a 128 uuid. If you use - vsn, that uuid isn't generated... so is it better practice to use - version() in your source so that you have that serial UID to uniquely identify the beam from the vsn attribute? /s From rvirding@REDACTED Sat Jan 31 18:44:44 2009 From: rvirding@REDACTED (Robert Virding) Date: Sat, 31 Jan 2009 18:44:44 +0100 Subject: [erlang-questions] Exceptions in guards are blocked. Why? In-Reply-To: References: <1233234860.2781.4.camel@tvaroh-laptop> Message-ID: <3dbc6d1c0901310944u61977131obe02c6abe40f580e@mail.gmail.com> 2009/1/29 Richard O'Keefe > > > Is this cause of 'side effects free' guards nature? > > Not really. It's because guards aren't true or false; > they succeed or fail. (Blurring this distinction was a > really bad idea.) This point Richard is making is actually very basic and important, guards aren't true or false but rather they either succeed or fail. Just to restate it! Guards are really just the bits of pattern matching which can't easily be written in the pattern. So really the only way a clause is chosen is by pattern matching alone. In this context it was quite reasonable to add the feature that an exception in a guard was equivalent to the guard failing. It also explains why some guard *tests* aren't really valid as expressions, for example the *test* float(F) tests whether F is a float, while the *expression* float(F) means convert F to a float (if it is an integer). Unfortunately adding boolean operators, while being useful, makes guards look like expressions and blurs the distinction between expressions and guard tests. It also complicates the semantics of exceptions in guards. Robert P.S. Yes I know there exists ways of writing patterns were the tests are included in the pattern, I have seen some, but I think they the pattern very hard to read. Having them in a separate guard does make it easier to read (but maybe harder to understand). -------------- next part -------------- An HTML attachment was scrubbed... URL: From cliff@REDACTED Sat Jan 31 19:16:02 2009 From: cliff@REDACTED (Cliff Moon) Date: Sat, 31 Jan 2009 10:16:02 -0800 Subject: [erlang-questions] inspect process mailbox size Message-ID: <49849562.4050202@moonpolysoft.com> is there any way to inspect mailbox size at runtime? Under load testing I'm seeing conditions pop up where a node will go out of control due to mailbox growth and it's rather hard to debug the issue post mortem from crash dumps. From koops.j@REDACTED Sat Jan 31 19:29:32 2009 From: koops.j@REDACTED (Jeroen Koops) Date: Sat, 31 Jan 2009 19:29:32 +0100 Subject: [erlang-questions] inspect process mailbox size In-Reply-To: <49849562.4050202@moonpolysoft.com> References: <49849562.4050202@moonpolysoft.com> Message-ID: <331a9abb0901311029k5fb468ebv7436c6ce715c9ae3@mail.gmail.com> erlang:process_info(Pid, message_queue_len) will do this, but it is intended for debugging only according to the docs. On Sat, Jan 31, 2009 at 7:16 PM, Cliff Moon wrote: > is there any way to inspect mailbox size at runtime? Under load testing > I'm seeing conditions pop up where a node will go out of control due to > mailbox growth and it's rather hard to debug the issue post mortem from > crash dumps. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From harveyd@REDACTED Sat Jan 31 19:36:50 2009 From: harveyd@REDACTED (Dale Harvey) Date: Sat, 31 Jan 2009 18:36:50 +0000 Subject: [erlang-questions] inspect process mailbox size In-Reply-To: <49849562.4050202@moonpolysoft.com> References: <49849562.4050202@moonpolysoft.com> Message-ID: http://erlang.org/doc/man/erlang.html 4> erlang:process_info(self(),[message_queue_len,messages]). [{message_queue_len,0},{messages,[]}] 5> self()!hello. hello 6> erlang:process_info(self(),[message_queue_len,messages]). [{message_queue_len,1},{messages,[hello]}] 2009/1/31 Cliff Moon > is there any way to inspect mailbox size at runtime? Under load testing > I'm seeing conditions pop up where a node will go out of control due to > mailbox growth and it's rather hard to debug the issue post mortem from > crash dumps. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nem@REDACTED Sat Jan 31 20:11:14 2009 From: nem@REDACTED (Geoff Cant) Date: Sat, 31 Jan 2009 20:11:14 +0100 Subject: [erlang-questions] inspect process mailbox size In-Reply-To: <49849562.4050202@moonpolysoft.com> (Cliff Moon's message of "Sat, 31 Jan 2009 10:16:02 -0800") References: <49849562.4050202@moonpolysoft.com> Message-ID: Cliff Moon writes: > is there any way to inspect mailbox size at runtime? Under load testing > I'm seeing conditions pop up where a node will go out of control due to > mailbox growth and it's rather hard to debug the issue post mortem from > crash dumps. erlang:process_info/2 is very helpful for this: erlang:process_info(Pid, messages_queue_len) gives you the length of the queue and erlang:process_info(Pid, messages) gives you the queue itself. A common cause of mailbox blowout is that the process is blocked waiting for a reply from something - in this case erlang:process_info(Pid, backtrace) and erlang:process_info(Pid, current_function) can help you figure out what it might be waiting for. Cheers, -- Geoff Cant From steven.charles.davis@REDACTED Sat Jan 31 20:51:33 2009 From: steven.charles.davis@REDACTED (Steve Davis) Date: Sat, 31 Jan 2009 13:51:33 -0600 Subject: [erlang-questions] version or vsn? In-Reply-To: <0e922b47-ccf3-42dc-9f37-5f2d52ac2988@v5g2000pre.googlegroups.com> References: <0e922b47-ccf3-42dc-9f37-5f2d52ac2988@v5g2000pre.googlegroups.com> Message-ID: <4984ABC5.5080303@gmail.com> I've noticed that if you use -version() in your source then -vsn() is still recorded in Module:module_info(attributes) -- apparently as a 128 uuid. However, If you do use -vsn(), that uuid isn't generated... so is it better practice to use -version() in your source so that you have that auto-generated serial UID to uniquely identify the beam from the -vsn() attribute? /s From lfredlund@REDACTED Sat Jan 31 22:27:12 2009 From: lfredlund@REDACTED (=?windows-1252?Q?Lars-=C5ke_Fredlund?=) Date: Sat, 31 Jan 2009 22:27:12 +0100 Subject: [erlang-questions] Erlang talk in Madrid (Spain) on Monday by Francesco Cesarini Message-ID: <4984C230.1080305@fi.upm.es> WHO: Francesco Cesarini WHEN: Monday, February 2, 15:30 WHERE: Facultad de Inform?tica, Campus de Montegancedo (Boadilla del Monte) Universidad Polit?cnica de Madrid, H-1002 (bloque 1) WHAT: Functional Programming in Industry: Erlang for five nines Abstract: Francesco Cesarini is the founder and CTO of Erlang Training and Consulting. He has used Erlang on a daily basis for almost 15 years, having started his career as an intern at Ericsson?s computer science laboratory, the birthplace of Erlang. He moved on to Ericsson?s Erlang training and consulting arm working on the first release of OTP, applying it to turnkey solutions and flagship telecom applications. In 1999, soon after Erlang was released as open source, he founded Erlang Training and Consulting. With offices in the UK, Sweden, Poland (and soon the US), they have become the world leaders in Erlang based consulting, contracting, training and systems development. Francesco has worked in major Erlang based projects both within and outside Ericsson, and in his role as CTO, is currently leading the development and consulting teams at ETC. He is also the co-author of Practical Erlang Programming, a book soon to be published. Francesco Cesarini will be presenting the concurrent soft real time functional programming language Erlang and its rapidly growing community. He will describe why Erlang programs are generally 4 - 10 times shorter than their counterparts in Java, C and C++ achieving 99,999% availability. The talk will also go into why Erlang, originally invented to handle the next generation of Telecom products, has been successful in a much wider range of sectors including banking and e-commerce. All welcome!