【问题标题】:Simulate delayed response for specific address模拟特定地址的延迟响应
【发布时间】:2012-05-02 17:35:11
【问题描述】:

我想测试当远程服务器响应缓慢时加载外部 javascript 对页面的影响。

我寻找可以减慢特定网站连接速度的工具,但我只能找到减慢整个网络或 Mac 不存在的工具(例如 herehere

有这样的工具吗?

【问题讨论】:

  • iptables,简而言之,但您可以改为设置代理 - 并在其中创建延迟池

标签: javascript networking simulate


【解决方案1】:

使用适用于 Mac 的 Detours App,您可以将某些主机重定向到您自己的本地 Web 服务器。然后,您可以从您的服务器获取资源(通过 curl 等),休眠一段时间,然后返回响应。

【讨论】:

  • 这是一个有趣的概念。我试试看
【解决方案2】:

这不是简单的方法,但您可以将 IPTABLES(unix ip-router)与 TC(流量控制)结合使用吗? 如果您不知道终端 bash 脚本是如何工作的,那么这非常广泛,但您需要 100% 的终端才能获得正确的解决方案。

如果这对您不起作用,请尝试更简单的方法:http://lartc.org/howto/lartc.ratelimit.single.html

将其存储在例如您的主文件夹中,将其命名为 bwm.sh

#!/bin/bash

# through this interface
IF=$1
# on this HOST
HOST=$2
# get the IP from HOST
HOSTIP="`nslookup $HOST|grep Address|grep -v "#"|cut -d " " -f2`"
# with this rate
your_rate=$3


# defaults /sbin/tc
TC="`whereis tc | sed 's/[^\ ]*.\([^\ ]*\).*/\1/'`" 
# defaults /sbin/iptables
IPTABLES="`whereis iptables | sed 's/[^\ ]*.\([^\ ]*\).*/\1/'`" 

#some number
PRIO="123"
# you create a new rule in the mangle table
IPT="$IPTABLES -t mangle"

echo "Program locations found: iptables: $IPTABLES and tc: $TC"
echo "down-rating bandwidth\n on $HOST\n to $your_rate whilst marking packages that origins\n from $HOSTIP\n with $PRIO on interface\n named $IF"
echo -n "starting setup.."

# apply custom filter
$IPT -N myfilter

# add it to the POSTROUTING chain
$IPT -A POSTROUTING -j myfilter

# if conntrack is used - restore a mark and allow the packets, which already have been marked, through - no need to check again

$IPT -A myfilter -p tcp -j CONNMARK --restore-mark
$IPT -A myfilter -m mark --mark $PRIO -j ACCEPT

# add to it your matching rule

$IPT -A myfilter -p tcp -s $HOSTIP -j MARK --set-mark $PRIO

# conntrack it optionally, so not every packet has to be rematched
$IPT -A myfilter -j CONNMARK --save-mark

# use that mark in a tc filter rule
echo qdisc add
$TC qdisc add dev $IF root handle 1: htb default 30
echo class add
$TC class add dev $IF parent 1: classid 1:1 htb rate $your_rate # <<<<<<<< fill in rate

echo sfq add
# add an SFQ qdisc to the end - to which you then attach the actual filter
$TC qdisc add dev $IF parent 1:1 sfq perturb 10
echo filter add
$TC filter add dev $IF parent 1:1 prio 1 handle $PRIO fw flowid 1:1
echo "done"

现在打开终端窗口并获得root权限

finder > 终端 > 打开,我们将进入用户主页并输入超级用户

cd; su

输入root密码

使用接口、主机名、速率参数启动程序

sh bwm.sh IF HOST RATE

【讨论】:

  • 感谢您的回答!我很遗憾地说 netem 在所有努力之后都无法用于 mac。
  • 不确定您所说的 netem 是什么意思?但我猜你的意思是找不到工具?
  • netem 是具有您在答案中使用的命令行“tc”的软件。你可以在这里找到它:linuxfoundation.org/collaborate/workgroups/networking/netem,它在 Mac 中不可用
  • 啊,不知道那个网络模拟器的东西 :=) 但是,为了将来在这里查找,正确的包 - 无论如何在 linux 存储库中 - 是 iproute(2),在这里找到了一个很棒的 wiki:@ 987654323@
  • 运行一个建议的程序(它实际上是一个代理服务器)可能足够可行,无论如何在开发环境中。但是在你的本地主机上代理网络是相当过分的,比如一台笔记本电脑
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-01-02
  • 1970-01-01
  • 2017-02-15
  • 2017-03-25
  • 1970-01-01
  • 2018-09-22
  • 2014-01-04
相关资源
最近更新 更多