Skip to content

Commit 00d1dbc

Browse files
committed
Remove image server per-image concurrency locks
1 parent c40b30b commit 00d1dbc

File tree

3 files changed

+2
-103
lines changed

3 files changed

+2
-103
lines changed

scripts/vm/hypervisor/kvm/imageserver/concurrency.py

Lines changed: 0 additions & 68 deletions
This file was deleted.

scripts/vm/hypervisor/kvm/imageserver/handler.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from urllib.parse import parse_qs
2525

2626
from .backends import NbdBackend, create_backend
27-
from .concurrency import ConcurrencyManager
2827
from .config import TransferRegistry
2928
from .constants import CHUNK_SIZE, MAX_PARALLEL_READS, MAX_PARALLEL_WRITES, MAX_PATCH_JSON_SIZE
3029
from .util import is_fallback_dirty_response, json_bytes, now_s
@@ -38,14 +37,13 @@ class Handler(BaseHTTPRequestHandler):
3837
All backend I/O is delegated to ImageBackend implementations via the
3938
create_backend() factory.
4039
41-
Class-level attributes _concurrency and _registry are injected
40+
Class-level attribute _registry is injected
4241
by the server at startup (see server.py / make_handler()).
4342
"""
4443

4544
server_version = "cloudstack-image-server/1.0"
4645
server_protocol = "HTTP/1.1"
4746

48-
_concurrency: ConcurrencyManager
4947
_registry: TransferRegistry
5048

5149
_CONTENT_RANGE_RE = re.compile(r"^bytes\s+(\d+)-(\d+)/(?:\*|\d+)$")
@@ -493,10 +491,6 @@ def do_PATCH(self) -> None:
493491
def _handle_get_image(
494492
self, image_id: str, cfg: Dict[str, Any], range_header: Optional[str]
495493
) -> None:
496-
if not self._concurrency.acquire_read(image_id):
497-
self._send_error_json(HTTPStatus.SERVICE_UNAVAILABLE, "too many parallel reads")
498-
return
499-
500494
start = now_s()
501495
bytes_sent = 0
502496
try:
@@ -564,7 +558,6 @@ def _handle_get_image(
564558
except Exception:
565559
pass
566560
finally:
567-
self._concurrency.release_read(image_id)
568561
dur = now_s() - start
569562
logging.info(
570563
"GET end image_id=%s bytes=%d duration_s=%.3f", image_id, bytes_sent, dur
@@ -573,10 +566,6 @@ def _handle_get_image(
573566
def _handle_put_image(
574567
self, image_id: str, cfg: Dict[str, Any], content_length: int, flush: bool
575568
) -> None:
576-
if not self._concurrency.acquire_write(image_id):
577-
self._send_error_json(HTTPStatus.SERVICE_UNAVAILABLE, "too many parallel writes")
578-
return
579-
580569
start = now_s()
581570
bytes_written = 0
582571
try:
@@ -596,7 +585,6 @@ def _handle_put_image(
596585
logging.error("PUT error image_id=%s err=%r", image_id, e)
597586
self._send_error_json(HTTPStatus.INTERNAL_SERVER_ERROR, "backend error")
598587
finally:
599-
self._concurrency.release_write(image_id)
600588
dur = now_s() - start
601589
logging.info(
602590
"PUT end image_id=%s bytes=%d duration_s=%.3f", image_id, bytes_written, dur
@@ -610,10 +598,6 @@ def _handle_put_range(
610598
content_length: int,
611599
flush: bool,
612600
) -> None:
613-
if not self._concurrency.acquire_write(image_id):
614-
self._send_error_json(HTTPStatus.SERVICE_UNAVAILABLE, "too many parallel writes")
615-
return
616-
617601
start = now_s()
618602
bytes_written = 0
619603
try:
@@ -650,7 +634,6 @@ def _handle_put_range(
650634
logging.error("PUT range error image_id=%s err=%r", image_id, e)
651635
self._send_error_json(HTTPStatus.INTERNAL_SERVER_ERROR, "backend error")
652636
finally:
653-
self._concurrency.release_write(image_id)
654637
dur = now_s() - start
655638
logging.info(
656639
"PUT range end image_id=%s bytes=%d duration_s=%.3f flush=%s",
@@ -725,10 +708,6 @@ def _handle_patch_zero(
725708
size: int,
726709
flush: bool,
727710
) -> None:
728-
if not self._concurrency.acquire_write(image_id):
729-
self._send_error_json(HTTPStatus.SERVICE_UNAVAILABLE, "too many parallel writes")
730-
return
731-
732711
start = now_s()
733712
try:
734713
logging.info(
@@ -749,7 +728,6 @@ def _handle_patch_zero(
749728
logging.error("PATCH zero error image_id=%s err=%r", image_id, e)
750729
self._send_error_json(HTTPStatus.INTERNAL_SERVER_ERROR, "backend error")
751730
finally:
752-
self._concurrency.release_write(image_id)
753731
dur = now_s() - start
754732
logging.info("PATCH zero end image_id=%s duration_s=%.3f", image_id, dur)
755733

@@ -760,10 +738,6 @@ def _handle_patch_range(
760738
range_header: str,
761739
content_length: int,
762740
) -> None:
763-
if not self._concurrency.acquire_write(image_id):
764-
self._send_error_json(HTTPStatus.SERVICE_UNAVAILABLE, "too many parallel writes")
765-
return
766-
767741
start = now_s()
768742
bytes_written = 0
769743
try:
@@ -807,7 +781,6 @@ def _handle_patch_range(
807781
logging.error("PATCH range error image_id=%s err=%r", image_id, e)
808782
self._send_error_json(HTTPStatus.INTERNAL_SERVER_ERROR, "backend error")
809783
finally:
810-
self._concurrency.release_write(image_id)
811784
dur = now_s() - start
812785
logging.info(
813786
"PATCH range end image_id=%s bytes=%d duration_s=%.3f",

scripts/vm/hypervisor/kvm/imageserver/server.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
class ThreadingHTTPServer(ThreadingMixIn, HTTPServer): # type: ignore[no-redef]
3434
pass
3535

36-
from .concurrency import ConcurrencyManager
3736
from .config import TransferRegistry, validate_transfer_config
3837
from .constants import (
3938
CONTROL_RECV_BUFFER,
@@ -42,14 +41,11 @@ class ThreadingHTTPServer(ThreadingMixIn, HTTPServer): # type: ignore[no-redef]
4241
CONTROL_SOCKET_PERMISSIONS,
4342
DEFAULT_HTTP_PORT,
4443
DEFAULT_LISTEN_ADDRESS,
45-
MAX_PARALLEL_READS,
46-
MAX_PARALLEL_WRITES,
4744
)
4845
from .handler import Handler
4946

5047

5148
def make_handler(
52-
concurrency: ConcurrencyManager,
5349
registry: TransferRegistry,
5450
) -> Type[Handler]:
5551
"""
@@ -60,7 +56,6 @@ def make_handler(
6056
"""
6157

6258
class ConfiguredHandler(Handler):
63-
_concurrency = concurrency
6459
_registry = registry
6560

6661
return ConfiguredHandler
@@ -186,8 +181,7 @@ def main() -> None:
186181
)
187182

188183
registry = TransferRegistry()
189-
concurrency = ConcurrencyManager(MAX_PARALLEL_READS, MAX_PARALLEL_WRITES)
190-
handler_cls = make_handler(concurrency, registry)
184+
handler_cls = make_handler(registry)
191185

192186
ctrl_thread = threading.Thread(
193187
target=_control_listener,

0 commit comments

Comments
 (0)