PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Oct 22, 2017 3:52 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Network emulator
PostPosted: Tue Jul 20, 2010 4:27 pm 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4296
Location: Sofia, Bulgaria
Linux only! (of course)
It will emulate network delay, network packet loss and network bandwidth limits.
Edit the values in the EDIT section.

Syntax: [ Download ] [ Hide ]
#!/bin/bash

#-EDIT BEGIN-----------------------------------------------------------------------------------------#


DELAY=100                       #[ms]
DELAY_VARIATON=10               #[ms]
DELAY_CORRELATION=10            #[%]

PACKET_LOSS=0.5                 #[%]
PACKET_LOSS_CORRELATION=        #[%]

TRAFFIC_RATE=300                #[kbit]

DEV="lo"                        #[ lo | ethX | wlanX | etc. ]
IP="127.0.0.1"

#-EDIT END-------------------------------------------------------------------------------------------#

TC=`which tc`

$TC qdisc del dev $DEV root 2>/dev/null

if [ "$1" = "stop" ];
then
        exit 0
fi

$TC qdisc add dev $DEV handle 1: root htb r2q 1700
$TC class add dev $DEV parent 1:1 classid 1:20 htb rate ${TRAFFIC_RATE}kbit
$TC qdisc add dev $DEV parent 1:20 handle 12: netem delay ${DELAY}ms ${DELAY_VARIATON}ms ${DELAY_CORRELATION}% loss ${PACKET_LOSS} ${PACKET_LOSS_CORRELATION}
$TC filter add dev $DEV protocol ip parent 1: u32 match ip src $IP flowid 1:20


To stop emulation run ./your_file_name stop

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Last edited by VladSun on Sun Sep 05, 2010 3:19 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Network emulator
PostPosted: Tue Jul 20, 2010 6:29 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
What would you test with this in PHP?


Top
 Profile  
 
 Post subject: Re: Network emulator
PostPosted: Wed Jul 21, 2010 1:02 am 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4296
Location: Sofia, Bulgaria
fsockopen :P

It's not PHP specific, it's a web development testing tool.

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
 Post subject: Re: Network emulator
PostPosted: Sun Aug 29, 2010 11:00 am 
Offline
Forum Commoner

Joined: Sun Jul 11, 2010 12:40 pm
Posts: 71
Progressive loading.

You want to make sure your web-page will look good as it loads slowly over a slow connection. One thing in particular is that people do a form, then do a JS onload event that attaches functionality to the inputs. If you do it badly, what can happen is that a user on a slow connection can get the form, start to use it, then the page finishes and the onload fires, and somehow, that form is messed up for that user.

Very handy. I was going to be looking for something like this soon myself. How does this work - does it effect traffic from a certain IP, so could I run it with the IP of my development server for instance?


Top
 Profile  
 
 Post subject: Re: Network emulator
PostPosted: Sun Aug 29, 2010 2:29 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
I think this is too pro for me to understand, vlad can you list an example how I would test this out? :D


Top
 Profile  
 
 Post subject: Re: Network emulator
PostPosted: Sun Aug 29, 2010 3:32 pm 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 5978
Location: Odessa, Ukraine
josh wrote:
I think this is too pro for me to understand, vlad can you list an example how I would test this out? :D

Well, that seems to be easy:
Syntax: [ Download ] [ Hide ]
sudo aptitude install iproute
./slowdown.sh
# enjoy your slow connection =)
./slowdown.sh stop
 


Top
 Profile  
 
 Post subject: Re: Network emulator
PostPosted: Sun Sep 05, 2010 3:28 am 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4296
Location: Sofia, Bulgaria
jarofgreen wrote:
Very handy. I was going to be looking for something like this soon myself. How does this work - does it effect traffic from a certain IP, so could I run it with the IP of my development server for instance?


