Phoenix as a Meteor alternative

Were’s that slack channel? Any idea on how can I use Phoenix as a chat backend and connect it to meteor publications? That seems like a really good option for me. Meteor + Phoenix. And what’s the best db option with Phoenix for that? (Lots of small writes)

Here is the slack channel https://elixir-slackin.herokuapp.com/

I haven’t ever tried to hook Meteor into Phoenix, nor have I thought much about it, so anything I say is just an off-the-top-of-my-head comment. @SkinnyGeek1010 has done it though so he likely has a good idea of whether that’s possible.

There is no best DB option for anything really. It comes down to your project needs. Phoenix defaults to Postgres which is a really solid option. I also think RethinkDB is a stellar choice so you likely can’t go wrong with either of those.

2 Likes

This is super interesting… But I’m thinking of holding off building a phoenix/redux app at the moment because this issue https://github.com/facebook/relay/issues/114 is going to be resolved at some point.

I think relay will completely replace redux as soon as it can handle both client and server data.

And then there’s this issue: https://github.com/facebook/relay/issues/541 that is trying to cover real-time updates via subscriptions.

Once relay matures a bit more in company with Elixir’s graphql packages, that will an incredible way to build apps going forward.

I don’t know much about Relay, but from a quick glance it looks intriguing. When school calms down I’ll have to give it a closer look.

Ya I agree! Chris McCord has been saying that their goal is to move Phoenix over to a more GraphQL type system so that should definitely be interesting. He and Jose are super smart dudes. They seem to be pumping out good stuff at a break neck pace! Pretty impressive.

Chapter 9 on Phoenix Channels was uploaded tonight. Disappointed you were not there.

Do you have some thoughts about this other solution that tries to compensate Meteor limitations, mainly about scaling, but still using Node.js?

It seems well done.

1 Like

It’s a great proof of concept. I wouldn’t say scaling is the main issue he’s attempting to resolve. He’s put a lot of thought into many aspects.

The project looks interesting, but with only 34 commits from one guy it’s too early to tell what will become of it. I hope others start pushing code.

It’s certainly a direction MDG should be heading towards but will never be able to. The level of resistance to positive change in the meteor community dwarfs that of when Apple decided to ditch Motorola.

Myself though, Elixir has re-ignited my love for programming. Whenever I write code in Javascript I feel dirty. It is so bad on so many levels. That and the fact that Phoenix’s development activity level makes Meteor look like abandonware in comparison.

3 Likes

I’m confused as to why Phoenix is a suitable Meteor alternative tbh. I’m always interested in new technology and do have a habit of jumping from framework to framework - but Phoenix is a backend-only framework written in an obtuse (albeit seemingly enjoyable to use) language. It’s hardly like you could jump from one to the other.

I’m not sure what I’m getting at really, but I can see why @Babak is a bit fazed. There’s more activity in this thread than in Elixir’s SO tag.

2 Likes

I guess my tolerance for mucking around in javascript is a bit higher :smile:

Honestly, with babel, there is rarely a pattern that makes me feel dirty. And the beauty of a language that updates annually is that it keeps getting more performant & it’ll probably absorb some good parts of Elixir, too.

I don’t think there’s an inherent performance gain to Elixir (the one benchmark is outdated, was performed on different machines, and didn’t really test much). We’ve all heard the success stories of node in Netflix & Walmart black fridays, but they don’t use sockets like we use them. About a year ago someone forked node to work concurrently, it never got popular because evented programming is just as fast & easier to reason about.

There’s always something to learn from a different language. Evented programming didn’t start with node, the libuv pattern was popular in C/C++ since the 80s. Chances are Flux/Redux wouldn’t exist without Elm & that’s a functional language. Who knows what nice treats the JS community can steal from Elixir :wink:

3 Likes

I know… I even talked to Michael about! Hopefully I’ll be on the next one. It’s been a little hard making the time with school :frowning:

