stargeek
PHP news website logo.
home    PHP scripts    articles    seo tools    links    search    contact    shop    realtors


Implementing Flood Control







Implementing Flood Control

Implementing Flood Control 12/19/2004 03:27 PM

If the load of application relies on incoming events, you may eventually face the happy curse of popularity: too much work to do with your available resources. If you set a limit on how many events you can process within a time period, you can avoid the flood. Vladi Belperchinov-Shabanski explains the algorithm and demonstrates working code.




This is a GrokNews Entry: (what is grok?)





Similar Items

Implementing Flood Control

Grok Headline matches for Implementing Flood Control

Implementing An ADO Data Control With
VB6


Implementing An ADO Data Control With
VB6
06/18/2002 10:19 AM
The ADO data control can save Visual Basic developers hours of time. In this article Susan shows us exactly how to go about implementing an ADO control. 5 Free Bonuses!!! "Attention All Web Developers" Now includes 5 FREE eBooks to help you promote your ConMan website! "This is one of the best pieces of software that we have ever used. It's quick, streamlined, and allowed us to have a fully working site packed with articles in just 3 hours" Ever wanted to run your own content driven web site? Well now you can with ConMan: the fast, flexible and secure web site + admin suite. Try it for free!Click here. Get notified when we post new content: New Forum Threads 1. How do i do this? 2. C# editor of your choice? 3. Article Added Date 4. ASP Developer Seeking Employment 5. Hlp pls. - 1 record per page, refresh through records problem 6. your site was down :( 7. Can't get html editor to work properly 8. New website & advice 9. mysql tables 10. Article Type More Forum Threads... Other Recent Articles An Introduction To The Bulk Copy Utility // by Mitchell Harper - 12th Jun 2002

Implementing CSS (Part 1)


Implementing CSS (Part 1) 06/05/2005 11:17 PM

One of the most interesting problems (to me at least) in browser layout engines is how to implement a style system that can determine the style information for elements on a page efficiently. I worked on this extensively in the Gecko layout engine during my time at AOL and I've also done a lot of work on it for WebCore at Apple. My ideal implementation would actually be a hybrid of the two systems, since some of the optimizations I've done exist only in one engine or the other.

When dealing with style information like font size or text color, you have both the concept of back end information, what was specified in the style rule, and the concept of front end information, the computed result that you'll actually use when rendering. The interesting problem is how to compute this front end information for a given element efficiently.

Back end information can be specified in two different ways. It can either be specified using CSS syntax, whether in a stylesheet or in an inline style attribute on the element itself, or it is implicitly present because another attribute on the element specified presentational information. An example of such an attribute would be the color attribute on the font tag. Both WebCore and Gecko use the term mapped attribute to describe an attribute whose value (or even mere presence) maps to some implicit style declaration.

A rule in CSS consists of two pieces. There is the selector, that bit of information that says under what conditions the rule should match a given element, and there is the declaration, a list of property/value pairs that should be applied to the element should the selector be matched.

All back end information can ultimately be thought of as supplying a declaration. A normal rule in a stylesheet that is matched has the declaration specified as part of the rule. An inline style attribute on an element has no selector and is simply a declaration that always applies to that element. Similarly each individual mapped attribute (like the color and face attributes on the font tag) can be thought of as supplying a declaration as well.

Therefore the process of computing the style information for an element can be broken down into two phases. The first phase is to determine what set of declarations apply to an element. Once that back end information has been determined, the second phase is to take that back end information and quickly determine the information that should be used when rendering.

WebCore (in upcoming Safari releases) has a really cool optimization that I came up with to avoid even having to compute the set of declarations that apply to an element. This optimization in practice results in not even having to match style for about 60% of the elements on your page.

The idea behind the optimization is to recognize when two elements in a page are going to have the same style through DOM (and other state) inspection and to simply share the front end style information between those two elements whenever possible.

