cURL by Example: Limit Upload Speed
Throttle upload bandwidth. Useful for testing low-bandwidth conditions or being a good network citizen.
Code
# Limit upload to 1 megabyte per second
curl --limit-rate 1M -T bigfile.iso https://upload.example.com
# Limit to 500 kilobytes per second
curl --limit-rate 500k -F "[email protected]" https://api.example.com/uploadExplanation
Bandwidth throttling with the --limit-rate option provides precise control over upload and download speeds, measured as a maximum average transfer rate over several seconds. While cURL cannot inherently detect your connection's maximum speed, it will actively limit itself to stay at or below your specified rate. Unlike instantaneous speed caps, --limit-rate sets an average target, so short bursts above the limit may occur, but cURL will compensate by slowing down to maintain the average over time. This averaging behavior happens over a window of several seconds, making it suitable for long-running transfers rather than microsecond-precision control.
Unit Specifications and Practical Limits: The speed can be specified in various units for convenience: bytes per second (default, no suffix), kilobytes with k or K suffix (e.g., --limit-rate 500k = 500 KB/s), megabytes with M suffix (e.g., --limit-rate 10M = 10 MB/s), or gigabytes with G suffix for very high-speed limits. Note these are kilobytes/megabytes (1000 bytes), not kibibytes/mebibytes (1024 bytes). Both upload and download speeds are governed by the same --limit-rate setting—there's no way to set different limits for each direction in a single command. If you need asymmetric limits, you'd run separate cURL commands.
Why Throttle Uploads? Upload throttling serves several critical purposes beyond just "being polite." Most residential internet connections are asymmetric with much lower upload than download bandwidth (e.g., 100 Mbps down but only 10 Mbps up). A large upload at full speed can completely saturate your uplink, causing severe latency issues for all other internet activity including web browsing, video calls, and gaming—this is called "bufferbloat." Limiting uploads to 50-80% of your max uplink capacity keeps the connection responsive. In testing scenarios, throttling simulates slow connections or mobile networks: --limit-rate 100k simulates a poor mobile connection, letting you test how your app handles timeouts, progress bars, and user experience under constrained bandwidth. For shared infrastructure, being a good network citizen means not monopolizing bandwidth that others need. Some hosting providers or APIs have rate limits or may throttle aggressive uploaders, and proactively limiting your own rate can prevent triggering these defensive measures.
Monitoring and Network Testing: Combine --limit-rate with the -w (write-out) flag to monitor actual transfer speeds and verify the limit is working: curl --limit-rate 1M -w "Average speed: %{speed_upload} bytes/sec
" -T file.zip https://upload.example.com. The reported speed should hover around your limit. For testing how applications behave under various network conditions, systematically vary the limit: test with 56k modem speeds (--limit-rate 7k), 3G speeds (--limit-rate 384k), LTE speeds (--limit-rate 5M), etc. This is invaluable for mobile app development or progressive web apps that need to work across varying network conditions. Remember that --limit-rate is client-side throttling—the server still processes data as fast as cURL sends it. For server-side rate limiting, you'd need server configuration changes.
Code Breakdown
--limit-rate 1M caps speed at 1MB/s.500k is 500 kilobytes/s.