Totes! I hope they do steal a few things… Elixir has some awesome features. Well, functional programming languages in general have awesome features (e.g. pattern-matching, pipes, etc…)

I love JavaScript, but man, I miss Elixir when I work with it haha. It’s kinda nice to switch back and forth when I build with React and Phoenix.

This is an interesting benchmark, have you seen this? Phoenix Showdown Comparative Benchmarks @ Rackspace · GitHub

I was pretty surprised by the performance of Elixir. Because you can spin up millions of processes to do work all at the same time you can get stuff done very quickly. It’s actually kinda shocking… Super fast.

But, this says it all:

Spot on.

2 Likes

It’s better than BASIC. At least we have classes now. Still no strong typing though.

I have to admit I find this new dynamic of transpilers quite fascinating. I thought .net was nifty when you could do something similar with outputting a C# app from a VB app or vice-versa, but this is another level altogether.

The Erlang VM uses a separate heap per process. A process in Erlang takes just 309 words to spin up, including 233 words for the stack which auto-grows and shrinks. That means you can spin up millions of them at will.

It a fully preemptive scheduler. No stop the world GC pauses and no synch process killing the rest of the system. It values low latency over throughput. @SkinnyGeek1010 posted about this earlier with his own benchmarks. 14ms response times, and only 16ms under heavy load.

If you have knowledge of how computers actually work there is no way you are not amazed at Erlang. Node, or even GO/Scala just cannot compete.

Get back to us when meteor’s (O)n^2 feature says hello. Meteor is the only framework where you hope and pray your application doesn’t become too popular. And by popular, we’re talking a few hundred users.

1 Like

btw dont trust any benchmarks you see, try them out for yourself and modify them to reflect what you are trying to build.

Just some useless info: I have performed the same with latest everything and you can see my results below. This doesnt say much, my env can be different or something else can be wrong. Point is try it out yourself :smile:

Note that the phoenix they used was very old so I created it from scratch, there might have been some performance tweaks I missed. Both ran in prod env.

[2015/12/02, 2:30:46 PM] Riaan Jacobs: phoenix:
[2015/12/02, 2:30:48 PM] Riaan Jacobs: riaans-MacBook-Pro-3:wrk riaan$ ./wrk -t4 -c100 -d30S --timeout 2000 "http://127.0.0.1:4000/showdown"
Running 30s test @ http://127.0.0.1:4000/showdown
4 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 9.09ms 0.91ms 18.38ms 73.06%
Req/Sec 2.76k 102.10 3.01k 76.25%
329775 requests in 30.01s, 729.06MB read
Requests/sec: 10988.04
Transfer/sec: 24.29MB

[2015/12/02, 2:30:54 PM] Riaan Jacobs: and express cluster:
[2015/12/02, 2:31:03 PM] Riaan Jacobs: iaans-MacBook-Pro-3:wrk riaan$ ./wrk -t4 -c100 -d30S --timeout 2000 "http://127.0.0.1:3000/showdown"
Running 30s test @ http://127.0.0.1:3000/showdown
4 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 4.72ms 3.60ms 167.29ms 95.64%
Req/Sec 5.57k 559.22 8.04k 86.20%
666977 requests in 30.10s, 1.36GB read
Requests/sec: 22156.41
Transfer/sec: 46.34MB

btw I really like phoenix and node/meteor. I look at my projects requirements and then pick the correct tool for the job.

Haha, same here. After writing Elixir, I’ve been using de-structuring heavily in my JS now, as well as making modules with just functions (no classes!). Using underscore’s chain method to pipe data through functions

var res = _.chain('555 121-7878')
  .callFn(stripChars, '.')
  .callFn(stripChars, ' ')
  .callFn(stripChars, '-').value();

console.log(res);
// ->  "5551217878"

Yea this is important. However, if you’re already using React/Redux in Meteor then the jump is not as far because you’re still using the same frontend. Instead of Meteor.call you use AJAX, and instead of subscribe you use the JS channels API.

