【发布时间】:2013-10-17 17:56:26
【问题描述】:
我正在尝试实现一个 ajax 页面加载图标,但我当然无法在本地主机上对其进行测试,因为它会立即加载......
如何在 Ubuntu 中使用 Eclipse 平台模拟慢速互联网连接,这将允许我测试加载图标???
非常感谢
【问题讨论】:
标签: django eclipse performance connection pydev
我正在尝试实现一个 ajax 页面加载图标,但我当然无法在本地主机上对其进行测试,因为它会立即加载......
如何在 Ubuntu 中使用 Eclipse 平台模拟慢速互联网连接,这将允许我测试加载图标???
非常感谢
【问题讨论】:
标签: django eclipse performance connection pydev
这对中间件很有用。 Here 是一个中间件示例,可以将每个请求延迟一定量,可在您的设置中进行配置:
"""
This module provides very simple Django middleware that sleeps on every request.
This is useful when you want to simulate slow response times (as might be
encountered, say, on a cell network).
To use, add this middleware, and add a value for SLEEP_TIME to your settings.
Possible future feature: Look for an X-Django-Sleep header on each request,
to let the client specify per-request sleep time.
"""
import time
import django.conf
import django.core.exceptions
class SleepMiddleware(object):
def __init__(self):
self.sleep_time = getattr(django.conf.settings, "SLEEP_TIME", 0)
if not isinstance(self.sleep_time, (int, float)) or self.sleep_time <= 0:
raise django.core.exceptions.MiddlewareNotUsed
def process_request(self, request):
time.sleep(self.sleep_time)
您可以从这里变得更有趣,例如,加入随机性,这在测试复杂的 ajax 交互时很有用。
【讨论】:
在您的视图中输入time.sleep(5),然后返回睡眠状态五秒钟。
【讨论】:
from time import sleep,然后是 sleep(5)。但是非常感谢你让我完成了 90% 的路!!
对于 200 毫秒的延迟,我只需使用以下命令:
sudo tc qdisc add dev enp2s0 root netem delay 200ms
将add 更改为del 以返回原始状态。
您可以通过在延迟的机器上执行 ping 来监控事情的变化。
我是从here那里拿到的。
【讨论】: