How to improve your Apache Web server’s performance?

Apache

The performance of web application depends upon the performance of the webserver and the database server.

You can increase your web server’s performance either by adding additional hardware resources such as RAM, faster CPU, etc. or you can get better performance on the same hardware through Cloud Management, by doing some custom configuration to the webserver.

Here are some custom configurations for better performances

  • Load only the required modules:

Apache server is a modular program which includes the functionality of selecting a set of modules. So it’s suggested to run Apache with only the required modules which will reduce the memory footprint and hence the server performance.

  • Choose appropriate MPM:

Apache comes with a number of Multi-Processing Modules (MPMs) which binds the network ports to the machine. But only one MPM can be loaded at a time, so choose the appropriate MPM for your application. It depends on various factors like, whether the OS supports threads, available memory, scalability versus stability, whether non-thread-safe third-party modules are used, etc.

  • DNS lookup:

Keep “HostnameLookups off” to reduce latency to every request since the DNS lookup has to be completed before the request is finished.

  • AllowOverride:

Make “AllowOverride all” to reduce additional file system lookups.

  • FollowSymLinks:

Add the option ‘FollowSymLinks’ to make the server follow the symbolic links in the directory.

  • Content Negotiation:

Option ‘Multiviews’ scans the directory for files, which causes latency.

  • MaxClients:

‘MaxClients’ is the limit on maximum simultaneous requests. It should be set to low so that new connections are put in queue.

  • MinSpareServers, MaxSpareServers, and StartServers:

The ‘MinSpareServers’ and ‘MaxSpareServers’ determines how many child processes should be kept waiting for request. Now you can adjust it as your requirement.

Listed below are some tweaks to help you around

StartServers—2

MinSpareServers—2

MaxSpareServers—5

ServerLimit—100

MaxClients—100

MaxRequestsPerChild—4000

  • KeepAlive and KeepAliveTimeout:

The ‘KeepAlive’ directive allows multiple requests to be sent over the same TCP connection. This is useful when HTML pages use a lot of images.

KeepAlive–on

Timeout–20

  • HTTP Compression & Caching:

Use mod_deflate module for HTTP Compression. Most of the browsers are supporting it.

  • Separate server for static and dynamic content:

For dynamic contents Apache server needs 3M to 20M of RAM, while for the static contents it consumes only 1M. To reduce latency use separate servers for static and dynamic contents.

  • Reducing network load:

Use ‘mod_gzip’ to compress the data in order to reduce bandwidth. Most of the browsers are supporting it.

How to create a form page in Refinery CMS app

Refinerycms

Refinery is a powerful CMS based on Rails framework. It gives a fully generated site with admin control features. However, we can extend it to create our own customized forms like Job Inquiry, Contact Us etc… by following this tutorial. Here is the environment we have used on this tutorial.Ruby 1.9.3, Rails 3.2.8 & RefineryCMS 2.0.8

Step#1

Cd to refinerycms application

Execute the following command to get all the options & usages to create a form engine in refinery CMS

rails g refinery:form

Step#2

Execute the following command to create a form. Let’s create a Job Inquiry form

rails generate refinery:form job_inquiry name:string message:text job_type:radio brochure:checkbox qualification:select

Step#3

Run the following commands

bundle install
 
rails generate refinery:job_inquiries
 
rake db:migrate<code></code>
 
<code>rake db:seed<code>

ss

This will create a “job inquiry” engine in the “vendor/extensions” folder

Step#4
Add the “job type” and “qualification” data in the “/vendor/extensions/job_inquiries/app/models/refinery/job_inquiries/job_inquiry.rb” model. You can also add other fields as per your requirement.

module Refinery
module JobInquiries
class JobInquiry < Refinery::Core::BaseModel       self.table_name = 'refinery_job_inquiries'       attr_accessible :name, :message, :job_type, :brochure, :qualification, :position       acts_as_indexed :fields => [:name, :message]
# Add some validation here if you want to validate the user's input
# We have validated the first string field for you.
validates :name, :presence => true
JOB_TYPES = ["Freelance", "Fulltime", “Contract”]
QUALIFICATIONS = ["MCA", "MTECH", "BTECH"]
end
end
end

Step#5

Restart the rails server to get the effect

That’s it! We will have a fully functional Job Inquiry form attached in our refinery application. This will also add the following functionalities automatically.

  • Mail send feature to Admin after submitting the job inquiry form
  • Auto email respond functionality to the user after submitting the form
  • Adds Job Inquiry menu in the Admin side to manage auto email respond message, mail id change to get job inquiry
  • Adds an Inbox in the Job Inquiry Menu for Admin to manage all the forms submitted through the Job Inquiry form

SEE ALSO: Creation of a new Rails App using Refinery CMS

If you have any other tips or rules that you follow, let us know in the comments below.

How to install Devise in Rails 3.x

ror41-150x150Devise is a flexible authentication solution for Rails based on Warden. Devise handles authentication across the entire stack. It has the following features:

  • Rack based
  • MVC based on Rails engines
  • Allows you to have multiple roles (or models/scopes) signed in at the same time
  • Modularity concept: use just what you really need

It is composed of 12 modules:

  • Database Authenticatable
  • Token Authenticatable
  • Omniauthable
  • Confirmable
  • Recoverable
  • Registerable
  • Rememberable
  • Trackable
  • Timeoutable
  • Validatable
  • Lockable

Steps to install the Devise

Step#1

Add the following gem in your Gemfile

gem 'devise'

Then run

bundle install

Step#2

To invoke the Devise in your application, run the devise generator

 rails g devise:install

The generator will install an initialize, which describes all devise’s configuration options.

Step#3

Create a model “User” using devise to handle authentication.

rails g devise User

This generator creates a few interesting things like a file, a migration and a devise_for in route.

