Click here to learn
about this Sponsor:
Home  |  News  |  Articles  |  Polls  |  Forum

Keywords: Match:
Implementing an embedded Linux web app framework
by Cliff Brake (Aug. 3, 2006)

Foreword -- This article describes a way to build embedded Linux web applications that follow the "Model, View, Controller" (MVC) software architecture popular nowadays among enterprise web application developers, yet are capable of running on a 130MHz ARM processor. The method is based on several popular open source software components. Enjoy . . . !



How to implement a web application framework in an embedded Linux system

by Cliff Brake

As devices are increasingly more networked, an embedded web server is becoming a standard way for users to interact with and configure an embedded device using a standard web browser. As an example, most pieces of networking equipment (such as routers and wireless access points) are configured this way.

There are many ways to implement a web server. One way is to just write a monolithic program that handles the requests and outputs HTML using print statements. Without a lot of planning, you usually end up with something where logic is intermixed with presentation. The disadvantage of such an approach is that it quickly becomes very difficult to maintain your web application as it grows and changes. The current best practice with web application frameworks (such as Ruby on Rails) splits a web application into 3 distinct components (Model, View, Controller -- MVC) so that changes to one component can be made with minimal impact to others.

This article details a solution used in a recent project to implement such an architecture using the following open source components: SQLite, Clearsilver, and Python. The challenge was to find a solution that performed acceptably on a resource constrained 130MHz ARM-Linux system.

Components Used

The requirements for the web application framework for this system are:
  • Footprint must be fairly small -- less than 10MiB.
  • Must enable us to implement a clean MVC type architecture
  • Must support a high level language like python for rapid development
  • Includes a database
  • Reasonable performance -- less than 1 second to render a typical page

After researching and testing several options, the following components were chosen to implement the framework:
  • Web Server: Cherokee (1MiB)
  • Model: SQLite (290KB)
  • View: Clearsilver (170KB)
  • Controller: Python (2-3MB)


Web application architecture


Total size for the above components is about 4MB.

The following sequence occurs during a typical web transaction:
  • An HTTP request is received by Cherokee
  • If the request matches the URI for the web application, Cherokee forwards the request to the web application framework via CGI
  • Clearsilver parses the HTTP headers (including CGI GET and POST parameters) and provides the data to python in easy-to-access HDF (hierarchical data format)
  • Python looks at the URI and dispatches the request to the appropriate function; data is extracted from the SQLite database and an HDF datastructure is created.
  • Clearsilver is called to render the appropriate template; data from the HDF datastructure is used in the template to provide the dynamic content in the page
  • The rendered HTML is passed back to Cherokee, and is then returned to the user's web browser
Each of these components is discussed in more detail in the following sections.

Performance

One of the issues with modern web frameworks is that most require a lot of processing power. Many frameworks are written in interpreted languages, which tend to be not very efficient on embedded systems such as the 130MHz ARM-Linux system used in this project. As most of the application development for this project is done in Python, I tried several other Python-based solutions with the following results:
  • Django -- takes 10 seconds to render a page
  • webpy -- takes 5 seconds to render a page
  • Clearsilver/Python -- takes about 1 second to render a page
Anything over 1 second is very slow for a web interface. With fastcgi, webpy could probably have been sped up to be acceptably fast, but I don't think there is much hope for frameworks like django on this type of system. I have read of similar experiences trying to run Ruby-on-Rails on ARM-Linux systems. As I'm currently just using a basic CGI interface, the Clearsilver solution could also be sped up significantly as well, if the Python portion could be kept running between requests with fastcgi or a similar mechanism.

Cherokee Web Server

A web application typically consists of a web server (like Apache) and a program that provides the dynamic web content. Some of the functions of a web server are:
  • receives HTTP requests
  • handles the request by serving static files/images or routes the request to a program that outputs dynamic content
  • authentication
  • encryption (SSL, TLS)
There are many web servers that can be used in embedded devices. Some of them are:Cherokee was chosen for this application because it provides a good balance between the size and functionality I am looking for. It is also included in the OpenEmbedded build system I am using. Other systems will have different requirements -- use the one that fits your application best.

