Running Meteor Application on a Single Core

Running Meteor Application on a Single Core

You shouldn't be running Meteor this way. Basically when your shell times out the meteor process will be killed. You need to detach it from the remote login.

There are a number of ways to do it.

The first step will be to do a 'meteor build', which will produce a bundle, and zip it up ready for transfer to the host

1) Nginx and Phusion Passenger
This is my recommendation, as I have found it very easy to set up and maintain, and it also looks after sharing one IP address among several Meteor servers (much like Apache does with virtual hosts). There is an excellent wizard on their site which leads you through installation and setup https://www.phusionpassenger.com/library/install/nginx/install/oss/

2) Forever
If you are only running one server and have simpler needs, forever will do. It's also useful for running nodejs servers (which is what meteor server is). https://github.com/foreverjs/forever

3) mup will allow you a one step publish to your own server
https://github.com/kadirahq/meteor-up

4) Galaxy hosting. Perhaps more expensive, but again it gives you a one step publish option. https://www.meteor.com/hosting

Galaxy and mup are the least amount of effort, as they are very much a black box. Trouble shooting when things go wrong can be harder. I like the nginx solution because you have fine grained control and yet setup is really simple.

Running a meteor server from terminal

meteor and meteor run are equivalent and are the standard way to run the Meteor server via the command line utility during development.


Usage: meteor [--release ] [--help] [args]
meteor help
meteor [--version] [--arch]

With no arguments, 'meteor' runs the project in the current
directory in local development mode. You can run it from the root
directory of the project or from any subdirectory.

Use 'meteor create ' to create a new Meteor project.
Commands:
run [default] Run this project in local development mode.
...

run is the default in case no other command is specified after meteor.

The initial run can be a rather slow, and sometimes takes longer than desired to pick up changes.

There is an unofficial webpack build package that could be faster in some cases, but there are some things to consider before using it (I would say that it has a slightly higher learning curve than the standard build system, and the file structure and features are slightly different between vanilla meteor and the webpack version).

In the (not-so-distant) future, there are plans to move to the LTS version of Node.js and migrate the build tool to npm, so things are likely to change.

How to deploy a meteor application to my own server?

Meteor documentation currently says:

"[...] you need to provide Node.js 0.8 and a MongoDB server. You can
then run the application by invoking node, specifying the HTTP port
for the application to listen on, and the MongoDB endpoint."



So, among the several ways to install Node.js, I got it up and running following the best advice I found, which is basically unpacking the latest version available directly in the official Node.JS website, already compiled for Linux (64 bits, in my case):

# Does NOT need to be root user:

# create directory
mkdir -p ~/.nodes && cd ~/.nodes

# download latest Node.js distribution
curl -O http://nodejs.org/dist/v0.10.13/node-v0.10.13-linux-x64.tar.gz

# unpack it
tar -xzf node-v0.10.13-linux-x64.tar.gz

# discard it
rm node-v0.10.13-linux-x64.tar.gz

# rename unpacked folder
mv node-v0.10.13-linux-x64 0.10.13

# create symlink
ln -s 0.10.13 current

# add path to PATH
export PATH="~/.nodes/current/bin:$PATH"

# check
node --version
npm --version



And to install MongoDB, I simply followed the instructions in the MongoDB manual available in the Documentation section of its official website:

# Needs to be root user (apply "sudo" if not at root shell)

apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee /etc/apt/sources.list.d/10gen.list
apt-get update
apt-get install mongodb-10gen



The server is ready to run Meteor applications! For deployment, the main "issue" is where the "bundle" operation happens. We need to run meteor bundle command from inside the application source files tree. For example:

cd ~/leaderboard
meteor bundle leaderboard.tar.gz



If the deployment will happen in another server (flavour 2), we need to upload the bundle tar.gz file to it, using sftp, ftp, or any other file transfer method. Once the file is there, we follow both Meteor documentation and the README file which is magically included in the root of the bundle tree:

# unpack the bundle
tar -xvzf leaderboard.tar.gz

# discard tar.gz file
rm leaderboard.tar.gz

# rebuild native packages
pushd bundle/programs/server/node_modules
rm -r fibers
npm install fibers@1.0.1
popd

# setup environment variables
export MONGO_URL='mongodb://localhost'
export ROOT_URL='http://example.com'
export PORT=3000

# start the server
node main.js



If the deployment will be in the same server (flavour 1), the bundle tar.gz file is already there, and we don't need to recompile the native packages. (Just jump the corresponding section above.)



Cool! With these steps, I've got the "Leaderboard" example deployed to my custom server, not "meteor.com"... (only to learn and value their services!)

I still have to make it run on port 80 (I plan to use NginX for this), persist environment variables, start Node.JS dettached from terminal, et cetera... I am aware this setup in a "barely naked" one... just the base, the first step, basic foundation stones.

The application has been "manually" deployed, without taking advantage of all meteor deploy command magic features... I've seen people published their "meteor.sh" and "meteoric.sh" and I am following the same path... create a script to emulate the "single command deploy" feature... aware that in the near future all this stuff will be part of the pioneer Meteor explorers only, as it will grow into a whole Galaxy! and most of these issues will be an archaic thing of the past.

Anyway, I am very happy to see how fast the deployed application runs in the cheapest VPS ever, with a surprisingly low latency and almost instant simultaneous updates in several distinct browsers. Fantastic!

Thank you!!!

Does Meteor take advantage of multiple core systems?

The short answer is no, Meteor does not take advantage of multi core processors.

The reason is simple: Meteor is based on node.js, and by definition node.js will not automatically scale to multiple CPUs or CPU cores.

You may wonder if it's possible to somehow 'force' it to leverage multiple cores. Well, I think the answer to that is 'maybe, but not easily'. Recently node.js has included the cluster module http://nodejs.org/docs/latest/api/cluster.html which allows you to start child processes that return eventually. It might be a good use case for you, say if you are doing image manipulation on a large scale or something similar. But I'm not aware of any Meteor-native way of enabling this.

If you're looking at this from the point of view of scaling, you could try to fire up a node process per core by setting core affinity using Taskset on *nix, then spawn a meteor instance on each. That might work but my gut feel is your hardware is more likely to choke on I/O instead of CPU. Furthermore, at the moment it's not possible for two meteor servers to talk to each other.

You may have more luck when Meteor goes V1 - see this Trello note on the roadmap regarding server-to-server communications: https://trello.com/c/RKEYpJ4P/46-multitier-server-architecture-support-very-large-numbers-of-simultaneous-clients.

Finally, keep in mind that Meteor is still in development, and that Galaxy might (I'm speculating here) support multi-core processing. Galaxy is the meteor platform the team at MDG is currently working on. You can read more about this project on http://www.meteor.com/blog/2012/07/25/meteors-new-112-million-development-budget

I hope this helps.

How can I deploy my meteor app to an Ubuntu server in my local network?

I have handled this situation with the information in this link. It is not running the bundled version of meteor, but this is actually comes up as a better way to do it to make it easier to test on the local network.



Related Topics



Leave a reply



Submit