Changeset 82

Show
Ignore:
Timestamp:
08/21/07 21:27:13 (1 year ago)
Author:
edsuom
Message:

Fiddling around with process-based wsgi

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • projects/AsynCluster/trunk/doc/gevolver/knapsack.py

    r14 r82  
    1 # pbGE: 
    2 # Grammatical Evolution (GE) run by a "master" server and a bunch of "worker" 
    3 # clients via Twisted's Perspective Broker (PB). Computations are dispatched 
    4 # and carried out asynchronously using Twisted's deferred processing 
    5 # capabilities. 
     1# AsynCluster: gevolver 
     2# Python-based Grammatical Evolution with attribute grammars 
    63# 
    7 # Copyright (C) 2006 by Edwin A. Suominen, http://www.eepatents.com 
     4# Copyright (C) 2006-2007 by Edwin A. Suominen, http://www.eepatents.com 
    85# 
    9 # This code is not currently released for any public use. 
     6# This program is free software; you can redistribute it and/or modify it under 
     7# the terms of the GNU General Public License as published by the Free Software 
     8# Foundation; either version 2 of the License, or (at your option) any later 
     9# version. 
     10#  
     11# This program is distributed in the hope that it will be useful, but WITHOUT 
     12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
     13# FOR A PARTICULAR PURPOSE.  See the file COPYING for more details. 
     14#  
     15# You should have received a copy of the GNU General Public License along with 
     16# this program; if not, write to the Free Software Foundation, Inc., 51 
     17# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 
    1018 
    1119""" 
     
    1725 
    1826# Imports 
    19 from pbge.grammar import TBase, NBase 
     27from gevolver.grammar import TBase, NBase 
    2028 
    2129 
     
    7482class T(TBase): 
    7583    """ 
    76     T = {  } 
     84    BNF Grammar Terminal Set 
    7785    """ 
    7886    def handgun(self, a): 
     
    8189        it adds value depending on the danger present. 
    8290        """ 
    83         def _handgun(s): 
     91        def valuer(s): 
    8492            s.bulk += 1 
    8593            if s.setting.handguns: 
     
    8896                s.value -= 10 
    8997 
    90         return Terminal(_handgun, 'handgun') 
     98        return Terminal(valuer, 'handgun') 
    9199 
    92100    def propane(self, a): 
     
    101109        only if the setting isn't dry. 
    102110        """ 
    103         def _pan(s): 
     111        def valuer(s): 
    104112            s.bulk += 2 
    105113            if not s.setting.dry: 
    106114                s.value += 1 
    107115 
    108         return Terminal(_pan, 'pan') 
    109  
    110     # TODO from here on 
     116        return Terminal(valuer, 'pan') 
    111117 
    112118    def stove(self, a): 
     
    114120        A stove is useful if propane and a pan have been brought. 
    115121        """ 
    116         def _stove(s): 
     122        def valuer(s): 
    117123            s.bulk += 2 
    118124            if 'propane' in a.items and 'pan' in a.items: 
    119125                s.value += 2 
    120126 
    121         return Terminal(_stove, 'stove') 
     127        return Terminal(valuer, 'stove') 
    122128 
    123129    def heater(self, a): 
     
    125131        A heater is somewhat useful if it's cold and propane has been brought. 
    126132        """ 
    127         def _heater(s): 
     133        def valuer(s): 
    128134            s.bulk += 1 
    129135            if s.setting.cold and 'heater' in a.items: 
    130136                s.value += 1 
    131137 
    132         return Terminal(_heater, 'heater') 
     138        return Terminal(valuer, 'heater') 
    133139 
    134140    def literOfWater(self, a): 
     
    137143        """ 
    138144        s.bulk += 1 
    139         addedValue = 1 + s.setting.dry + s.setting.dry 
     145        addedValue = 1 + (s.setting.dry and s.setting.hot) 
    140146        s.value += addedValue 
    141147 
     
    143149class P(PBase): 
    144150    """ 
     151    BNF Grammar Rule Set 
    145152    """ 
    146     def next(self, a): 
    147         return ( 
    148             self.done, 
    149             self.singleItem, 
    150             self.addItem(self.t.literOfWater) 
    151             ) 
    152  
    153153    def singleItem(self, a): 
    154154        possibilites = [self.next] 
  • projects/AsynCluster/trunk/setup.py

    r16 r82  
    3232 
    3333### Define requirements 
    34 required = ['sAsync>=0.4', 'Twisted-Goodies>=0.4'
     34required = ['sAsync>=0.4', 'Twisted-Goodies>=0.4', 'AsynQueue>=0.2'
    3535 
    3636 
    3737### Define setup options 
    38 kw = {'version':'0.1', 
     38kw = {'version':'0.2', 
    3939      'license':'GPL', 
    4040      'platforms':'OS Independent', 
     
    5757    'Twisted', 'asynchronous', 
    5858    'taskqueue', 'queue', 'priority', 'tasks', 'jobs', 
    59     'cluster', 'clustering', 'parallel', 'grid'] 
     59    'cluster', 'clustering', 'parallel', 'grid', 
     60    'genetic', 'evolution', 'evolutionary computing', 'GE', 'GA', 'GP'] 
    6061 
    6162kw['classifiers'] = [ 
     
    7879""".split("\n")) 
    7980 
    80 kw['long_description'] = """ 
     81kw['long_description'] = " ".join(""" 
    8182Asynchronous operation of a computing cluster with a Node Display Manager (NDM) 
    8283that allows regular workstation usage of cluster nodes with computing jobs 
    83 running behind the scenes. Includes evolutionary computing tools that make 
    84 effective use of the asynchronous node processing capabilities that are 
    85 provided. 
    86 """ 
     84running behind the scenes. Includes evolutionary computing tools (under 
     85construction) that make effective use of the asynchronous node processing 
     86capabilities that are provided. 
     87""".split("\n")) 
    8788 
    8889### Finally, run the setup 
  • projects/Twisted-Goodies/branches/simpleserver-process-wsgi/twisted_goodies/simpleserver/http/wsgi.py

    r80 r82  
    2424""" 
    2525 
    26 import os, threading 
     26import os 
    2727import Queue 
    2828from zope.interface import implements 
     
    3434from twisted.web2.twcgi import createCGIEnvironment 
    3535 
    36 from asynqueue import ThreadQueue 
    37  
    38  
    39 VERBOSE = False 
     36from asynqueue.processworker import ChildManager 
     37 
     38 
    4039MAX_PENDING = 10 
    4140IP_BAN_SECS = 30.0 
     
    4847class WSGIMeta(type): 
    4948    """ 
     49    This metaclass instantiates a child process manager and other queue-related 
     50    attributes that are common to all invoking classes and subclasses. 
    5051    """ 
    5152    def __new__(mcls, name, bases, dictionary): 
    5253        if not hasattr(mcls, 'globalStuff'): 
    5354            gs = mcls.globalStuff = {} 
    54             # Just use one worker in one thread for now             
    55             gs['queue'] = ThreadQueue(1
     55            # Just use one worker in one thread for now 
     56            gs['mgr'] = ChildManager(
    5657            gs['pending'] = 0 
    5758            gs['handlers'] = [] 
     
    6768    A web2 Resource which wraps the given WSGI application callable. 
    6869 
    69     The WSGI application will be called in a separate thread (using 
    70     the reactor threadpool) whenever a request for this resource or 
    71     any lower part of the url hierarchy is received. 
     70    The WSGI application will be called in a separate process whenever a 
     71    request for this resource or any lower part of the url hierarchy is 
     72    received. 
    7273 
    7374    This isn't a subclass of resource.Resource, because it shouldn't do any 
     
    8182    def __init__(self, application): 
    8283        self.application = application 
    83         self.queue.subscribe(self) 
     84        self.mgr.queue.subscribe(self) 
    8485 
    8586    def renderHTTP(self, req): 
    8687        def done(result, IP): 
    8788            if not result or isinstance(result, failure.Failure): 
    88                 if VERBOSE: 
    89                     print "Failed request from %s" % IP 
    9089                self.banIP(IP) 
    9190            if handler in self.handlers: 
     
    144143        old = cls.pending 
    145144        cls.pending = new 
    146         if VERBOSE and new != old: 
    147             print "Pending: %02d -> %02d" % (old, new) 
    148145        if new > MAX_PENDING and cls.handlers: 
    149146            if new > min([old, 2*MAX_PENDING]): 
    150147                oldestHandler = cls.handlers.pop(0) 
    151                 if VERBOSE: 
    152                     print "Stopping handler:", oldestHandler 
    153148                oldestHandler.stopProducing() 
    154149 
     
    269264        Call this if this input stream is backing things up too much. 
    270265        """ 
    271         if VERBOSE: 
    272             print "Closing laggard input stream..." 
    273266        self.stream.finish() 
    274267 
     
    306299class WSGIHandler(object): 
    307300    """ 
     301    Each HTTP request is handled by an instance of me, constructed in the child 
     302    process. 
    308303    """ 
    309304    implements(interfaces.IPushProducer)