Clearsilver

Clearsilver is the real gem that was discovered during this exercise. Clearsilver is a language-neutral HTML template system written in C. It is used as the templating system for many high volume sites such as Google Groups 2. Clearsilver also provides CGI handling functions and bindings to several languages including Python.

The fact that it is written in C and is fast for high volume sites also makes it fast enough on slower embedded systems. Because Clearsilver is written in C, the templating system is already fast. Parts or all of the application can also be moved to C as needed to get the required performance. Having a performance upgrade path is nice. Clearsilver also forces a strict separation of application logic and presentation templates, which keeps things in line with the MVC architecture.

SQLite

SQLite is a small C library that implements a self-contained, embeddable, zero-configuration SQL database engine. SQLite works as expected and also has bindings to a number of languages including Python. A SQLite database is just a single file that requires no configuration, making it very easy to use. The database engine runs in the same process as the application using it, which increases performance because there is no context switch when running database operations.

Because SQLite does not have its own process, it does not handle concurrency as well as other databases such as MySQL, but in an embedded system you seldom have more than one process using the database. SQLite provides some support for concurrency with reader/writer locks for the entire database. If your application is not real busy, this is often adequate if you need two processes to share some data.

Python

Python is the glue that ties things together in this web application framework. It sits between Clearsilver and the database. The advantages of using a language like Python are rapid development and an extensive library. Python is considerably slower than C, but there is always the option to move parts of the application into C as needed.

OpenEmbedded Build System

How does one put together a system with all these components? The answer is the OpenEmbedded Build System (OE). OE includes support for all of the components discussed in this article.

Summary

The combination of Python, Clearsilver, and SQLite provides a compelling solution for a web application framework in an embedded Linux system. The solution is reasonably small, performs well, and provides a path to improve performance if needed. We also get a clean architecture to create clean, maintainable web applications.


Copyright (C) BEC Systems, 2006. All rights reserved. Reproduced by LinuxDevices.com with permission.



About the author -- Cliff Brake owns BEC Systems, a consulting operation that "helps customers utilize modern computer technologies in their products." BEC offers a range of services "to make its customers' embedded projects a success," including technology selection, development, troubleshooting, and training. Further information and other free resources are available on the company's website.



Related Stories:

(Click here for further information)


FUEL Database on MontaVista Linux
Whether building a mobile handset, a car navigation system, a package tracking device, or a home entertainment console, developers need capable software systems, including an operating system, development tools, and supporting libraries, to gain maximum benefit from their hardware platform and to meet aggressive time-to-market goals.

Breaking New Ground: The Evolution of Linux Clustering
With a platform comprising a complete Linux distribution, enhanced for clustering, and tailored for HPC, Penguin Computing¿s Scyld Software provides the building blocks for organizations from enterprises to workgroups to deploy, manage, and maintain Linux clusters, regardless of their size.

Data Monitoring with NightStar LX
Unlike ordinary debuggers, NightStar LX doesn¿t leave you stranded in the dark. It¿s more than just a debugger, it¿s a whole suite of integrated diagnostic tools designed for time-critical Linux applications to reduce test time, increase productivity and lower costs. You can debug, monitor, analyze and tune with minimal intrusion, so you see real execution behavior. And that¿s positively illuminating.

Virtualizing Service Provider Networks with Vyatta
This paper highlights Vyatta's unique ability to virtualize networking functions using Vyatta's secure routing software in service provider environments.

High Availability Messaging Solution Using AXIGEN, Heartbeat and DRBD
This white paper discusses a high-availability messaging solution relying on the AXIGEN Mail Server, Heartbeat and DRBD. Solution architecture and implementation, as well as benefits of using AXIGEN for this setup are all presented in detail.

Understanding the Financial Benefits of Open Source
Will open source pay off? Open source is becoming standard within enterprises, often because of cost savings. Find out how much of a financial impact it can have on your organization. Get this methodology and calculator now, compliments of JBoss.