The "IP" config item should be the IP address you are trying to reach. It may need to be edited together with the "DEV" config item (I've just added it) - the network interface you are connecting through.

With the configuration shown, it can be used in situations where both the developer's IDE and the HTTP (or any other network service) server run on a single machine.

This script must be run with superuser privileges (i.e. sudo ./netem.sh)

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
 Post subject: Re: Network emulator
PostPosted: Tue Apr 19, 2011 10:40 am 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 5978
Location: Odessa, Ukraine
Interestingly, it works when I use it against local machine (DEV="lo" IP="127.0.0.1") but doesn't seem to work with remote connection (DEV="eth0" IP="xxx.xxx.xxx.xxx"). By "doesn't work" I mean bandwidth limits not being applied. I tried to limit bandwidth to 30kbit, but still get ~1.4MBps (megabytes per second) downloads from that remote host.

Tested using wget <url>


Top
 Profile  
 
 Post subject: Re: Network emulator
PostPosted: Tue Apr 19, 2011 11:17 am 
Offline
DevNet Master
User avatar

Joined: Mon Feb 24, 2003 11:12 am
Posts: 2572
Location: The Republic of Texas
Using this method you can only affect egress (outgoing packets). To affect ingress you have to use something like Intermediate Functional Block pseudo-device.

_________________
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.


Top
 Profile  
 
 Post subject: Re: Network emulator
PostPosted: Tue Apr 19, 2011 2:09 pm 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 5978
Location: Odessa, Ukraine
AbraCadaver wrote:
Using this method you can only affect egress (outgoing packets).

What if I rate-limited outgoing ACKs? I realize it's not quite the same as bandwidth limit, but my understanding is that it would cause remote host to shrink send window quickly, effectively limiting bandwidth for the connection.


Top
 Profile  
 
 Post subject: Re: Network emulator
PostPosted: Tue Apr 19, 2011 2:15 pm 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4296
Location: Sofia, Bulgaria
AbraCadaver wrote:
Using this method you can only affect egress (outgoing packets). To affect ingress you have to use something like Intermediate Functional Block pseudo-device.

Or simple ingress tc

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
 Post subject: Re: Network emulator
PostPosted: Tue Apr 19, 2011 2:18 pm 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4296
Location: Sofia, Bulgaria
Weirdan wrote:
AbraCadaver wrote:
Using this method you can only affect egress (outgoing packets).

What if I rate-limited outgoing ACKs? I realize it's not quite the same as bandwidth limit, but my understanding is that it would cause remote host to shrink send window quickly, effectively limiting bandwidth for the connection.


I remember there was a TCP window-based TC implementation... can't find it now.... It's very hard to estimate the number of dropped ACK packets, so to achieve the expected incoming bandwidth. The main reason is there are a number of window management algorithms, which behave completely different.

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
 Post subject: Re: Network emulator
PostPosted: Tue Apr 19, 2011 2:26 pm 
Offline
DevNet Master
User avatar

Joined: Mon Feb 24, 2003 11:12 am
Posts: 2572
Location: The Republic of Texas
That would be hackish and kind of defeat the purpose here to be able to add real values such as bandwidth, latency, jitter, etc. and see the effects. Use IFB, something like:

Syntax: [ Download ] [ Hide ]
modprobe ifb
ip link set dev ifb0 up
tc qdisc add dev eth0 ingress
tc filter add dev eth0 parent ffff: protocol ip u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev ifb0

# then start using the ifb0 dev
tc qdisc add dev ifb0 root netem delay 100ms


It's been a while, but as far as delay goes you may have to use the one-way latency since it will be applied ingress and egress. So the above would give 200ms round-trip latency.

_________________
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.


Top
 Profile  
 
 Post subject: Re: Network emulator
PostPosted: Tue Apr 19, 2011 3:14 pm 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 5978
Location: Odessa, Ukraine
You see, I don't need anything fancy and there's no requirements for any kind of precise control. Just make all connections to specific host(s) "slow", make them fast again. It's to be used in testing to see how web application would behave for a client on a slow connection.

For now what you guys discussing is a bit over my head, as I only have a basic understanding of network stack and absolutely no experience with linux networking (I had some experience on FreeBSD, but that was like 10 years ago).


Top
 Profile  
 
 Post subject: Re: Network emulator
PostPosted: Tue Apr 19, 2011 4:42 pm 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4296
Location: Sofia, Bulgaria
Nice one, AbraCadaver :)
Maybe Weirdan needs something less complex like in http://blog.stevedoria.net/20050906/ing ... nux-and-tc

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group