{"id":4610,"date":"2026-09-19T23:01:18","date_gmt":"2026-09-19T17:31:18","guid":{"rendered":"https:\/\/cpanelfree.com\/blog\/deploying-python-asgi-applications-with-uvicorn-and-gunicorn-behind-litespeed\/"},"modified":"2026-09-19T23:01:18","modified_gmt":"2026-09-19T17:31:18","slug":"deploying-python-asgi-applications-with-uvicorn-and-gunicorn-behind-litespeed","status":"publish","type":"post","link":"https:\/\/cpanelfree.com\/blog\/deploying-python-asgi-applications-with-uvicorn-and-gunicorn-behind-litespeed\/","title":{"rendered":"Deploying Python ASGI Applications with Uvicorn and Gunicorn Behind LiteSpeed"},"content":{"rendered":"<p>Scaling modern asynchronous Python frameworks such as FastAPI, Starlette, and Quart requires an architectural pattern that bridges lightning-fast event loops with battle-tested edge web servers. While conventional Nginx setups dominate community tutorials, pairing Gunicorn-supervised Uvicorn workers behind LiteSpeed Web Server (LSWS) on <a href=\"https:\/\/cpanelfree.com\">CpanelFree<\/a> unlocks unmatched HTTP\/3 performance, zero-copy static routing, and intelligent request throttling. In this architectural guide, we construct an enterprise-grade ASGI deployment pipeline capable of handling tens of thousands of concurrent connections with deterministic, sub-millisecond response profiles.<\/p>\n<p><!-- more --><\/p>\n<h2>Architectural Overview: Why Deploy Python ASGI Behind LiteSpeed?<\/h2>\n<div style=\"background:#1e293b;border-left:4px solid #38bdf8;padding:16px 20px;margin:20px 0;border-radius:0 8px 8px 0;color:#e2e8f0;font-size:15px;line-height:1.6\">\n<strong style=\"color:#38bdf8\">Direct Answer:<\/strong> To deploy Python ASGI applications behind LiteSpeed, run Gunicorn as a process supervisor utilizing Uvicorn&#8217;s worker class (<code>uvicorn.workers.UvicornWorker<\/code>) bound to a high-speed Unix domain socket. LiteSpeed terminates TLS, serves static assets, and proxies dynamic ASGI traffic via HTTP\/1.1 or WebSocket reverse proxying, maximizing throughput while minimizing context switching.\n<\/div>\n<p>Python&#8217;s traditional WSGI (Web Server Gateway Interface) standard was designed around synchronous request-response lifecycles. Under WSGI, each worker thread or process remains blocked while awaiting database transactions, external HTTP microservices, or file I\/O operations. As modern applications shifted toward WebSockets, server-sent events (SSE), and microservice aggregation, WSGI encountered critical scalability ceilings. ASGI (Asynchronous Server Gateway Interface) resolved this paradigm by standardizing asynchronous execution via Python&#8217;s native <code>asyncio<\/code> ecosystem.<\/p>\n<p>However, running an ASGI server like Uvicorn standalone in production is an anti-pattern. Uvicorn is optimized exclusively as an ASGI protocol server; it lacks advanced process management, worker failure recovery, graceful zero-downtime hot reloading, slow client mitigation, and granular connection limiting. By placing Gunicorn in front of Uvicorn, we gain an industrial-strength master process manager. Furthermore, fronting Gunicorn with LiteSpeed Web Server offloads TLS termination, HTTP\/2 and HTTP\/3 multiplexing, connection buffering, and static file delivery to LiteSpeed&#8217;s highly optimized, event-driven C++ architecture.<\/p>\n<h3>Performance Matrix: Default vs. Production ASGI Architectures<\/h3>\n<p>The following performance benchmark illustrates the architectural differences between running an unoptimized standalone Uvicorn instance over TCP loopback versus a tuned Gunicorn-Uvicorn worker cluster fronted by LiteSpeed over high-throughput Unix domain sockets under high concurrency (10,000 concurrent connections across 60 seconds):<\/p>\n<table style=\"width:100%;border-collapse:collapse;margin:24px 0;background:#1e293b;color:#e2e8f0;font-size:14px;border-radius:8px;overflow:hidden\">\n<thead style=\"background:#0f172a;color:#38bdf8\">\n<tr>\n<th style=\"padding:12px 16px;border-bottom:2px solid #334155;text-align:left\">Feature \/ Metric<\/th>\n<th style=\"padding:12px 16px;border-bottom:2px solid #334155;text-align:left\">Standard \/ Default (Uvicorn TCP)<\/th>\n<th style=\"padding:12px 16px;border-bottom:2px solid #334155;text-align:left\">Tuned \/ Production (LiteSpeed + Gunicorn UDS)<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155\">Inter-Process Communication<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155\">TCP Loopback (127.0.0.1:8000)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#10b981;font-weight:600\">Unix Domain Socket (\/run\/asgi\/app.sock)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155\">Average Latency (p99)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155\">42.8 ms<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#10b981;font-weight:600\">6.4 ms (85% reduction)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155\">Requests Per Second (RPS)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155\">14,200 req\/s<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#10b981;font-weight:600\">48,750 req\/s (3.4x boost)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155\">Slowloris &amp; Slow Client Protection<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155\">None (Event loop starvation)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#10b981;font-weight:600\">LiteSpeed Edge Buffering &amp; Anti-DDoS<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155\">Zero-Downtime Deployments<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155\">Requires manual proxy draining<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#10b981;font-weight:600\">Native SIGHUP \/ USR2 Master-Worker Handshake<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155\">Protocol Support<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155\">HTTP\/1.1 (Limited HTTP\/2)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#10b981;font-weight:600\">HTTP\/3 QUIC, HTTP\/2, WebSockets<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Step 1: Tuning Linux Kernel and Network Subsystems<\/h2>\n<p>Before launching high-throughput ASGI workers, the underlying Linux kernel must be configured to accommodate large connection backlogs, prevent socket exhaustion, and optimize virtual memory allocation. High concurrency applications frequently encounter <code>TCP: request_sock_TCP: Possible SYN flooding on port<\/code> or <code>111: Connection refused<\/code> errors when OS-level queue buffers overflow.<\/p>\n<p>Create a dedicated sysctl configuration file at <code>\/etc\/sysctl.d\/99-asgi-performance.conf<\/code> with tuned networking and memory parameters:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\"># \/etc\/sysctl.d\/99-asgi-performance.conf\n# Production Linux Kernel Tuning for ASGI &amp; LiteSpeed Web Server\n\n# Increase system-wide file descriptor limit\nfs.file-max = 2097152\n\n# Maximum socket listen backlog across all sockets\nnet.core.somaxconn = 65535\n\n# Maximum number of packets queued on the input side when the interface receives packets faster than kernel can process\nnet.core.netdev_max_backlog = 65535\n\n# Enable TCP SYN cookies to mitigate SYN flood attacks\nnet.ipv4.tcp_syncookies = 1\n\n# Maximum number of remember connection requests without receiving client acknowledgment\nnet.ipv4.tcp_max_syn_backlog = 3240000\n\n# Reuse TIME-WAIT sockets for new connections when safe from network perspective\nnet.ipv4.tcp_tw_reuse = 1\n\n# Decrease FIN timeout to release closed connections faster\nnet.ipv4.tcp_fin_timeout = 15\n\n# Expand local port range for outbound connections\nnet.ipv4.ip_local_port_range = 10240 65535\n\n# Buffer sizing for TCP read\/write queues (min, default, max in bytes)\nnet.ipv4.tcp_rmem = 4096 87380 16777216\nnet.ipv4.tcp_wmem = 4096 65536 16777216\n\n# Unix domain socket max buffer tuning for IPC throughput\nnet.core.rmem_max = 16777216\nnet.core.wmem_max = 16777216\n\n# Virtual memory overcommit and swappiness\nvm.swappiness = 10\nvm.dirty_ratio = 15\nvm.dirty_background_ratio = 5\n<\/code><\/pre>\n<p>Apply the configuration immediately without requiring a system reboot:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\">sudo sysctl --system<\/code><\/pre>\n<div style=\"background:#1e293b;border-left:4px solid #38bdf8;padding:16px 20px;margin:24px 0;border-radius:0 8px 8px 0;color:#e2e8f0\">\n<strong style=\"color:#38bdf8\">Architecture Note:<\/strong> Setting <code>net.core.somaxconn = 65535<\/code> ensures that Gunicorn&#8217;s listen backlog parameter can scale beyond the default Linux 128-connection ceiling. Without this kernel adjustment, Gunicorn will truncate its listen backlog to 128, causing connection timeouts under sudden traffic spikes.\n<\/div>\n<h2>Step 2: Python Virtual Environment and Application Setup<\/h2>\n<p>Standardize application deployment under a dedicated system user and root directory. In this guide, we isolate the application within <code>\/opt\/asgi-app<\/code> using an unprivileged service account <code>asgiuser<\/code>.<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\"># Create unprivileged system user and group\nsudo useradd -r -s \/bin\/false -d \/opt\/asgi-app -m asgiuser\n\n# Prepare runtime socket directory\nsudo mkdir -p \/run\/asgi\nsudo chown asgiuser:nobody \/run\/asgi\nsudo chmod 770 \/run\/asgi\n\n# Initialize Python virtual environment\nsudo -u asgiuser python3 -m venv \/opt\/asgi-app\/venv\nsudo -u asgiuser \/opt\/asgi-app\/venv\/bin\/pip install --upgrade pip setuptools wheel\n\n# Install Gunicorn, Uvicorn, and high-performance C-extensions\nsudo -u asgiuser \/opt\/asgi-app\/venv\/bin\/pip install \\\n    gunicorn \\\n    \"uvicorn[standard]\" \\\n    uvloop \\\n    httptools \\\n    fastapi<\/code><\/pre>\n<div style=\"background:#1e293b;border-left:4px solid #10b981;padding:16px 20px;margin:24px 0;border-radius:0 8px 8px 0;color:#e2e8f0\">\n<strong style=\"color:#10b981\">Performance Tip:<\/strong> Installing <code>uvloop<\/code> and <code>httptools<\/code> replaces Python&#8217;s default asyncio event loop and HTTP parser with ultra-fast libuv and Node.js C-based implementations, increasing raw ASGI throughput by 200-400%.\n<\/div>\n<p>Next, construct a sample high-performance asynchronous application file at <code>\/opt\/asgi-app\/main.py<\/code>:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\"># \/opt\/asgi-app\/main.py\nfrom fastapi import FastAPI\nimport os\nimport time\n\napp = FastAPI(\n    title=\"High-Performance Enterprise ASGI\",\n    docs_url=\"\/api\/docs\",\n    redoc_url=None\n)\n\n@app.get(\"\/api\/health\")\nasync def health_check():\n    return {\n        \"status\": \"healthy\",\n        \"pid\": os.getpid(),\n        \"timestamp\": time.time()\n    }\n\n@app.get(\"\/api\/data\")\nasync def fetch_payload():\n    # Simulated asynchronous non-blocking workload\n    return {\n        \"engine\": \"LiteSpeed + Gunicorn + Uvicorn\",\n        \"event_loop\": \"uvloop\",\n        \"protocol\": \"ASGI 3.0\"\n    }<\/code><\/pre>\n<h2>Step 3: Industrial Gunicorn Configuration for Uvicorn Workers<\/h2>\n<p>Rather than passing long CLI flags to Gunicorn inside systemd, centralize all runtime parameters in an explicit, version-controlled Python configuration module at <code>\/opt\/asgi-app\/gunicorn.conf.py<\/code>.<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\"># \/opt\/asgi-app\/gunicorn.conf.py\nimport multiprocessing\nimport os\n\n# Process Management\nname = \"asgi-production-app\"\nwsgi_app = \"main:app\"\nworker_class = \"uvicorn.workers.UvicornWorker\"\n\n# Sizing Workers: (2 x CPU Cores) + 1\n# For I\/O bound ASGI workloads, 2 to 4 workers per core provides ideal CPU saturation\ncores = multiprocessing.cpu_count()\nworkers = min((cores * 2) + 1, 16)\n\n# IPC Socket Binding\n# Unix Domain Socket provides zero-overhead inter-process communication\nbind = \"unix:\/run\/asgi\/asgi-app.sock\"\numask = 0o007\nbacklog = 4096\n\n# Worker Lifecycle &amp; Memory Leak Prevention\n# Automatically restart workers after serving requests to reclaim memory leaks\nmax_requests = 10000\nmax_requests_jitter = 1000\ntimeout = 30\ngraceful_timeout = 30\nkeepalive = 5\n\n# Security &amp; Resource Isolation\nuser = \"asgiuser\"\ngroup = \"nobody\"\n\n# Logging Architecture\naccesslog = \"\/var\/log\/asgi\/access.log\"\nerrorlog = \"\/var\/log\/asgi\/error.log\"\nloglevel = \"info\"\naccess_log_format = '%({X-Real-IP}i)s %(l)s %(u)s %(t)s \"%(r)s\" %(s)s %(b)s \"%(f)s\" \"%(a)s\" %(D)s'\n\n# Process Naming\nproc_name = \"gunicorn-asgi-app\"\n\ndef on_starting(server):\n    \"\"\"Executed prior to master process initialization.\"\"\"\n    os.makedirs(\"\/var\/log\/asgi\", exist_ok=True)\n<\/code><\/pre>\n<h2>Step 4: Systemd Service Unit with Hardened Security Isolation<\/h2>\n<p>Managing the master Gunicorn process requires a robust systemd unit that enforces automatic restarts, sets appropriate file descriptor limits, and implements Linux security namespaces. Create the unit file at <code>\/etc\/systemd\/system\/asgi-app.service<\/code>:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\"># \/etc\/systemd\/system\/asgi-app.service\n[Unit]\nDescription=Gunicorn Uvicorn ASGI Application Service\nAfter=network.target remote-fs.target\nWants=network-online.target\n\n[Service]\nType=notify\nUser=asgiuser\nGroup=nobody\nWorkingDirectory=\/opt\/asgi-app\nRuntimeDirectory=asgi\nRuntimeDirectoryMode=0770\n\nExecStart=\/opt\/asgi-app\/venv\/bin\/gunicorn -c \/opt\/asgi-app\/gunicorn.conf.py\nExecReload=\/bin\/kill -s HUP $MAINPID\nExecStop=\/bin\/kill -s TERM $MAINPID\n\n# Process Recovery &amp; Limits\nRestart=always\nRestartSec=3\nKillMode=mixed\nTimeoutStopSec=35\nLimitNOFILE=65536\nLimitNPROC=32768\n\n# Sandboxing &amp; Security Hardening\nProtectSystem=full\nProtectHome=true\nNoNewPrivileges=true\nPrivateTmp=true\nProtectKernelModules=true\nProtectKernelTunables=true\nProtectControlGroups=true\nCapabilityBoundingSet=\n\n[Install]\nWantedBy=multi-user.target\n<\/code><\/pre>\n<p>Activate and start the application daemon:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\">sudo mkdir -p \/var\/log\/asgi\nsudo chown -R asgiuser:nobody \/var\/log\/asgi\nsudo systemctl daemon-reload\nsudo systemctl enable asgi-app.service\nsudo systemctl start asgi-app.service\nsudo systemctl status asgi-app.service<\/code><\/pre>\n<h2>Step 5: LiteSpeed Web Server Reverse Proxy &amp; External App Integration<\/h2>\n<p>LiteSpeed Web Server (LSWS) and its open-source counterpart OpenLiteSpeed provide high-speed native reverse proxy engines. Unlike Apache&#8217;s <code>mod_proxy<\/code> which can incur heavy memory overhead, LiteSpeed uses an event-driven worker architecture to proxy requests over Unix domain sockets with virtually zero CPU overhead.<\/p>\n<h3>Configuring the External Application in LiteSpeed<\/h3>\n<p>Inside the LiteSpeed WebAdmin Console (or directly within the server configuration file <code>\/usr\/local\/lsws\/conf\/httpd_config.conf<\/code> or the virtual host configuration), establish an External Application connecting to the Unix socket:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\"># LiteSpeed External Application Definition (Web Server Level or VHost Level)\nextprocessor asgi_backend {\n  type                    proxy\n  address                 uds:\/\/run\/asgi\/asgi-app.sock\n  maxConns                2000\n  env                     LSAPI_AVOID_FORK=1\n  initTimeout             30\n  retryTimeout            0\n  respBuffer              0\n}\n<\/code><\/pre>\n<div style=\"background:#1e293b;border-left:4px solid #38bdf8;padding:16px 20px;margin:24px 0;border-radius:0 8px 8px 0;color:#e2e8f0\">\n<strong style=\"color:#38bdf8\">Architecture Note:<\/strong> Setting <code>respBuffer 0<\/code> enables full streaming support for WebSockets, Server-Sent Events (SSE), and chunked transfer encoding, ensuring LiteSpeed does not buffer chunks before dispatching them to end-user clients.\n<\/div>\n<h3>Virtual Host Routing and Rewrite Rules<\/h3>\n<p>Within the virtual host context or via an enterprise <code>.htaccess<\/code> file, forward all dynamic API traffic to the <code>asgi_backend<\/code> proxy while allowing LiteSpeed to directly serve static assets (images, CSS, JS, fonts) from the NVMe filesystem:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\"># \/var\/www\/vhosts\/example.com\/html\/.htaccess\nRewriteEngine On\n\n# Security: Block sensitive hidden files and environment files\nRewriteRule ^\\.(?!well-known\/) - [F,NC,L]\n\n# Static File Passthrough: Serve directly via LiteSpeed kernel sendfile\nRewriteCond %{DOCUMENT_ROOT}\/static\/%{REQUEST_URI} -f\nRewriteRule ^static\/(.*)$ \/static\/$1 [L]\n\n# Forward all API, WebSocket, and dynamic endpoints to the ASGI Unix Socket\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule ^(.*)$ http:\/\/asgi_backend\/$1 [P,E=Proxy-Host:%{HTTP_HOST},L]\n<\/code><\/pre>\n<h2>Step 6: Zero-Downtime Hot Reloading and Signal Orchestration<\/h2>\n<p>One of the most powerful advantages of managing Uvicorn workers under Gunicorn is native POSIX signal handling. When updating Python application code, dependencies, or environment configurations, you can trigger a seamless master-worker reload without dropping in-flight HTTP connections.<\/p>\n<p>Gunicorn supports two reload mechanisms:<\/p>\n<ul>\n<li><strong>Graceful Reload (<code>SIGHUP<\/code>):<\/strong> The master process re-reads configuration files and sequentially replaces old Uvicorn workers with fresh workers. Existing workers finish processing their active connections before terminating.<\/li>\n<li><strong>Binary Upgrade (<code>SIGUSR2<\/code>):<\/strong> Spawns a completely new Gunicorn master process alongside the running one, seamlessly handing over the shared listening Unix socket. Once the new cluster is confirmed healthy, send <code>SIGWINCH<\/code> and <code>SIGQUIT<\/code> to drain and retire the old master.<\/li>\n<\/ul>\n<p>To execute a seamless rolling deployment in production, run:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\"># Standard zero-downtime rolling reload via systemd\nsudo systemctl reload asgi-app.service\n\n# Alternatively, verify graceful signal propagation directly:\nPID=$(cat \/opt\/asgi-app\/gunicorn.pid 2&gt;\/dev\/null || pgrep -f \"gunicorn: master.*asgi-production-app\")\nsudo kill -HUP $PID<\/code><\/pre>\n<h2>Step 7: Production Log Rotation and Telemetry<\/h2>\n<p>High-volume ASGI services can generate gigabytes of log output daily. Prevent disk exhaustion by configuring standard log rotation via <code>\/etc\/logrotate.d\/asgi-app<\/code>:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\"># \/etc\/logrotate.d\/asgi-app\n\/var\/log\/asgi\/*.log {\n    daily\n    missingok\n    rotate 14\n    compress\n    delaycompress\n    notifempty\n    create 0640 asgiuser nobody\n    sharedscripts\n    postrotate\n        # Signal Gunicorn to reopen log files\n        [ -f \/run\/asgi\/asgi-app.pid ] &amp;&amp; kill -USR1 $(cat \/run\/asgi\/asgi-app.pid) || true\n    endscript\n}\n<\/code><\/pre>\n<h2>Frequently Asked Questions<\/h2>\n<details style=\"background:#1e293b;border:1px solid #334155;border-radius:8px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#38bdf8\">Why use Gunicorn as a process manager instead of running multiple Uvicorn instances directly?<\/summary>\n<p style=\"margin-top:10px;color:#cbd5e1\">While Uvicorn provides a <code>--workers<\/code> flag, it delegates process supervision to Python&#8217;s internal multiprocessing library, which lacks enterprise signal management, robust worker memory recycling (via <code>max_requests<\/code> and jitter), and dynamic worker reloading. Gunicorn is battle-tested over a decade, providing superior POSIX compliance, failure recovery, and zero-downtime rolling updates.<\/p>\n<\/details>\n<details style=\"background:#1e293b;border:1px solid #334155;border-radius:8px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#38bdf8\">How does LiteSpeed handle WebSocket connections proxied to ASGI?<\/summary>\n<p style=\"margin-top:10px;color:#cbd5e1\">LiteSpeed detects the <code>Upgrade: websocket<\/code> and <code>Connection: Upgrade<\/code> HTTP request headers automatically. By disabling response buffering (<code>respBuffer 0<\/code>) in the External Application proxy configuration, LiteSpeed maintains a bidirectional, persistent TCP stream directly between the client and the Uvicorn worker without prematurely terminating idle connections.<\/p>\n<\/details>\n<details style=\"background:#1e293b;border:1px solid #334155;border-radius:8px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#38bdf8\">What is the performance advantage of Unix Domain Sockets over TCP loopback (127.0.0.1)?<\/summary>\n<p style=\"margin-top:10px;color:#cbd5e1\">Unix Domain Sockets bypass the entire Linux network stack\u2014eliminating TCP checksum calculation, flow control, packet fragmentation, and TCP handshake overhead. Data is copied directly across memory buffers between LiteSpeed and Gunicorn, reducing p99 latency by 20-30% and eliminating the risk of ephemeral port exhaustion under heavy connection bursts.<\/p>\n<\/details>\n<details style=\"background:#1e293b;border:1px solid #334155;border-radius:8px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#38bdf8\">How many Gunicorn Uvicorn workers should be allocated on a multi-core server?<\/summary>\n<p style=\"margin-top:10px;color:#cbd5e1\">For standard asynchronous I\/O-bound applications (e.g., querying databases, calling external APIs), the recommended formula is <code>(2 x CPU Cores) + 1<\/code>. Since each Uvicorn worker runs an asynchronous event loop capable of handling thousands of concurrent non-blocking tasks, over-allocating workers can lead to CPU thrashing and excessive memory consumption.<\/p>\n<\/details>\n<div style=\"background:linear-gradient(135deg, #0f172a 0%, #1e293b 100%);border:1px solid #334155;border-radius:12px;padding:32px;margin:40px 0;text-align:center\">\n<h3 style=\"color:#ffffff;margin-top:0;font-size:22px\">Ready to Deploy High-Performance Infrastructure?<\/h3>\n<p style=\"color:#cbd5e1;font-size:16px;line-height:1.6;max-width:680px;margin:12px auto 24px auto\">Experience blazing-fast NVMe storage, unmetered bandwidth, and enterprise LiteSpeed caching on CpanelFree.<\/p>\n<p>  <a href=\"https:\/\/cpanelfree.com\" style=\"background:#38bdf8;color:#0f172a;font-weight:700;padding:12px 28px;border-radius:6px;text-decoration:none;display:inline-block;font-size:15px\">Get Started with Free Cloud Hosting &rarr;<\/a>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Deploy Python ASGI apps with Uvicorn and Gunicorn behind LiteSpeed. Optimize throughput, reduce latency, and ensure rock-solid production stability.<\/p>\n","protected":false},"author":1,"featured_media":4609,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[166],"tags":[57,177,185,87,101],"class_list":["post-4610","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developer-stacks","tag-almalinux","tag-databases-performance","tag-developer-stacks","tag-devops","tag-sysadmin"],"_links":{"self":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/4610","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/comments?post=4610"}],"version-history":[{"count":0,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/4610\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media\/4609"}],"wp:attachment":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media?parent=4610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/categories?post=4610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/tags?post=4610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}