Embedded Hardware and OS Technology Empower PC-Based Platforms
The modern embedded computer is the jack of all trades appearing in many forms.

Data Management for Real-Time Distributed Systems
This paper provides an overview of the network-centric computing model, data distribution services, and distributed data management. It then describes how the SkyBoard integration and synchronization service, coupled with an implementation of the OMG¿s Data Distribution Service (DDS) standard, can be used to create an efficient data distribution, storage, and retrieval system.

7 Advantages of D2D Backup
For decades, tape has been the backup medium of choice. But, now, disk-to-disk (D2D) backup is gaining in favor. Learn why you should make the move in this whitepaper.

 


Got a HOT tip?   please tell us!
Free weekly newsletter
Enter your email...
Click here for a profile of each sponsor:
PLATINUM SPONSORS
GOLD SPONSORS
(Become a sponsor)

ADVERTISEMENT
(Advertise here)

Check out the latest Linux powered...

mobile phones!

other cool
gadgets



BREAKING NEWS

• Wind River buys Mizi Research
• Home automation panel runs Poky Linux
• "Green" integrated PC runs Linux
• Intel acquires Linux distro developer
• Linux Space Cube ready for blast-off
• Nettop is "almost fanless"
• Tutorial sounds alarm for Nokia tablets
• CG Linux distro supports multicore MIPS64
• Embedded Linux guide updated
• Patent dispute threatens GPS imports
• MIDs offer Atom, HSDPA
• Software connects Linux MIDs to PC media
• Linux radio keeps it simple
• Motorola U9 takes fashion "beyond thin"
• Location-aware social net app targets MIDs


Most popular stories -- past 90 days:
• Open source phone goes mass-market
• Updated! Linux Mobile Phones Showcase
• World's cheapest Linux-based laptop?
• Garmin Nav devices run Gnome Linux
• First Atom-based notebook runs Linux
• ARM9 board boots Debian in 0.69 seconds
• Open source camera records geotagged video to SATA HDD
• Linux-friendly Beagle fetches $150
• "PDA phone" runs Linux
• Intel offers $80 "Little Falls" Atom mobo
• Netflix Player runs Linux


DesktopLinux headlines:
• Summit debuts for Linux end users
• "UbuntuLite" reviewed
• Linux in the SME
• Linux: not yet photo-friendly
• Linux to gain anti-virus software
• Linux gains backup utility
• Testing Lenny
• HP offers Linux on low-end mini-notes
• Dell shipping five Hardy Heron systems
• IBM pushes "Microsoft-free" desktops


Also visit our sister site:


Sign up for LinuxDevices.com's...

news feed

Home  |  News  |  Articles  |  Polls  |  Forum  |  About  |  Contact
 

Ziff Davis Enterprise Home | Contact Us | Advertise | Link to Us | Reprints | Magazine Subscriptions | Newsletters
Tech RSS Feeds | White Papers | ROI Calculators | Tech Podcasts | Tech Video | VARs | Channel News

Baseline | Careers | Channel Insider | CIO Insight | DesktopLinux | DeviceForge | DevSource | eSeminars |
eWEEK | Enterprise Network Security | LinuxDevices | Linux Watch | Microsoft Watch | Mid-market | Networking | PDF Zone |
Publish | Security IT Hub | Strategic Partner | Web Buyer's Guide | Windows for Devices

Developer Shed | Dev Shed | ASP Free | Dev Articles | Dev Hardware | SEO Chat | Tutorialized | Scripts |
Code Walkers | Web Hosters | Dev Mechanic | Dev Archives | igrep

Use of this site is governed by our Terms of Service and Privacy Policy. Except where otherwise specified, the contents of this site are copyright © 1999-2008 Ziff Davis Enterprise Holdings Inc. All Rights Reserved. Reproduction in whole or in part in any form or medium without express written permission of Ziff Davis Enterprise is prohibited. Linux is a registered trademark of Linus Torvalds. All other marks are the property of their respective owners.