X-Git-Url: https://code.grnet.gr/git/pithos/blobdiff_plain/7efc9f8670f263196536ed6be5db2caa12bb36f1..45f442f7c3813e8525b33bbbcc0ead062468fd28:/snf-pithos-app/pithos/api/util.py diff --git a/snf-pithos-app/pithos/api/util.py b/snf-pithos-app/pithos/api/util.py index 0055d9a..f8233f9 100644 --- a/snf-pithos-app/pithos/api/util.py +++ b/snf-pithos-app/pithos/api/util.py @@ -326,8 +326,6 @@ def copy_or_move_object(request, src_account, src_container, src_name, dest_acco if 'ignore_content_type' in request.GET and 'CONTENT_TYPE' in request.META: del(request.META['CONTENT_TYPE']) content_type, meta, permissions, public = get_object_headers(request) - if delimiter: - public = False # ignore public in that case src_version = request.META.get('HTTP_X_SOURCE_VERSION') try: if move: @@ -790,7 +788,8 @@ def simple_list_response(request, l): if request.serialization == 'json': return json.dumps(l) -def get_backend(): + +def _get_backend(): backend = connect_backend(db_module=BACKEND_DB_MODULE, db_connection=BACKEND_DB_CONNECTION, block_module=BACKEND_BLOCK_MODULE, @@ -802,6 +801,50 @@ def get_backend(): backend.default_policy['versioning'] = BACKEND_VERSIONING return backend + +def _pooled_backend_close(backend): + backend._pool.pool_put(backend) + + +from synnefo.lib.pool import ObjectPool +from new import instancemethod + +USAGE_LIMIT = 500 +POOL_SIZE = 5 + +class PithosBackendPool(ObjectPool): + def _pool_create(self): + backend = _get_backend() + backend._real_close = backend.close + backend.close = instancemethod(_pooled_backend_close, backend, + type(backend)) + backend._pool = self + backend._use_count = USAGE_LIMIT + return backend + + def _pool_verify(self, backend): + return 1 + + def _pool_cleanup(self, backend): + c = backend._use_count - 1 + if c < 0: + backend._real_close() + return True + + backend._use_count = c + if backend.trans is not None: + backend.wrapper.rollback() + if backend.messages: + backend.messages = [] + return False + +_pithos_backend_pool = PithosBackendPool(size=POOL_SIZE) + + +def get_backend(): + return _pithos_backend_pool.pool_get() + + def update_request_headers(request): # Handle URL-encoded keys and values. meta = dict([(k, v) for k, v in request.META.iteritems() if k.startswith('HTTP_')]) @@ -872,6 +915,7 @@ def request_serialization(request, format_allowed=False): return 'text' + def api_method(http_method=None, format_allowed=False, user_required=True): """Decorator function for views that implement an API method."""