Optimizing network throughput and latency