Best practice for Scalable project on ruby on rails. Problem: I don't understand the difference between web and app server in ror projects.
I understood that the differences between application and web servers are webserver handles requests and application has business logic. However I don't quite understand how I can implement it in my ruby on rails application.
So, I have, for example, two instances and ruby on rails application.
On the first server I want to set up a web server, and on the second one I want to install application server.
But, for example, I use passengers as my webserver that makes easier to deploy my ror application. So, will I have any benefits implementing such logic? Can I use passenger as an cache server or something like this? Is it possible to put passenger on another server and send request to ror application? Or I totally wrong and don't understand the conception?
Note: I just found amazon web application hosting architecture and now I'm trying to figure out how I can it implement and how it could work.
Use heroku with puma. That's the easiest to setup.
http://www.justinweiss.com/articles/a-web-server-vs-an-app-server/
https://www.nateberkopec.com/2015/07/29/scaling-ruby-apps-to-1000-rpm.html
https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server
Related
Iam a novice in rails and trying to write my first React frontend. I have read enough to know that there are different methods to use React with rails. I decided to split frontend and backend, and use rails in API mode. I cannot find good sources explaining what I need on my server to get rails and react going, and why. I read so far about npm, node.js, Heroku and so on, but i lack the knowledge to decide what to pick and i dont understand the interactions yet.
Does someone know a good tutorial, some sources or keywords to point me to a direction?
If you want to use Rails just in API mode with React on frontend then you can separate those apps completely.
I.e. use Rails/Puma server for API and have a separate server (Nginx/Apache/Node.js) to serve the frontend React app and other static assets.
For using react as your client-side application and rails for the server-side you need two different applications. As Rails is MVC I suggest you use just ruby and Sinatra server.
In this situation be careful about the cross-origin errors you have to enable it while using two agents.
Take a look at this.
I'm developing a web application with an AngularJS frontend and a Rails backend.
My goal is to keep the two entirely separate, since the Rails app will ultimately be relegated to a simple REST server, and the AngularJS frontend will be just one of a few different clients that use the backend. For that reason, I don't want to integrate the frontend into the Rails asset pipeline, or similar.
The Rails app is running locally on port 3000. The frontend uses Gulp to compile static assets, and BrowserSync, which contains a development server that I'm running on port 3001.
For development purposes, how can I get the AngularJS app to talk to the Rails server, avoiding this browser error (which I'd expected) when making HTTP request via Angular's $http service?
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:3001' is therefore not allowed access.
Do I just need to set up CORS in the Rails app? Is there another way - maybe some sort of local hosts file trick (I'm on a Mac, FWIW) or similar? I ask because my coworker is responsible for the Rails app (I have limited experience with Rails) but is out of town for a while; my knowledge is mostly limited to the AngularJS stack that I've set up.
I've searched and read up for about an hour, but haven't yet been able to find anything that I can grok that is applicable to my situation. I might not be aware of the best search terms.
Thanks for any help!
Ah, wonderful. Here are a few solutions:
set up CORS, which shouldn't be too hard. All you have to do is add the headers to pages serving your static content (not the rails REST endpoints), The problem with this is you shouldn't really be doing it unless you have a good reason (so see 3). How are you serving the static content? There should be plugins to do the headers for you if it's a popular tool
serve the angularJS pages from the rails backend for now (using some kind of static route)
if you're thinking about production and want to sort this out for good, use nginx to proxy the two services into one single domain, http://nginx.org/en/docs/beginners_guide.html
I have a single controller implementing my SOAP webservice API using the datanoise-actionwebservice (2.3.2). I am not using Rail as a web app or website to serve any static content at all - it is purely running as a webservice, with direct Mysql.real_connect based queries from the controller code. This is more from my lack of deeper understanding of how to use the model part of Rails, but more practically because the queries are pretty complex and easier to code.
This webservice further makes SOAP webservice calls to other legacy services, and replies back to the windows based webservice client apps.
Challenge is that I have so far used the default mongrel server to handle the multiple calls to my API across several terminals, but obviously need to redeploy mongrel as a cluster or use other setups such as passenger to improve the response time to the clients. I'm unable to find a simple HOWTO for achieving this or comparable approaches - most point to usage as a website/webapp, where the need for apache etc. is more for serving statick content and CSS etc., along with the ruby part.
Can anyone point me to a resource where I can setup the cluster to handle multiple webservice calls concurrently and process in the controller and respond. Does rails automatically instantiate a controller for each webservice request so that it gets done in parallel? Or do we need to rewrite using available libraries?
Any help/advice is much appreciated. I cannot rewrite anything - it needs to be in Rails2.3.5/Ruby1.8.7 - upgrades are not an option as this is already working in production, and datanoise itself doesn't seem to like 1.8.7+ or Rails 3 from what I can see.
Cheers!
Fundamentally, you need to run more than one Mongrel.
The mongrel processes will become your backend servers, and you will need to run a front-end load-balancing proxy.
The thing is, the advantage of the pure-Ruby single-threaded Mongrel is easy setup. Once you move beyond the easy-setup realm, you may as well deal with the complexity of running Passenger. Passenger will do the load balancing internally.
If it was me, I would compile nginx or tengine from source, as it does not include Passenger out-of-the-box. This is as simple as adding an argument to the configure script.
# gem install rake rack passenger --no-rdoc --no-ri
# exit
$ ./configure --add-module=`passenger-config --root`/ext/nginx
$ make
Hi I've been learning rails for the past half year and have a few apps up on Heroku. So for me I thought deploying apps onto the world wide web was just as simple as heroku push. However, I just got my first internship doing Rails and one of my seniors is talking about Apache and Nginx and I'm not sure how they fit in the picture, since I thought apps consisted of only Rails + cloud app platform. I have looked it up but I still don't get how and where it affects my app life cycle. Can someone explain what/where/when of using web servers?
So you've got your Rails app, and as you know you've got controllers and actions and view and what not.
When a user in their browser goes to your app on Heroku, they type in the URL which points to the Heroku servers.
The Heroku servers are web servers that listen to your users that type in the URL and connect them to your Rails application. The rails application does its thing (gets a list of blog posts or whatever) and the server sends this information back to your user's browser.
You've been using a web server the whole time, just it was abstracted away from you and made super simple thanks to Heroku.
So the life cycle is somewhat like this:
Whilst you've been building your applications on your development machine you've probably come across the command rails server. This starts a program called WEBrick which is a web server, and listens on port 3000. You go to your app via http://localhost:3000.
WEBrick listens on port 3000 and responds to requests from users, such as the "hey give me a list of posts" command.
When you push your code into production (in your experience via heroku push) you're sending your code a provider who takes care of the production equivalent of rails server for you.
A production setup (which your senior developers are talking about) is a bit more complex than your local rails server setup on your development machine.
In production you have your Rails server (often things like Unicorn, Passenger) which takes the place of WEBrick.
In a lot of production setups, another server, such as Apache or nginx is also used, and is the server that the user connects to when they go to your application.
This server exists often as a bit of a router to work out how different types of requests should be handled. For instance, requests to static files (css, images, javascript etc) that are storted on the server might just be processed directly by Apache or nginx, since it does a fantastic (and fast) job of sending static assets back to the client.
Other requests, such as "get me a list of all blog posts" get passed onto the Rails server (Unicorn, Passenger etc) who in turn do the required work and send the response to Apache/nginx, who send it back to the client.
Heroku does all this for you in a nice easy to use package, but it sounds like the place your working at manages this themselves, rather than using Heroku. They've setup their own bunch of web servers, and will have their own way doing an equivalent of heroku push which will send the code to the servers, and make sure they're up and running ready to respond to user requests.
Hope that helps!
Web Pages need a Web Server to make them available on the Internet.
So a site that is all static content (all just .html pages) just needs a web server and that's where Apace, nginx, etc come in. They are web servers.
When you use frameworks like rails, an additional component is added, an application server. This pre-processes the pages using the rails framework and then (still) uses the above mentioned web server to make the final pages (which are .html of course) available to the end users through their browser.
Passenger Phusion is an application server that, with rails will help manage and automate the deployment of code.
Heroku is a cloud service, meaning they take care of hardware and software allowing you to seamlessly publish you application without worrying about what is going on behind the scene. So the only thing you have to do is push your code to their Git and voila.
On the other hand, Rails can also be deployed on a system built by you completely from scratch, and you will be the responsible not only for the app development but also for the server maintenance and choice of the hardware and/or software. You could then choose between several application servers capable of running rails such as ngix.
Hope that helps.
I'm very new to web programming (or actually, very old to it, since the last time I messed with the web was HTML 1.1), but now need to deploy a web application quickly. It seems like every time I turn around, there's new acronyms and technologies to learn (JSON, XMLRPC, GWT, Javascript, Rails, etc).
Here's what my app must do:
Given a username and password, authenticate (easy enough, everything does that, apparently).
Allow the user to upload a large glob of data for processing.
Process that data.
Allow the user to download their processed data.
I've already got Java scripts and a database for handling the data. On one machine, I can run a series of command-line programs to process an incoming datablock and put the results back into a mysql database. That is already present and working.
I want to construct a web front-end to this task, using these existing and tested methods. I'm currently leaning to this approach:
Have two machines, a database machine and a web server. That approach allows for later scalability, if necessary, but also requires that I can't assume that the programs that I use to access the data and manipulate it are locally stored.
Use a Ruby DRb application to create a server and a client. The client would pass data to the server which would in turn call these applications.
Use some other Ruby interface to interact with the DRb for the web frontend.
Here's my problem: it looks like most Ruby applications for the web automatically try to build some kind of local database. All the Rails tutorials I've found start with making your own database and interacting with that, which is exactly what I don't want to do.
Is Rails the right technology for me, or using Ruby DRb? Is there some other technology I should be exploring?
If Rails or Ruby is the Right Thing here, what should I be looking at? I already have the Programming Ruby book, and have used that for some of the backend stuff as well as getting basic DRb stuff working.
Sounds like Rails might be a bit heavyweight for your situation. Perhaps Sinatra might be a better fit? It's an ultra-lightweight framework: a hello world app might look something like:
require 'sinatra'
get '/' do
"Hello World!"
end
Rails is fine. You can have development and test databases on your local machine and the production database on a remote machine. It doesn't have to be the web server. Get a copy of Agile Web Development with Rails. It'll teach you all you need to know.