There is no simple answer, and some research will be necessary.
I have started down this path, but not yet had the time to fully implement ..
Start by reading:
Complex Traffic Shaping/Control
OpenWRT > Linux Packet Scheduling
OpenWRT > Bandwidth Monitoring
OpenWRT > Network Traffic Control
supermind.org > Thoughts on Lucene, Solr, crawling and vertical search