
Remember I did a quick post on how to write a load-balancing script (or bandwidth throttling)?
Well, today I found another cool script for limiting bandwidth. I believe this one if more complicated but if you need it, it might be greatly helpful.
Here’s the code via Adamsinfo.com:
# Set some variables
#!/bin/bash
EXT_IFACE=”eth0″
INT_IFACE=”eth1″
TC=”tc”
UNITS=”kbit”
LINE=”10000″ #maximum ext link speed
LIMIT=”5000″ #maximum that we’ll allow
# Set some variables for individual “classes” that we’ll use to shape internal upload speed, i.e. shaping eth0
CLS1_RATE=”200″ # High Priority traffic class has 200kbit
CLS2_RATE=”300″ # Medium Priority class has 300kbit
CLS3_RATE=”4500″ # Bulk class has 4500kbit
# (We’ll set which ones can borrow from which later)
# Set some variables for individual “classes” that we’ll use to shape internal download speed, i.e. shaping eth1
INT_CLS1_RATE=”1000″ #Priority
INT_CLS2_RATE=”4000″ #Bulk
# Delete current qdiscs. i.e. clean up
${TC} qdisc del dev ${INT_IFACE} root
${TC} qdisc del dev ${EXT_IFACE} root
# Attach root qdiscs. We are using HTB here, and attaching this qdisc to both interfaces. We’ll label it “1:0″
${TC} qdisc add dev ${INT_IFACE} root handle 1:0 htb
${TC} qdisc add dev ${EXT_IFACE} root handle 1:0 htb
# Create root classes, with the maximum limits defined
# One for eth1
${TC} class add dev ${INT_IFACE} parent 1:0 classid 1:1 htb rate ${LIMIT}${UNITS} ceil ${LIMIT}${UNITS}
# One for eth0
${TC} class add dev ${EXT_IFACE} parent 1:0 classid 1:1 htb rate ${LIMIT}${UNITS} ceil ${LIMIT}${UNITS}
# Create child classes
# These are for our internal interface eth1
# Create a class labelled “1:2″ and give it the limit defined above
${TC} class add dev ${INT_IFACE} parent 1:1 classid 1:2 htb rate ${INT_CLS1_RATE}${UNITS} ceil ${LIMIT}${UNITS}
# Create a class labelled “1:3″ and give it the limit defined above
${TC} class add dev ${INT_IFACE} parent 1:1 classid 1:3 htb rate ${INT_CLS2_RATE}${UNITS} ceil ${INT_CLS2_RATE}${UNITS}
# EXT_IF (upload) now. We also set which classes can borrow and lend.
# This class is guaranteed 200kbit and can burst up to 5000kbit if available
${TC} class add dev ${EXT_IFACE} parent 1:1 classid 1:2 htb rate ${CLS1_RATE}${UNITS} ceil ${LIMIT}${UNITS}
# This class is guaranteed 300kbit and can burst up to 5000kbit-200kbit=4800kbit if available
${TC} class add dev ${EXT_IFACE} parent 1:1 classid 1:3 htb rate ${CLS2_RATE}${UNITS} ceil `echo ${LIMIT}-${CLS1_RATE}|bc`${UNITS}
# This class can is guaranteed 4500kbit and can’t burst past it (5000kbit-200kbit-300kbit=4500kbit).
# I.e. even if our bulk traffic goes crazy, the two classes above are still guaranteed availability.
${TC} class add dev ${EXT_IFACE} parent 1:1 classid 1:4 htb rate ${CLS3_RATE}${UNITS} ceil `echo ${LIMIT}-${CLS1_RATE}-${CLS2_RATE}|bc`${UNITS}
# Add pfifo. Read more about pfifo elsewhere, it’s outside the scope of this howto.
${TC} qdisc add dev ${INT_IFACE} parent 1:2 handle 12: pfifo limit 10
${TC} qdisc add dev ${INT_IFACE} parent 1:3 handle 13: pfifo limit 10
${TC} qdisc add dev ${EXT_IFACE} parent 1:2 handle 12: pfifo limit 10
${TC} qdisc add dev ${EXT_IFACE} parent 1:3 handle 13: pfifo limit 10
${TC} qdisc add dev ${EXT_IFACE} parent 1:4 handle 14: pfifo limit 10
### Done adding all the classes, now set up some rules! ###
# INT_IFACE
# Note the ‘dst’ direction. Traffic that goes OUT of our internal interface and to our servers is out server’s download speed, so SOME_IMPORTANT_IP is allocated to 1:2 class for download.
${TC} filter add dev ${INT_IFACE} parent 1:0 protocol ip prio 1 u32 match ip dst SOME_IMPORTANT_IP/32 flowid 1:2
${TC} filter add dev ${INT_IFACE} parent 1:0 protocol ip prio 1 u32 match ip dst SOME_OTHER_IMPORTANT_IP/32 flowid 1:2
#All other servers download speed goes to 1:3 - not as important as the above two
${TC} filter add dev ${INT_IFACE} parent 1:0 protocol ip prio 1 u32 match ip dst 0.0.0.0/0 flowid 1:3
# EXT_IFACE
# Prioritize DNS requests
${TC} filter add dev ${EXT_IFACE} parent 1:0 protocol ip prio 1 u32 match ip src IMPORTANT_IP/32 match ip sport 53 0xffff flowid 1:2
# SSH is important
${TC} filter add dev ${EXT_IFACE} parent 1:0 protocol ip prio 1 u32 match ip src IMPORTANT_IP/32 match ip sport 22 0xffff flowid 1:2
# Our exim SMTP server is important too
${TC} filter add dev ${EXT_IFACE} parent 1:0 protocol ip prio 1 u32 match ip src 217.10.156.197/32 match ip sport 25 0xffff flowid 1:3
# The bulk
${TC} filter add dev ${EXT_IFACE} parent 1:0 protocol ip prio 1 u32 match ip src 0.0.0.0/0 flowid 1:4
Brought to you by: Zedomax.com
Linux Server Hack - How to Limit Bandwidth with Linux, TC, and iproute2!
A+Featured Hacks, ceil, Computer, Cool, cool script, DoItYourself!, download speed, Educational, Hack, high priority, HOWTO, iface, internal interface, link speed, Linux, load balancing, medium priority, priority class, priority traffic, root classes, speed limit, tc units, traffic class, Ubuntu, upload speed, variables, WebBecome Skilled at more about hoists, their uses, types, operation and maintenance Conceivably the most daunting task for any apprentice gear head is the act of totally removing the engine. Removing nearly one thousand pounds of metal from a car seems to be an unworkable task, but it is one that every severe automobile hobbyist or proficient will have to do at one time or another. Providentially, there is a truly phenomenal class of devices known as overhead auto engine hoists that can make the process much easier and take care of all of the heavy lifting for you. This article provides a brief overview of how to you transparency auto engine hoists to remove your engine.
The first thing to do is make sure that the above your head auto engine hoists that you will be using will in shape your car. The legs should be long sufficient and low sufficient to fit under your automobile and provide the necessary clearance to attach the hoist to the engine. Unless you are an automobile proficient and plan to have to remove various engines over time, the most reasonably priced choice is to rent your above your head auto engine hoists. Many local rental companies rent out above your head auto engine hoists for twenty to fifty dollars per day.
Previous to attaching above your head auto engine hoists, you should remove all the perfunctory couplings, wire attachments, and perhaps the transmission. After this, it is as simple as attaching the hoist to your engine and using the hoist invigorating instrument to extract the engine. Good luck!
Become skilled at more about hoists, their uses, types, operation and maintenance. Take a look at http://www.hoistsindia.com
handling
Brakes,
Gearboxes,
Hoists,
exporter,
winches
power
material
limit
Switches,
Manufacturers and Suppliers of Electrical HoistsFORUM HOIST PVT. LTD. is manufacturers and suppliers of electrical hoists, EOT and Hot cranes, Material handling equipments, jib crane, Power Winches, Gantry or goliath cranes, Cranes for Foundry, Steel plants, Wire rope hoists, Single and double girder crane, Overhead bridge cranes from india.
limit
Brakes,
Gearboxes,
Rope,
Hoists,
rope
manufacturer
power
material
Switches,
If you want to limit your download and upload speeds use one of the following tools
1) Wondershaper
2) Trickle
Wondershaper
An easy to use traffic shaping script that provides these improvements:
* Low latency for interactive traffic (and pings) at all times
* Allow websurfing at reasonable speeds while uploading / downloading
* Make sure uploads don’t hurt downloads
* Make sure downloads don’t hurt uploads
It does this by:
* Limiting upload speed slightly, to eliminate queues
* Limiting download speed, while allowing bursts, to eliminate queues
* Interactive traffic skips the queue
* ACKs and tiny packets skip the queue
Configuring the wondershaper requires you to accurately and precisely determine your consistent upload and download speeds.
Install wondershaper in Ubuntu
sudo aptitude install wondershaper
This will complete the installation.
Using wondershaper
use ifconfig to determine which of your networkcards is the one that is connected to your modem (and thus the internet).
ifconfig
the networkcard that has your normal ip adress is the one (not 192.168.x.x)
Go to a speedtesting website and determine your average upload and download speed. Use these speeds to setup limitations.
sudo wondershaper eth1 downspeed upspeed
Note:- Speed should be in KB
Example
sudo wondershaper eth0 10000 280
download a big and uncompressable file while pinging to a fast and stable server on the internet or to your modem and adjust your downspeed until you are satisfied and do the same with uploading a big and uncompressable file.
When you are ready you can make these connection settings permanent by
sudo gedit /etc/network/interfaces
add these lines under eth1 if eth1 is your internetconnection. Change eth1,upspeed and downspeed to your settings.
up /sbin/wondershaper eth1 downspeed upspeed
down /sbin/wondershaper clear eth1
Useful Tip
How do I go about putting my settings back to default for eth1?
sudo wondershaper clear eth1
Problem
When you try to run similar to the following command
wondershaper eth3 4500 333
You might see the following error
What is “flowid”?
Illegal “police”
Solution
This is a bug in iproute, not in wondershaper. Debian has already fixed the problem
Replacing iproute2 with this http://mirror.aarnet.edu.au/debian/pool/main/i/iproute/iproute_20071016-3_i386.deb solved the problem
trickle
Trickle is a voluntary, cooperative bandwidth shaper. it works entirely in userland and is very easy to use.The most simple application is to limit the bandwidth usage of programs.
Install trickle in ubuntu
sudo aptitude install trickle
Stand alone mode
Trickle is easiest to use in stand-alone mode. Simply run trickle with a download and/or upload limit and a program you want to limit. For example:
sudo trickle -d 20 -u 20 wget http://www.google.com/bigfile
Daemon mode
In daemon mode, trickle can limit a group of programs to a fixed limit of bandwidth. To start the daemon, run the trickled command:
sudo trickled -d 20 -u 20
This will start the trickle daemon that will limit the total bandwidth available to all programs run via trickle to 20 K/s both up and down. So if you run a single program via trickle, it can consume 20 K/s. Two programs can each consume 10 K/s, etc.
Ubuntu: Ubuntu Geek - Ubuntu Tutorials,Howto's,Tips and Tricks
Dear reader, this is a challenge. How’s your MySQL prowess? You know about LIMIT: it cuts off the results at the specified number.
mysql>s; select actor_id from sakila.actor where actor_id % 5 = 0 limit 5; +----------+ | actor_id | +----------+ | 5 | | 10 | | 15 | | 20 | | 25 | +----------+ 5 rows in set (0.00 sec)
But that query actually accessed 25 rows. What if I want to say “return up to 5 rows, but don’t read any more than 20 rows to find them?”
Right now I’ve got the following:
mysql> select actor_id, @rows
-> from actor, (select @rows := 0) as x where
-> ((@rows := @rows + 1) <= 20)
-> and actor_id % 5 = 0
-> limit 5;
+----------+-------+
| actor_id | @rows |
+----------+-------+
| 5 | 5 |
| 10 | 10 |
| 15 | 15 |
| 20 | 20 |
+----------+-------+
4 rows in set (0.00 sec)
The derived table subquery x is only there to initialize the user variable at the beginning of the query.
This appears to work, but it doesn’t. If you profile this with SHOW STATUS, you see that it reads every row in the table (Handler_read_next = 200). This is actually worse, not better, than just LIMIT.
Any ideas?
I’ve got a few. But I don’t like them for various reasons. Extra props for really efficient solutions that don’t involve subqueries (so it’ll work on pre-4.0) or things that add extra overhead (subqueries, for example). I guess you probably see the direction I want to go with this — I don’t want to use subqueries.
limit, mysql, user defined variables