The language can be learned in an intense weekend if you have Dave’s book and the learning elixir website. Phoenix is another day or two to make something to the point that it ‘clicks’.

That’s my experience and it was my first functional language (I find Elixir to pragmatic compared to Haskell/Listp/etc…)

It really depends on what you’re benchmarking… if it’s just a json api then you’re right, prob. not much of a difference comparing a node cluster to an Erlang machine. However… once you start benchmarking long lived stateful apps (websockets), Erlang/Elixir will rule the roost… mostly because the language itself was designed just to do this (telephone conversations are long lived connections).

2 Likes

@jacobin Perhaps I wasn’t clear. I wasn’t asking why it might be a better framework, but what makes it an ‘alternative’ in any real sense. I’d see something like sails.js as an alternative to meteor, for example. Phoenix is something different entirely.

i.e. If you had a trained team of javascript developers, you couldn’t easily migrate your meteor app to phoenix. It’s not something to consider unless you’re (likely) a sole developer and (likely) wanting to learn something new and quite different.

I guess this is pertinent. If ‘all’ your framework is doing is serving an API I guess the jump is a lot smaller.

Also if you’re the kind of developer that can pick up new languages easily it’s likely less of a big deal. I’m not a dedicated developer (although things seem to be shifting that way) and I still struggle with async coming from a PHP background, looking at Elixir code gives me the shivers!

Edit: tldr; Even if I went back to the day I discovered Meteor, I couldn’t imagine myself weighing up Phoenix vs Meteor - I think the target audiences are likely quite different.

(I’m sure it’s all awesome though, I really couldn’t say otherwise!)

1 Like

Purely out of interest, what kinds of jobs would you assign to each? (and when you say node/meteor, do you also mean you might use Phoenix over, say, Express for certain areas but not others?)

I think that’s true for certain benchmarks. In addition, I’m not to the level at which I’d feel confident conducting a benchmark as I’m neither a devops person nor a master of the intricate details of each framework. There are just too many nitty-gritty optimizations that I haven’t yet learned.

Did you just run the benchmark on your local machine?

I would imagine most Elixir code would be close to PHP and it’s sync by default :smiley: The Elixir docs do not really do it justice as a first glance (I passed it by the first time because of this)

Pattern matching can be confusing and this is a simple example. The first func in the module that matches will run (instead of an if/else in one function). Notice all of them have the same function name.

defmodule Greeter do
  # pattern matching determines what function runs, if the shape matches than it will run instead
  def say_hi([name]) do
    IO.puts "Hello, #{name} !"
  end

  def say_hi([name1, name2]) do
    IO.puts "Hello, #{name1} and #{name2} !"
  end

  def say_hi(_anythingelse) do
    IO.puts "Uh, oh you need to pass one or two names in an array"
  end
end

Greeter.say_hi(["Adam"])

Elixir makes you think of data transformation like Unix pipes sending input from one program to the next. The weird |> operator just means to send the output into the input of the next function. This allows you to compose a function from smaller functions like this:

defmodule NumberUtils do
  def normalize(number) do
    number
    |> strip_char '.'
    |> strip_char ~r/^+1/
    |> strip_char ' '
    |> strip_char '_'
  end

  # returns last line
  pdef strip_char(str, char) do
    String.replace(str, char)
  end
end

NumberUtils.normalize('+1 555 333-8888')


edited forgot to add number to pipeline

3 Likes

I know that https://dockyard.com/ did just that recently. I was actually very surprised at how quickly I was able to pick up Elixir/Phoenix. Now, by no means am I anywhere near expert level, but I certainly can get things done! That said, you definitely need to put in some time to learn everything and not everybody has a bunch of free time. This is especially true if you are swamped with work and have to pay the bills!! :grimacing:

1 Like

True that. Add my age to the equation and things start to become clear why learning basically anything is a ball ache! :smiley:

Edit: Although I have no excuse, there are older, busier people than me that are always learning, I probably just like things to come easy. Did you just call me lazy!?