{"id":2395,"date":"2010-12-14T10:38:13","date_gmt":"2010-12-14T09:38:13","guid":{"rendered":"http:\/\/daniel.haxx.se\/blog\/?p=2395"},"modified":"2019-03-05T22:16:51","modified_gmt":"2019-03-05T21:16:51","slug":"add-latency-to-localhost","status":"publish","type":"post","link":"https:\/\/daniel.haxx.se\/blog\/2010\/12\/14\/add-latency-to-localhost\/","title":{"rendered":"Add latency to localhost"},"content":{"rendered":"<p>P\u00e1draig Brady taught me a great trick in a <a href=\"http:\/\/daniel.haxx.se\/blog\/2010\/12\/08\/making-sftp-transfers-fast\/#comment-3638\">comment to a previous blog post<\/a> and it was so neat I feel a need to highlight it further as it also makes it easier for me to find it again later!<\/p>\n<p>To simulate a far away server, add RTT time to the localhost device. For example if we add 100 milliseconds (which then makes 200ms ping time to localhost):<\/p>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;\">$ tc qdisc add dev lo root handle 1:0 netem delay 100msec<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;\">Restore it back to normal again with:<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;\">$ tc qdisc del dev lo root<\/div>\n<blockquote>\n<pre>tc qdisc add dev lo root handle 1:0 netem delay 100msec<\/pre>\n<\/blockquote>\n<p>Restore it back to normal again with:<\/p>\n<blockquote>\n<pre>tc qdisc del dev lo root<\/pre>\n<\/blockquote>\n\n\n<p>In addition, add a random packet loss. 500ms latency with 2.5% packet loss:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">tc qdisc add dev lo root handle 1:0 netem delay 250msec loss 2.5%<\/pre>\n\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>P\u00e1draig Brady taught me a great trick in a comment to a previous blog post and it was so neat I feel a need to highlight it further as it also makes it easier for me to find it again later! To simulate a far away server, add RTT time to the localhost device. For &hellip; <a href=\"https:\/\/daniel.haxx.se\/blog\/2010\/12\/14\/add-latency-to-localhost\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Add latency to localhost<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,13],"tags":[421,302,219],"class_list":["post-2395","post","type-post","status-publish","format-standard","hentry","category-linux","category-net","tag-linux","tag-localhost","tag-network"],"_links":{"self":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/2395","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/comments?post=2395"}],"version-history":[{"count":9,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/2395\/revisions"}],"predecessor-version":[{"id":12077,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/2395\/revisions\/12077"}],"wp:attachment":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/media?parent=2395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/categories?post=2395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/tags?post=2395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}