There are a number of conditions that must be met in order for this sharing to be possible:
(1) The elements must be in the same mouse state (e.g., one can't be in :hover while the other isn't)
(2) Neither element should have an id
(3) The tag names should match
(4) The class attributes should match
(5) The set of mapped attributes must be identical
(6) The link states must match
(7) The focus states must match
(8) Neither element should be affected by attribute selectors, where affected is defined as having any selector match that uses an attribute selector in any position within the selector at all
(9) There must be no inline style attribute on the elements
(10) There must be no sibling selectors in use at all. WebCore simply throws a global switch when any sibling selector is encountered and disables style sharing for the entire document when they are present. This includes the + selector and selectors like :first-child and :last-child.

The algorithm to locate a shared style then goes something like this. You walk through your previous siblings and for each one see if the above 10 conditions are met. If you find a match, then simply share your style information with the other element. Such a system obviously assumes a reference counting model for your front end style information.

Where this optimization kicks into high gear, however, is that it doesn't have to give up if no siblings can be located. Because the detection of identical style contexts is essentially O(1), nothing more than a straight pointer comparison, you can easily look for cousins of your element and still share style with those elements.

The way this works is that if you can't locate a sibling, you can go up to a parent element and attempt to find a sibling or cousin of the parent element that has the same style pointer. If you find such an element, you can then drill back down into its children and attempt to find a match.

This means that for HTML like the following:

<table>
<tr class='row'>
<td class='cell' width=300 nowrap>Cell One</td>
</tr>
<tr class='row'>
<td class='cell' width=300 nowrap>Cell Two</td>
</tr>

In the above example, not only do the two rows share the same style information, but the two cells do as well. This optimization works extremely well for both old-school HTML (in which many deprecated presentational tags are used) and newer HTML (in which class attributes might figure more prominently).

Once the engine determines that a style can't be shared, i.e., that no pre-existing front end style pointer is available, then it's time to figure out the set of declarations that match a given element. It is obvious that for inline style attributes and mapped attributes that you can find the corresponding declaration quickly. The inline style declaration can be owned by the element, and the mapped attributes can be kept in a document-level hash. WebCore has a bit of an edge over Gecko here in that it treats each individual mapped attribute on an element as a separate declaration, whereas Gecko hashes all of the mapped attributes on an element as a single "rule." This means that Gecko will not be able to share the mapped attribute declaration for the following two elements:

<img width=300 border=0>
<img width=500 border=0>

WebCore creates three unique declarations and hashes them, one for a width of 300, one for a width of 500, and one for a border of 0. Gecko creates two different "rules," one for (width=300,border=0) and another for (width=500,border=0). As you can see in such a system, you will frequently not be able to treat the identical border attributes as the same.

Aside from this difference in mapped attribute handling, the two engines employ a similar optimization for quickly determining matching stylesheet rules called rule filtering. All rules that are potentially matchable by any element (i.e., that have the correct media type) are hashed based on the contents of the rightmost simple selector in the rule.

A selector in CSS can be either simple (meaning that all of the contents of that selector apply only to a single element) or compound (meaning that you may examine multiple elements like parents or siblings of that element). A compound selector is essentially a chain of simple selectors, so the following rule:

tr > td { color: blue }

has two simple selectors, tr and td. The rightmost simple selector in the rule is the one that we will use for the rule filtering optimization.

The rightmost simple selector falls into four categories.

