def __init__(self, prefix): self.prefix = prefix def load_bytecode(self, bucket): found, _bytes = ProcessScopedJinjaCache.instance().cache.get( self.prefix + bucket.key) if found and _bytes is not None: bucket.bytecode_from_string(_bytes) def dump_bytecode(self, bucket): _bytes = bucket.bytecode_to_string() ProcessScopedJinjaCache.instance().cache.put(self.prefix + bucket.key, _bytes) JINJA_CACHE_LEN = PerfCounter('gcb-models-JinjaBytecodeCache-len', 'A total number of items in Jinja cache.') JINJA_CACHE_SIZE_BYTES = PerfCounter( 'gcb-models-JinjaBytecodeCache-bytes', 'A total size of items in Jinja cache in bytes.') JINJA_CACHE_LEN.poll_value = ProcessScopedJinjaCache.get_cache_len JINJA_CACHE_SIZE_BYTES.poll_value = ProcessScopedJinjaCache.get_cache_size def create_jinja_environment(loader, locale=None, autoescape=True): """Create proper jinja environment.""" cache = None if CAN_USE_JINJA2_TEMPLATE_CACHE.value: prefix = 'jinja2:bytecode:%s:/' % models.MemcacheManager.get_namespace( )
from modules.review import domain from tools import verify from utils import BaseHandler from utils import BaseRESTHandler from utils import CAN_PERSIST_ACTIVITY_EVENTS from utils import CAN_PERSIST_PAGE_EVENTS from utils import CAN_PERSIST_TAG_EVENTS from utils import HUMAN_READABLE_DATETIME_FORMAT from utils import TRANSIENT_STUDENT from utils import XsrfTokenManager from google.appengine.ext import db COURSE_EVENTS_RECEIVED = PerfCounter( 'gcb-course-events-received', 'A number of activity/assessment events received by the server.') COURSE_EVENTS_RECORDED = PerfCounter( 'gcb-course-events-recorded', 'A number of activity/assessment events recorded in a datastore.') UNIT_PAGE_TYPE = 'unit' ACTIVITY_PAGE_TYPE = 'activity' def get_first_lesson(handler, unit_id): """Returns the first lesson in the unit.""" #lesson_in_progress = handler.get_course().get_lesson_in_progress(unit_id) #if lesson_in_progress: return lesson_in_progress
import urlparse from xml.etree import cElementTree import zipfile from common import schema_fields from common import tags from controllers import sites from controllers import utils from models.config import ConfigProperty from models.counters import PerfCounter from models import custom_modules from models import models from models import transforms ATTEMPT_COUNT = PerfCounter( 'gcb-khanex-attempt-count', 'A number of attempts made by all users on all exercises.') WHITELISTED_EXERCISES = ConfigProperty( '_khanex_whitelisted', str, ('A white-listed exercises that can be show to students. If this list ' 'is empty, all exercises are available.'), default_value='', multiline=True) ZIP_FILE = os.path.join(os.path.dirname(__file__), 'khan-exercises.zip') EXERCISE_BASE = 'khan-exercises/khan-exercises/exercises/' EXERCISE_HTML_PAGE_RAW = ("""<!DOCTYPE html> <html">
self.prefix = prefix def load_bytecode(self, bucket): found, _bytes = ProcessScopedJinjaCache.instance().cache.get( self.prefix + bucket.key) if found and _bytes is not None: bucket.bytecode_from_string(_bytes) def dump_bytecode(self, bucket): _bytes = bucket.bytecode_to_string() ProcessScopedJinjaCache.instance().cache.put( self.prefix + bucket.key, _bytes) JINJA_CACHE_LEN = PerfCounter( 'gcb-models-JinjaBytecodeCache-len', 'A total number of items in Jinja cache.') JINJA_CACHE_SIZE_BYTES = PerfCounter( 'gcb-models-JinjaBytecodeCache-bytes', 'A total size of items in Jinja cache in bytes.') JINJA_CACHE_LEN.poll_value = ProcessScopedJinjaCache.get_cache_len JINJA_CACHE_SIZE_BYTES.poll_value = ProcessScopedJinjaCache.get_cache_size def create_jinja_environment(loader, locale=None, autoescape=True): """Create proper jinja environment.""" cache = None if CAN_USE_JINJA2_TEMPLATE_CACHE.value: prefix = 'jinja2:bytecode:%s:/' % models.MemcacheManager.get_namespace()
DEFAULT_CACHE_CONTROL_MAX_AGE = 600 DEFAULT_CACHE_CONTROL_PUBLIC = 'public' # default HTTP headers for dynamic responses DEFAULT_EXPIRY_DATE = 'Mon, 01 Jan 1990 00:00:00 GMT' DEFAULT_PRAGMA = 'no-cache' # enable debug output DEBUG_INFO = False # thread local storage for current request PATH_INFO PATH_INFO_THREAD_LOCAL = threading.local() # performance counters STATIC_HANDLER_COUNT = PerfCounter( 'gcb-sites-handler-static', 'A number of times request was served via static handler.') DYNAMIC_HANDLER_COUNT = PerfCounter( 'gcb-sites-handler-dynamic', 'A number of times request was served via dynamic handler.') ZIP_HANDLER_COUNT = PerfCounter( 'gcb-sites-handler-zip', 'A number of times request was served via zip handler.') NO_HANDLER_COUNT = PerfCounter( 'gcb-sites-handler-none', 'A number of times request was not matched to any handler.') HTTP_BYTES_IN = PerfCounter( 'gcb-sites-bytes-in', 'A number of bytes received from clients by the handler.') HTTP_BYTES_OUT = PerfCounter(
def init_counters(cls): name = cls.__name__ cls.CACHE_RESYNC = PerfCounter( 'gcb-models-%s-cache-resync' % name, 'A number of times an vfs cache was updated.') cls.CACHE_PUT = PerfCounter( 'gcb-models-%s-cache-put' % name, 'A number of times an object was put into cache.') cls.CACHE_GET = PerfCounter( 'gcb-models-%s-cache-get' % name, 'A number of times an object was pulled from cache.') cls.CACHE_DELETE = PerfCounter( 'gcb-models-%s-cache-delete' % name, 'A number of times an object was deleted from cache.') cls.CACHE_HIT = PerfCounter( 'gcb-models-%s-cache-hit' % name, 'A number of times an object was found cache.') cls.CACHE_HIT_NONE = PerfCounter( 'gcb-models-%s-cache-hit-none' % name, 'A number of times an object was found cache, but it was None.') cls.CACHE_MISS = PerfCounter( 'gcb-models-%s-cache-miss' % name, 'A number of times an object was not found in the cache.') cls.CACHE_NOT_FOUND = PerfCounter( 'gcb-models-%s-cache-not-found' % name, 'A number of times an object was requested, but was not found in ' 'the cache or underlying provider.') cls.CACHE_UPDATE_COUNT = PerfCounter( 'gcb-models-%s-cache-update-count' % name, 'A number of update objects received.') cls.CACHE_EVICT = PerfCounter( 'gcb-models-%s-cache-evict' % name, 'A number of times an object was evicted from cache because it was ' 'changed.') cls.CACHE_EXPIRE = PerfCounter( 'gcb-models-%s-cache-expire' % name, 'A number of times an object has expired from cache because it was ' 'too old.')