• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Using Apache as an Application Server
 

Using Apache as an Application Server

on

  • 6,531 views

 

Statistics

Views

Total Views
6,531
Views on SlideShare
6,531
Embed Views
0

Actions

Likes
3
Downloads
76
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • My book is about building IMAs <br />
  • <br />

Using Apache as an Application Server Using Apache as an Application Server Presentation Transcript

  • Using Apache as an Application Server Phillip J. Windley, Ph.D. Founder and CTO Kynetx
  • Assumptions You’ve heard of Apache You’ve heard of Perl You’d like to build Web applications with less effort
  • Anti-Assumptions You’re familiar with mod_perl You’re an Apache expert You know what an application ser ver is and why you’d want one
  • Application Server Program that supplies support for running applications: Process and thread management Security Logging Interprocess communication Request dispatching
  • Popular Application Ser vers You might have heard of Tomcat JBoss WebLogic WebSphere
  • Application Server Benefits Flexibility through indirection (intermediary) Resource management Focused developer roles Maintainability Security Scalability Feature augmentation
  • Kynetx
  • Context automation services to link tasks across multiple Web-sites
  • Dynamically rearrange the DOM (post-delivery) based on client supplied rules, Web services, and browser context
  • Rule Language rule frequent_archive_visitor is active { select using "/archives/d+/d+/" setting () pre { c = counter.archive_pages; } if counter.archive_pages > 2 within 3 days then { replace_html("prize_div", "You win the prize! You've seen " + c + " pages from the archives!") } fired { clear counter.archive_pages; } else { counter.archive_pages += 1 from 1; } }
  • Kynetx Information Flow
  • We need a rule interpreter that dynamically serves Javascript
  • Rule execution must be as fast as possible
  • Amazon AWS deployment and scaling a necessity
  • Possible Architectures Standard Web application Custom HTTP server Apache module
  • Architecture Decisions Implement rule interpreter as an Apache module No database for scalability No session pinning Store rules in versioned repository
  • Detailed Architecture
  • Apache as an Application Server
  • Apache Fast and efficient Portable Well supported Won’t go away (open source) Stable and reliable Plenty of features Extensible Easy to administer
  • Apache Modules
  • Modules are NOT CGI Programs Modules run inside the Apache process architecture Modules have access to and can replace all Apache ser vices Uses the ser ver API - not an embedded interpreter Access to every part of the HTTP request lifecycle
  • Apache Server Lifecycle
  • HTTP Request Lifecycle
  • We’ve got both kinds: C & Perl!
  • Apache Application Ser vices Configuration Process and thread management Security Logging Interprocess communication Request dispatching
  • Configuration Support Via Apache configuration file Setting variables that can be seen in Perl $r->dir_config('memcached_hosts')
  • Configuration <LocationMatch /kobj/> # env var to turn on rule logging PerlSetEnv KOBJ 1 # host names PerlSetVar init_host init PerlSetVar log_host logger PerlSetVar action_host cs PerlSetVar frag_host frag # mode => development, production, test PerlSetVar run_mode development PerlSetVar memcached_hosts 192.168.2.2 PerlAddVar memcached_hosts 192.168.2.3 SetHandler perl-script PerlHandler Kynetx # Perl module name </LocationMatch>
  • Process & Thread Management Apache 2.X uses multi-processing modules (MPMs) to provide a flexible way to change the execution model prefork - Apache 1.3 worker - Hybrid, based on pthreads OS specific - Windows, BeOS, etc. perchild - virtual hosts with custom UID’s
  • Process & Thread Management <IfModule prefork.c> StartServers 5 MinSpareServers 8 MaxSpareServers 15 MaxClients 150 MaxRequestsPerChild 0 </IfModule>
  • Apache manages the processes
  • Start with one process model and switch to another later
  • Security Apache HTTP access, authentication, and authorization (AAA) isn’t very good for people HTTP AAA works fine for machines (usually) Standard mod_auth mod_access You can also override the AAA phases of the HTTP request cycle
  • Avoid AAA code in your application
  • Interprocess Communication Lots of Perl Modules IPC::SysV IPC::Shareable IPC::Semaphore IPC::ShareLite Cache::Cache Apache::Session
  • Apache::Session
  • Apache::Session Example my $mem_servers = Kynetx::Memcached::get_memcachedb_servers(); tie %{$session}, 'Apache::Session::Memcached', $cookie, { Servers => $mem_servers, NoRehash => 1, Readonly => 0, Debug => 1, CompressThreshold => 10_000 }; return $session;
  • Logging Apache has a great logging facility Use the standard Apache logging commands Apache2::Log
  • Logging LogFormat "%h %t %{TOTAL_SECS}e %{SITE}e %{TXN_ID}e "%{CALLER}e" % {SID}e "%{REFERER}e" "%{TITLE}e" [%{RULE_NAMES}e] [%{RESULTS}e] [% {ACTIONS}e] [%{TAGS}e] [%{LABELS}e] " KOBJ CustomLog "|/web/sbin/cronolog --period=5 --symlink=/web/logs/ kynetx_log /web/logs/kynetx/KOBJ-%Y%m%d-%H%M.log" KOBJ env=KOBJ
  • Logging $r->subprocess_env(SITE => $request_info->{'site'}); $r->subprocess_env(RULE_NAMES => join(',', @{ $rule_env->{'names'}})); $r->subprocess_env(RESULTS => join(',', @{ $rule_env->{'results'}}));
  • Request Dispatching Request dispatching says what to do for each URL or URL pattern Turns out that Apache is really good at this Request dispatching is known as “routes” in Rails
  • Dispatch Example Translate http://example.com/news/20021031/09/index.html to http://example.com/perl/news? date=20021031;id=09;page=index.html before news sees it.
  • Three Methods Use configuration file Use mod_rewrite Use custom Translation stage handler You can do anything you want here
  • Request Dispatching Example <LocationMatch /kobj/> SetHandler perl-script PerlHandler Kynetx # Perl module name </LocationMatch> <LocationMatch /js/> SetHandler perl-script PerlHandler Kynetx::KOBJ # Perl module name </LocationMatch> <LocationMatch /cb/> SetHandler perl-script PerlHandler Kynetx::Callbacks # Perl module name </LocationMatch>
  • What’s Missing? Event monitoring Timers Long running processes
  • Other Tools You Might Use mod_header mod_deflate Authentication modules Authorization modules
  • The End 46
  • Contact Information Contact me phil@windley.org www.windley.com www.kynetx.com Questions?