(1) The selector uses an ID. (Example: #foo)
(2) The selector doesn't have an ID but uses a class. (Example: .foo)
(3) The selector has no class or ID but specifies a tag name. (Example: div)
(4) The selector specifies none of these things. (Example: *[disabled])

The rule is placed into one of four hashtables depending on which category it falls into. The idea behind these categorizations is to always filter out more specific information first. For example, if an element has a specific ID, then obviously any rules whose rightmost selector uses a different ID cannot match. Technically the last category can just be a list and not a hashtable, since those rules must always be examined by all elements.

Each hashtable, therefore, consists of a mapping from a given atomic string to a set of rules that match. The class attribute is exceptional in that you must put the rule into the hashtable multiple times if multiple class attributes are used.

When determining the set of rules that match a given element, you only examine rules that correspond to the correct hash entry based off your ID, classes and tag name. This optimization basically eliminates 95+% of the rules up front so that they need not even be considered during the matching process.

Each rule is then examined in detail, with all selectors being checked, to determine if it is a match, and the set of matches is collected. The set of matches can then be sorted by priority and specificity such that all the declarations are in the proper application order.

This brings us to the final phase of the style computation, which is taking the set of matches and quickly computing the appropriate front end style information. It is here that Gecko really shines. What I implemented in Gecko was a data structure called the rule tree for efficient storing of cached style information that can be shared *even when* two elements are not necessarily the same.

The idea behind the rule tree is as follows. You can think of the universe of possible rules in your document as an alphabet and the set of rules that are matched by an element as a given input word. For example, imagine that you had 26 rules in a stylesheet and you labeled them A-Z. One element might match three rules in the sheet, thus forming the input word "C-A-T" or another might form the input word "D-O-G."

There are several important observations one can make once you formulate the problem this way. The first is that words that are prefixes of a larger word will end up applying the same set of rules. All additional letters in the word do is result in the application of more declarations. Thus the rule tree is effectively a lexicographic tree of nodes, with each node in a tree being created lazily as you walk the tree spelling out a given word.

This system allows you to cache style information at each node in the tree. This means that once you've looked up the word "C-A-T-E-R-W-A-U-L", and cached information at all of the nodes, then looking up the word "C-A-T" becomes more efficient.

In order to make the caching efficient, properties can be grouped into categories, with the primary criterion for categorization being whether the property inherits by default. It's also important to group properties together that would logically be specified together, so that when a fault occurs and you have to make a copy of a given struct, you do so knowing that the other values in the struct were probably going to be different anyway.

Once you have the properties grouped into categories like the border struct or the background struct, then you can either store these structs in the rule tree or as part of a style tree that more or less matches the structure of the document. Inheritance has to apply down the style tree and tends to force a fault, whereas non-inherited properties can usually be cached in the rule tree for easy access.

WebCore doesn't contain a rule tree, but it is smart enough to refcount the structs and share them as long as no properties have been set in the struct. In practice this works pretty well but is not as ideal as the rule tree solution.


Implementing XHTML 2.0


Implementing XHTML 2.0 07/27/2004 08:02 PM
Well, I slept off most of my desire to blog about XHTML 2.0, but here's a post anyway. The thing is, I don't think implementing elements using behaviors is really a good idea, although I feel bad saying it while the W3C is linking to my test implementation. ?

Implementing filesystems in Python


Implementing filesystems in Python 12/10/2003 06:35 PM

LUFS-Python provides a relatively simple API for implementing new Linux filesystems in pure Python. You install the package, write a class implementing methods for handling filesystem operations such as creating a directory, opening/reading/writing/closing a file, creating symlinks etc and finally mount your new filesystem with some special arguments to the mount command.

At first glance, this is a bit of a gimmick - why would you want to write your own filesystem in the first place? We've been talking about this at work and came up with a few ideas. How about a filesystem where HTML files saved in a certain directory were instantly run through HTMLTidy and converted in to valid XHTML ? Or a custom network filesystem that saves files on a remote server using GnuPG to encrypt them before transfer? How about a read-only filesystem that lets you browse the contents of a MySQL database? Just imagine being able to use tools such as grep and find to search your database. A module that maps someone elses public web server to your own filesystem, making mirroring as easy as running a recursive cp command. A filesystem that updates a swish-e full-text index every time a file is saved to it - years before Microsoft release Longhorn. The possibilities are endless.

Here's a really fun idea: a filesystem that implements a dynamic website. Instead of using tools like mod_python to dynamically create pages, implement a filesystem that dynamically creates HTML files as they are requested and set up a stock Apache install with the dynamic filesystem as the document root. Then point ProFTPD at it so you can log in via FTP and mess with your content dynamically. We're thinking about bulding an FTP interface to our new database driven CMS, but we could just build a filesystem interface and point our FTP server straight at it.

I'm sure there are performance and stability issues that make most of the above more trouble than it's worth, but I think you'll agree it's a pretty exciting technology.


Hands On: Implementing OS X 10.3
(Panther) Server


Hands On: Implementing OS X 10.3
(Panther) Server
02/10/2004 02:43 AM
I can tell you now that everything Apple promised is indeed in there -- and it works! By Yuval Kossovsky (Computerworld via MyAppleMenu)

Being User-Centered When Implementing a
UCD Process


Being User-Centered When Implementing a
UCD Process
09/09/2002 06:29 AM

Implementing Linux emulation on NetBSD


Implementing Linux emulation on NetBSD 05/13/2004 03:28 AM
NetBSD's Linux emulation doesn't run a Linux kernel on a virtual machine; it runs Linux binaries on a NetBSD kernel. Linux emulation let you run plenty of useful programs that won't run natively under NetBSD, such as Sun's 1.4 Java Runtime Environment and JDK.

Implementing client-side code for SSL in
JDK 1.3


Implementing client-side code for SSL in
JDK 1.3
01/23/2003 02:47 AM
CNET Jan 23 2003 1:24AM ET

Poll Position: Implementing Identity


Poll Position: Implementing Identity 04/04/2005 06:03 AM
Q: How do you best build a brand?

Implementing a relational database using
MySQL


Implementing a relational database using
MySQL
04/06/2005 12:17 PM
When properly implemented, a relational database can greatly enhance the availability of data and information for an enterprise's decision makers. However, deploying a relational database on almost any scale requires a thorough understanding of the fundamental concepts and rules that govern their behavior.

Implementing XPath for Wireless Devices


Implementing XPath for Wireless Devices 06/06/2002 05:37 PM
In the first of a two-part series, we explore the implementation of XPath on wireless devices using the WAP family of standards.

Implementing XPath for wireless devices
(XML.org)


Implementing XPath for wireless devices
(XML.org)
06/07/2002 08:34 AM

Gov't could raise P20B by implementing
IP law


Gov't could raise P20B by implementing
IP law
09/14/2004 04:18 PM
Sun Star Network Sep 14 2004 7:26PM GMT

"Code snippets for implementing tags
with SQL"


"Code snippets for implementing tags
with SQL"
04/11/2005 11:43 PM

ICANN To Begin Implementing IPv6


ICANN To Begin Implementing IPv6 07/22/2004 02:58 PM
WebProNews Jul 22 2004 6:18PM GMT

Implementing successful shared services
in government


Implementing successful shared services
in government
02/17/2004 10:26 PM
Computer Weekly Feb 18 2004 2:09AM GMT

Software Developer resist implementing
Atom


Software Developer resist implementing
Atom
05/24/2004 07:44 AM

Not all developers who are designing RSS applications are adding Atom support and I can't say that I blame them but it is interesting to see their comments. [miseldine.com]


Scilly Isles looks at implementing
e-government across 5 islands


Scilly Isles looks at implementing
e-government across 5 islands
04/16/2005 02:13 AM
PublicTechnology.net Apr 16 2005 4:16AM GMT

Implementing XPath for Wireless Devices,
Part II


Implementing XPath for Wireless Devices,
Part II
07/17/2002 07:16 PM
In the second of a two-part series, we explore the implementation of XPath on wireless devices using the WAP family of standards.

C++: Implementing Design by Contract to
reduce bugs


C++: Implementing Design by Contract to
reduce bugs
08/16/2004 03:06 AM
CNET Aug 16 2004 7:13AM GMT

Implementing XPath for wireless devices,
part II (XML.com)


Implementing XPath for wireless devices,
part II (XML.com)
07/18/2002 07:34 PM

Guidelines for Implementing and
Maintaining Virtual Reference Services


Guidelines for Implementing and
Maintaining Virtual Reference Services
07/29/2004 06:48 AM
Guidelines for Implementing and Maintaining Virtual Reference Services
http://www.ala.org/ala/rusa/rusaprotools/referenceguide /virtrefguidelines.htm

The purpose of these guidelines is to assist libraries and consortia with implementing and maintaining virtual reference services. The guidelines are meant to provide direction, without being over- prescriptive. Variance among institutions will result in differences in the adherence to these guidelines, but the committee hopes to have cast the model broadly enough to provide a framework for virtual reference which can be widely adopted and which will endure through many changes in the ways in which libraries provide virtual reference services. Prepared by the MARS Digital Reference Guidelines Ad Hoc Committee, Reference and User Services Association, 2004. Approved by the RUSA Board of Directors June 2004.

Features: Implementing REST Web
Services: Best Practices and Guidelines


Features: Implementing REST Web
Services: Best Practices and Guidelines
08/11/2004 07:03 PM
Hao He offers guidelines and best practices for implementing REST web services.

Sakhr implementing solutions with
e-government project in Qatar


Sakhr implementing solutions with
e-government project in Qatar
03/27/2005 07:47 AM
AME Info Mar 27 2005 9:54AM GMT

Enterprise Java Beans - Part 2,
Implementing Your First EJBs


Enterprise Java Beans - Part 2,
Implementing Your First EJBs
11/14/2003 03:33 AM
WebmasterBase Nov 14 2003 2:36AM ET

TechRepublic: Building and Implementing
a Successful Information Security Policy


TechRepublic: Building and Implementing
a Successful Information Security Policy
12/09/2003 01:27 PM
ZDNet Dec 9 2003 12:53PM ET

You Control: iTunes puts control in OS X
menu bar (MacCentral)


You Control: iTunes puts control in OS X
menu bar (MacCentral)
08/31/2004 07:26 PM
MacCentral - You Software Inc. announced on Tuesday the availability of You Control: iTunes, a free download that places iTunes controls in the Mac OS X menu bar. Without leaving the current application, you can pause, play, rewind or skip songs, as well as control iTunes' volume and even browse your entire music library by album, artist or genre. Each time a new song plays, You Control: iTunes also pops up a window that displays the artist and song name and the album artwork, if it's in the library. System requirements call for Mac OS X v10.2.6 and 10MB free hard drive space. ...

Photonics Control Announces Optical
Control Breakthrough


Photonics Control Announces Optical
Control Breakthrough
06/26/2004 02:40 AM
Intelligent Photonics Control Corp. (Photonics Control), the world leader in providing embedded control solutions for optical devices, announced today that it has reached a significant milestone. The Company has integrated its solutions into 50 different customer platforms including Optical Amplifiers, VMUXes, OPMs, DGEs, and Tunable Lasers. [PRWEB Jun 26, 2004]

You Control: iTunes puts control in OS X
menu bar


You Control: iTunes puts control in OS X
menu bar
08/31/2004 01:50 PM
You Software Inc. announced on Tuesday the availability of You Control: iTunes, a free download that places iTunes controls in the Mac OS X menu bar. Without leaving the current application, you can pause, play, rewind or skip songs, as well as control iTunes' volume and even browse your entire music library by album, artist or genre. Each time a new song plays, You Control: iTunes also pops up a window that displays the artist and song name and the album artwork, if it's in the library. System requirements call for Mac OS X v10.2.6 and 10MB free hard drive space.

TrendWatch Graphic Arts Report indicates
that most have litte interest in
implementing Computer Integrated
Manufacturing (CIM) into their business
right now.


TrendWatch Graphic Arts Report indicates
that most have litte interest in
implementing Computer Integrated
Manufacturing (CIM) into their business
right now.
07/20/2004 02:44 AM
With all the attention granted JDF and CIM in the last 12 months, one would expect to see a spike in implementation. Unfortunately, the truth is JDF, and subsequently CIM, is just not happening — at least, not right now. The evidence says that except for Periodical Printers, graphic arts professionals are not focused upon making CIM work for them. By most accounts, the commercial printing industry is in an infrastructure-building phase. The good news is that once that infrastructure is able to support CIM, the industry will then gradually begin adopting it. [PRWEB Jul 20, 2004]

Research And Markets: On Average, Many
Midsize Companies Or Divisions Of Large
Organizations Spend $315,000 To $880,000
On Selecting, Implementing And
Maintaining ECM Solutions.


Research And Markets: On Average, Many
Midsize Companies Or Divisions Of Large
Organizations Spend $315,000 To $880,000
On Selecting, Implementing And
Maintaining ECM Solutions.
12/19/2004 03:46 PM
[PRWEB Dec 17, 2004]

A flood of red ink


A flood of red ink 11/07/2003 02:01 AM
A flood of red ink This time the turnaround will be much tougher. There will be no “peace dividend” from the end of the cold war (indeed, the pressure on military spending may continue to increase). America is unlikely to see another stockmarket bubble, with its surge in tax revenues. As baby-boomers retire, the pressure from entitlement spending will be more acute. Set against this background, the path back to a sustainable fiscal policy will be extremely painful, even without any dramatic fiscal crisis. Long after Dubya is back on his ranch, Americans will be trying to recover from the mess he created.

Don Flood: An Eye For Fashion


Don Flood: An Eye For Fashion 05/21/2004 09:53 PM
"I find a lot of satisfaction at the end of the day seeing what we did. There's no wait-and-see anymore. I love the confidence of knowing I've got the shot." By Barbara Gibson, Apple (via MyAppleMenu)

DNS Flood Detector 1.10


DNS Flood Detector 1.10 10/30/2003 11:32 PM
Detect abusive nameserver activity.

Bookmarklet flood


Bookmarklet flood 03/20/2003 11:58 AM
One more bookmarklet for today. It makes a simple DOM inspector of active window and it's document. Tested in IE6/XP,...

Clean-up after flood devastation


Clean-up after flood devastation 08/17/2004 12:16 AM
A massive clean-up operation is underway in north Cornwall after devastating flash floods hit the area.

Help pledge for flood buildings


Help pledge for flood buildings 08/18/2004 08:19 AM
The government promises to do all in its power to help businesses affected by flash floods in Londonderry.

Computers try to keep up with
information flood


Computers try to keep up with
information flood
11/19/2003 11:40 AM
Yahoo! Nov 19 2003 10:24AM ET

HALO PC - flood, howto


HALO PC - flood, howto 02/10/2004 02:41 PM
AMDMB Feb 10 2004 6:29PM GMT
Grok Description matches for Implementing Flood Control
GrokA matches for Implementing Flood Control

Implementing Flood Control

The following phrases have been identified by the grok system as matching this entry:

















Also check out:


Grok

Ipod Porn on the
Rise

Brief Abstract of
Wikipedia's
Mesothelioma Cancer
page

Get first aid
instructions in your
cell phone

IE is crap
JSPWiki gains
podcasting support

This Week in Perl 6,
November 9 - 15 2004

Cross-Language
Remoting with
mod_perlservice

Perl Debugger Quick
Reference

Building a 3D Engine
in Perl

This Fortnight in
Perl 6, November
16-30 2004

This Fortnight in
Perl 6, December 1 -
6 2004

The Evolution of
ePayment Services at
UB

Perl Code Kata:
Testing Imports

Yes, Options Really
Are an Expense

Be a "Penny Stock"
Millionaire!

Apple's Melodious
Achievement

Pity Circuit City
Sepracor's Dream
Drug?

A Hot Stock at 7
Times Earnings

Tax Deductions for
Home PCs

The Chocolate-Coffee
Conundrum

Getting Comfy With
Herman Miller

YUKOS' Hollow
Victory

W3C Celebrates Its
Tenth Anniversary

W3C Workshop on
Semantic Web for
Life Sciences:
Summary

Working Draft:
Extensible
Stylesheet Language
(XSL) Version 1.1

Last Call: Web
Services
Choreography
Description Language
1.0

W3C Launches Patents
and Standards
Interest Group

'Architecture of the
World Wide Web,
Volume One' is a W3C
Recommendation

PHP 4.3.9 Released!
PHP 5.0.2 released!
PHP Freaks Forums
Upgrades / Blogs!

iCal 1.5.5 Now
Available

OS X 10.3.7 This
Week?

80 GB iPod?
Apple Disabling
RealNetworks Harmony
Technology

5 GB iPod Mini In
Production?

Mac OS X 10.3.7
Update

iTMS Downloads Top
200 Million

iPhone Rumor
Rebound?

Apple Sues Over Leak
Build Your Own
Blogging
Application, Part 2

Doug's
AppleScripts for
iTunes Podcast

MarsEdit 1.0fc3:
final candidate
release

See comic
subscriptions in
NetNewsWire 2.0

VoodooPad 2.0
released

Technical Note
TN2124: Mac OS X
Debugging Magic

Using drupal's
blogapi with
MarsEdit

ucomics Atom feeds
for NetNewsWire

The Omni Group is
hiring Cocoa
programmers

Developing Dashboard
Widgets

VoodooPad + GTD +
Applescript ->
NetNewsWire

Finance Site List
The Internet Site
for Economists

The International
Economics Network

what is grok?