145 points · by jxub · 8y ago · 103 comments
I think it's no wonder that Elixir is having the success it is. It fixes literally every single issue on this page (many of which still exist in erlang), plus you get all the good stuff.
I've worked for many years with many other languages and runtimes, but beam, OTP and Elixir (and the synergy between them) are better tools. As a foundation, message passing and isolation are the only realistic weapons I've seen against most common causes of technical debt (coupling). It isn't a silver bullet, but it tries hard to help you. And, importantly, it's approachable.
Another way to look at it is that it delivers many of the same benefits of SOA/microservices, without the significant infrastructure/deploy/devops overhead.
I did it using QnX re-inventing quite a bit of the Erlang philosophy along the way, if I had had access to either Erlang or Elixer at that point in time I would have been overjoyed, that would have saved so much time.
I am not saying it is bad. But I’d like to know about it before I dive in.
Had Elixir been mature at the time, we would have used it instead.
After a quick Google I also discovered this nifty site: https://elixir-companies.com/
It does seem there aren't that many very big companies outside of Silicon Valley using Elixir but maybe that's a factor of Silicon Vally having the vast majority of winners period.
My anecdatum. :)
So you get isolation (beam processes), decoupling (message passing) and resilience (supervisors) without having to deploy and maintain N different apps and the pain points that come with that (monitoring, discovery, integration testing, debugging, ...)
Our company has other systems, in other languages, and a pretty involved deployment process (docker+nomad) so our deploys are pretty specific to that. But, I can tell you that as a developer, having only a few "apps" that internally have hundreds of services, has more or less freed us up of having to worry about any of that cognitive (and performance) overhead.
1. Our jenkins CI builds a docker image which contains an erlang release (using distillery).
2. This image gets pushed to ECR (AWS's image repository), every version is tagged with a $GIT_REF.
3. We have another jenkins job which updates our AWS ECS Tasks to use the new version of Docker images.
4. AWS ECS now spins up a few new containers and drains out the connections from the old ones.I have written a detailed guide here: https://www.cogini.com/blog/best-practices-for-deploying-eli...
There are languages everyone is happy for you to criticize online. Then there are a small few that cause people to lose their shit when you offer a critique. It's really sad - you really shouldn't be so personally invested in a tool you didn't write.
"," means AND.
";" means OR.
"." ends the rules.
In Algol based languages ";" ends each statement. To apply OR or AND conditions between statements, you then need to use if/then/switch conditions.
To be pedantic about it, in ALGOL, the original "Algol based language", the semicolon is a separator. There are lots of "missing" semicolons in ALGOL programs. See the examples here: https://en.wikipedia.org/wiki/ALGOL#Code_sample_comparisons
I think that is more confusing than what C does. E.g. look at the ALGOL 68 example. One 'od' ends with a semicolon, the other doesn't. I dunno if that example is correct or not, I haven't written an ALGOL program in about 45 years.
(Prolog, which influenced this part of Erlang syntax an many others, does it this simpler way. It still sucks if you want to comment out the last line of a clause, or switch the last line of a clause with some other line.)
The trick is to define * as a prefix operator, and then define the predicate ( * )/1 to generalize away its argument. You only need two lines to do it:
:- op(920,fy, *).
*_.
Now, you can put * in front of any goal to "remove" it. For example: pred :-
true,
* false.
With this definition, ?- pred. succeeds.In Erlang, you cannot easily replicate this. You can try parse transformations to rewrite code at compilation time:
http://erlang.org/doc/man/compile.html
In Elixir, defining otherwise unused operators is generally discouraged:
https://hexdocs.pm/elixir/master/operators.html
For exchanging lines, an editor macro may be useful for Erlang and also for Prolog.
Map/reduce views ("secondary indexes") are currently built by serializing JSON down a pipe to an external process called couchjs that links against a seven year old version of Mozilla Spidermonkey (1.8.5, released on March 31st 2011, and the only version it currently works with). This external process then pipes the map results back, again as JSON. Forget zerocopy; we're serializing and deserializing twice per document. Almost all of this "external view server" (the only kind AFAICT) is actually written in Javascript on that seven year old engine. Nothing is streaming; your map function is sandbox-evaled in that process, the results of a single call are stuffed into a Javascript array via .push, then stringified and printed on standard output as a single line. The entire internal "view server" protocol is based on a pipe of single-line JSON commands and data payloads. Performance (and likely security, due to age of the engine) in this subsystem is extremely poor IME.
You can write map/reduce views in Erlang itself as an alternative, but that engine is disabled by default due to security concerns – it's "not sandboxed". Performance in this area also appeared to be proportional to the code size of the map function, which sounded a lot like it was being serialized down a pipe with no caching.
If you make a change to a single view in a design document, the database system will rebuild all indexes in that design document unconditionally, even if the other view code hasn't changed. The only way to prevent this is to store a single view per design document, and manage those documents yourself.
Once you've endured your multi-day index rebuild on a couple million documents, you'll also have to issue an extra "cleanup" command to delete the old (now essentially useless) indexes. It's a full rebuild, so you need 2x the space at a minimum to pull it off.
The data itself is stored in a single file per shard, opened in O_APPEND mode, effectively serializing all writes on the shard. You also will not see kswapd active, ever, because the OS VMM is not being used effectively – no shared memory for IPC, and no use of mmap AFAICT.
Server-side changes feed filters appear to be extremely slow when compared to just filtering the results in the client.
Authorization: limiting read access will be difficult at best. Transactional behavior: no, aside from a single bulk write feature (make sure to use "all or nothing" mode though).
Logging: signal to noise ratio is poor. Giant stack traces for minor events. You may even see strings emitted as UTF-32 arrays of integers in base 10. Hope you brought an ASCII table at least.
Documentation: The following passage from section 5.2.5 of the CouchDB v2.1.1 manual just about says it all: "Views with the JavaScript query server are extremely slow to generate when there are a non-trivial number of documents to process. The generation process won’t even saturate a single CPU let alone your I/O. The cause is the latency involved in the CouchDB server and separate couchjs query server, dramatically indicating how important it is to take latency out of your implementation." I can't say anything nice here about that last sentence, so I'm just going to keep my mouth shut.
But worst of all: every time it starts up, it tells me "it's time to relax". Nothing about this is relaxing.
(These are my own private individually-held views, and do not reflect the views of any employer or organization)
Except CouchDB entire REST API, where nearly every endpoint streams result row by row, which is great.
> Performance (and likely security, due to age of the engine) in this subsystem is extremely poor
As of security: wrong guess. Go compare number of critical CouchDB CVE for last, say, 5 years, with any other DB you want.
As for query server: indexing is slow for the reasons you pointed out. Requesting persisted index is ok. Taking in account CouchDB persists everything, it‘s not in-memory DB (which is again great), I‘d say it‘s even fast.
> Performance in this (Erlang) area also appeared to be proportional to the code size of the map function
Performance in this area depends much more on how branchy is the json doc being processed. It‘s not about CouchDB itself, it‘s about json parser used. There might be a situation when you have better perf using JS views.
> Nothing about this is relaxing.
Indeed. But then it just works, for years, with zero maintenance even for replications – the result I‘ve never even nearly achieved with any other DB I used.
I get the impression the author(s) of this DB were still at the stage of needing to brow-beat the infrastructure into submission, or somesuch :S
Or you can use a query language mostly similar to what MongoDB uses http://docs.couchdb.org/en/2.0.0/api/database/find.html
> If you make a change to a single view in a design document, the database system will rebuild all indexes in that design document unconditionally,
That's a feature. If they don't usually change together put them in a separate design documents.
> and manage those documents yourself.
It's a document database. So managing documents yourself is kind of what you do. Isn't it?
> he data itself is stored in a single file per shard, opened in O_APPEND mode, effectively serializing all writes on the shard.
So have more shards? A lot of databases use append only mode. There is a reason for that. Having uses the db for a good number of years, it had never lost data. Even during power outages or brutal restarts. That's more than I can say about other databases.
> no shared memory for IPC,
Shared memory IPC doesn't magically solve problems but it is a minefield of bugs.
> use of mmap AFAICT.
Large blocks of allocated memory use malloc instead of brk so memory allocation uses mmap. For file IO mmap isn't a panacea either. If data is not there, reads will still go to the disk. If it uses regular reads through data should end up in the page cache
> kswapd active,
Hmm, seeing kswapd being active is not something I look forward on a production server. From what I remember I have seen page cache utilized correctly and that's what should matter. Not kswapd.
> Transactional behavior: no, aside from a single bulk write feature
bulk docks is not a transactional feature. The database is not CP database so it doesn't have transactional feature.
> But worst of all: every time it starts up, it tells me "it's time to relax". Nothing about this is relaxing.
Yeah that is silly never liked that. From what I remember it was a DB that was built when MySQL ruled the open source DB world and many of the current DBs were not there. It was actually pretty relaxing being able to insert regular json object in it, index them, have master to master replication (which most dbs still don't support), have a nice built in web dashboard to inspect and query documents.
Isn’t it supposed to be mainly REST based and have a goal of being able to sync multiple nodes with expected connection loss in between?
I’ve never needed that on a project but it seems like it would work for some use cases. I hear good things about PouchDB.
I can understand it working the other way around, e.g. an application initially seems good, but opinion of it drops when finding out it's written in COBOL.
I can understand if the CouchDB authors agreed with criticism of their application, and explained them as being inherent to the language. AFAIK they haven't. EDIT: Ah, looks like the author wrote CouchDB!
I can understand if Erlang and its proponents held CouchDB up as a shining example of their philosophy. AFAIK they don't (e.g. it doesn't appear on https://www.erlang.org/community ).
I like all the other things he critiqued!!1!
Rearranging: the punctuation helps you think about how you’re rearranging. You can’t copy/paste around in any function and expect it it work!
The records comparison to a struct is unfair. He could have patterned matched on the record instead of destructuring and accessed the attributes of the record.
Immutability! Fuck yeah! I tend to name subsequent variables with the mutation that was applied to them. It’s wordy.
Name = “wayne”
NameCapitalized = ...
Now get off my lawn!
if
Logging ->
log("Something happened");
true -> ok
end
For this particular use-case there is much more elegant way in Erlang: Logging andalso log("Something happened");
Even though I agree that the syntax and the concepts are unfamiliar for the general audience, I mainly see those arguments as the main reason to learn the language rather than put it away since it's sometimes the only way to learn something new.
Regarding the "alien" syntax and expressing my point of view, I think Erlang syntax is usable, very simple and sometimes prevents you from doing "too fancy" things.
Erlang's main areas are fault tolerant, high throughput applications and network protocols. Once it's declared as the focus - I wouldn't punch the ecosystem too much for the syntax but rather just use another tool for solving the problems that require more expressive programming languages.
On the critics of the areas of focus I'd recommend the work done by Fred Herbert, the author of Learn you some Erlang for Great Good (http://learnyousomeerlang.com/).
There is a book on pitfalls while maintaining Erlang platform at large scale: http://www.erlang-in-anger.com/ report(Msg) -> hopefully_traced.
You can then add a trace probe to your report/1 function and this allows you to have debug information when you need it. f(X) ->
X1 = foo(X),
X2 = bar(X1),
baz(X2).
If I use the pointless variable names like that, sure, I run into trouble, but this means I'm a shitty programmer who cares little about program readability. f(X) ->
fooedX = foo(X),
baredX = bar(fooedX),
baz(baredX).
f(X) ->
fooedX = foo(X),
fabedX = fab(fooedX),
baredX = bar(fabedX),
baz(baredX).
Or just f(X) ->
baz(bar(fab(foo(x)))).My understanding though is that the problem is mixed with Erlangs pattern matching it can cause issues, because it won't necessarily fail to repeat the variable name, it'll just behave wrong. At least that's what I heard.
Personally I like Erlang the language, but it is still Erlang the system that truly shines.
It says a lot of Erlang the system that we’re fondly criticizing the language, warts and all. Erlang is all about pragmatism and we hand it over to the academy (the Swedish one, notch, notch, know what I mean?) to dwell on the Important Details about ‘.’, ‘,’ and ’;’ ;)
http://damienkatz.net/2012/01/the_future_of_couchdb.html
Yes, of course the argument should stand on its own despite the author's other claims or blog posts, so let's review some claims:
> Because Prolog sucks ass for building entire applications.
There have been entire applications written in Prolog. Attacking syntax is is just silly. Had Prolog used statements and not expressions or ; instead of . I doubt we'd would have a seen a lot more or less applications in Prolog.
> But that hasn't deterred Erlang from stealing it's dynamite syntax.
The syntax is consistent. That's the point. It has relatively few syntax and semantic rules. It has strong types and behaves consistently, comparing say, with "this" in Javascript. js has semicolons but it behave inconsistently sometimes. You'd have to explain why {} + [] = 0 for example. Picking on js here since the author used js as an example of a "good" language.
> editing code is much harder than conventional languages.
Have not found this to be true. It is a bit harder. But not much harder and not a show stopper. You can't randomly copy and paste code and reorder statements because compiler will not like it. That's probably a good thing. Variables being immutable is helping when inserting a new function call in the middle, you have to think well if that modified value is suitable for the operations that follow below.
> If Expressions
There are 6 paragraphs talking about the "if" expression. "if" is not even used that often and focusing on it just because it has the same name as the "if" statement from Algol (C) type languages is a waste of time.
Use "case" instead or even better multiple function clause heads. Yes, you can't do an early return so you have to explicitly handle every case. I see it as a good thing. You can cheat and say "_ -> ...DefaultValue" but it will stand and be obvious what's happening to the reader.
> You Say String of Characters, I Say List of Integers
Or list of unicode code points... You have a choice to use binaries instead of lists of integers. They are closer to the traditional strings in other languages. This is a better explanation of how they work: https://medium.com/@jlouis666/erlang-string-handling-7588daa...
> but it's surprisingly limited and verbose, requiring you to state the type of the record for each reference in the code.
Since the blog was written Erlang got maps other languages call them dicts or hash tables for example.
All in all I'd say syntax is often what people talk about but it is closer to bike shedding. It is easy to argue about because it's right there and everyone can see a . instead of a ;. It would better to talk about the semantics of the language, sending messages, concurrency, modeling applications as a set of communicating processes, supervision trees etc.
> Had Prolog used statements and not expressions or ; instead of .
Prolog uses "goals", which are a lot more like statements than they are like expressions. Also, Prolog doesn't use ; to separate the clauses ("rules") of a predicate, it uses . to terminate each one.
But I agree that whether or not Prolog sucks for building entire applications has nothing to do with these points.
As far as I am aware Erlang does not run the unification algorithm and it is very different, you can, for instance, assign variables.
I don't think it is right to compare the two as close languages as it is claimed but I would be interested in your opinion
An opinionated take: https://medium.com/@dmitriid/in-which-i-complain-about-elixi...
That said, I would say most everything that Damien says here and is not already labeled as fixed remains an issue as written. Erlang is an exceeding conservative language community, from its telecommunications heritage, and its syntax has hardly budged from when it was first written.
I’m skeptical. It seems more likely a new, larger community will form (probably has formed) but I think anyone sufficiently dedicated to have used such an obscure, weird language prior will stick with it.
(I may be projecting a bit, but as someone passionate about Erlang I have minimal interest in Elixir.)
With those syntax improvements, we get the power of Erlang with the ease of use of Rails: http://www.littlelines.com/blog/2014/07/08/elixir-vs-ruby-sh... (A bit dated, but this is the post that sold me on the platform.)