Step#4

Run the migration

rake db:migrate

Step#5

Devise provides some helper methods to recognize a user after sign in and default route paths for “sign in”, “sign up” and “sign out”

We can modify our ‘app/views/layout/application.html.erb’ file to allow us to “sign out”, “sign in” and “sign up” by writing the following block

<div>
<% if user_signed_in? %>
Signed in as <%= current_user.email %>. Not you?
<%= link_to "Sign out", destroy_user_session_path,:method => :delete %>
<% else %>
<%= link_to "Sign up", new_user_registration_path %> or
<%= link_to "Sign in", new_user_session_path %>
<% end %>
</div>

Configuring views

Since Devise is an engine, all its views are packaged inside the devise gem.

Get all the view files for devise by running the following generate command

rails generate devise:views

You can also configure the message language, mailer from address and other things by editing the devise config files as located in following locations

devise.en.yml – config/locales
 
devise.rb – config/initializers

Now you are done to use the app with authentication!

How to use Amazon S3 Bucket with Paperclip to store images in Rails3

Amazon_S3_Online_Service-resized200-150x150

“S3 Bucket” is Amazon Simple Storage Service – a “highly durable and available store” and can be used to reliably store graphical and other applications contents such as media files, static assets and user uploads. It allows you to off-load your entire storage infrastructure. This feature facilitates better scalability, reliability, and speed than just storing files on the file-system.

It is an online storage web service offered by Amazon Web Services and provides storage through web services interfaces (REST, SOAP etc.)

Here is an example on how to use Amazon S3 with paperclip in Ruby on Rails applications.

Step#1

  • In rails 3.x

Install aws-s3 gem by adding in Gemfile

gem 'aws-s3'

And run

Run “bundle install”

Step#2

To get AWS S3 bucket ‘Access Key ID’ and ‘Secret Access Key’ go to the “http://aws.amazon.com/s3”

Create s3.yml file under config directory and enter your Amazon S3 credentials

development:
bucket: bucket-dev-name
access_key_id: xxxxx
secret_access_key: xxxxx
test:
bucket: bucket-test-name
access_key_id: xxxxx
secret_access_key: xxxxx
production:
bucket: bucket-prod-name
access_key_id: xxxxx
secret_access_key: xxxxx

Step#3

Open your model file that would hold the attachment and modify it as follows

###Paperclip
has_attached_file :photo,:styles =>{ :thumb => "100x100", :medium => "200x200", :large => "600x400" },:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",:path => ":attachment/:id/:style.:extension",:bucket => 'yourbucket'

Step#4

In view, to display the image

How to use ActiveRecord Callbacks in Rails

Rails3Callbacks are a great technique for achieving simplicity and flexibility. A callback allows you to run some code (usually a method) automatically when another piece of code runs. In Rails, you’ll commonly see callbacks that run before, after or even around other bits of code. Callback functions are minimizing the length of codes in controllers.

Implementing Callbacks

There are four types of callbacks accepted by the callback macros:

  • Method references (symbol)
  • Callback objects
  • Inline methods (using a proc)
  • Inline eval methods (using a string) – deprecated

Here is the list of some useful callback functions while saving AcriveRecord objects

  • before_save
  • after_save

before_save:

This method is called before an ActiveRecord object is saved.

class Post < ActiveRecord::Base before_save :update_slug protected def update_slug self[:slug] = [year, season_slug, season_type_slug].compact.join '/' end end

after_save:
Once the active record object saved some method will be fired in that scenario we have to use the after_save callback.

class Post < ActiveRecord::Base after_save :handle_status_changed protected def handle_status_changed Setting.create(:post_id=>self.id , :status => true) end end

Whats are the Differences in Community and Enterprise Editions

Since Magentoits mid-quarter release in 2008, Magento has been the first choice for E-commerce development and it still prevails the same effect.

Magento development is the most secure, flexible and customizable solution for business who are new to e-commerce or switching to this niche.

Upon its popularity and evolution, Magento Inc. has released two editions for Magento, the Community edition and the Enterprise edition. There is still some confusion among developers or users about these editions and their usability.

Let’s have a look at some differences between these two:

Advantages of Advanced Features and Functionality

Since its launch, Magento is open source and both editions are targeted to different audiences.

The community edition is meant for small startup e-commerce business with basic yet powerful solutions. At the same time, the Enterprise edition is meant for those retailers who require more advanced features, customization, and functionality to their e-commerce business.

Magento Team Support

With the Enterprise edition, the retailer signs a Service Level Aggrievement(SLA) with Magento support and will be having the advantage agents development team support for tiniest issues.

Neither the agreement nor the service is available to Community users. They can take care of support issues with their own development team or through Community discussion forums.

Efficient Bug Tracking

The bug Fixing service is provided to both of editions users which comes to act when you report a bug in your Magento platform to the Magento team.

Although the bug resolution service is available to both user types, however sometimes the Magento development team gives much priority to Enterprise edition users as compared to Community edition users due to SLAs.

If you’re a small startup you can manage with the Community edition, but if you’re a large retailer and switching for Magento then you got to choose the Enterprise or Enterprise Premium Edition.

With much more competition on retailing and so many new functionalities to count in for your business, you need to choose the right Magento edition.

Recently Magento also launched the Magento Go feature, where a non-techno buff can also create an e-commerce web app.

At Andolasoft, we always try to build a high quality e-commerce web app with a much higher quality interface, scalability, and customization. Magento development is one of our major expertise and we’ve developed many custom Magento based e-commerce applications, modules, and other extensions.

Whether you’re a startup e-commerce business or a large retailer switching to e-commerce, we can help you by building search friendly and secure websites as per your requirements. We’ve expert Magento developers who can provide top-notch year-round service for your e-commerce solution.