How is it possible to balance load through one proxy? - proxy

After reading about proxies, reverse proxies and load balancing I am left with a question: how is it possible to balance load (via a proxy) if all traffic still has to go through one point - the proxy?
What I understood is the concept that a proxy can distribute requests to different servers. For a client it seems like all the responses come from the proxy. But if all the responses still have to go through the proxy in the end, how does this help so much? The proxy needs to have the capacity off all the servers behind it combined! I am probably missing something..
One of the discussions I am referring to is: Difference between proxy server and reverse proxy server

Well, the load-balancing proxy only performs very simple tasks like rolling a virtual dice to pick one of the servers behind it. These tasks should take a negligible time to complete so that the throughput of the proxy was as high as possible.
On the other hand the servers that handle actual users' requests perform many complex tasks (connect to and query the database, parse data, prepare response) which take longer time, therefore their load is higher and the throughput is significantly lower.
Of course, the load-balancing isn't as simple as that, you can't just pick random numbers as you need to deal with back-end servers' downtimes for example, the point is that the tasks on a load balancer should take much much shorter time than tasks on the servers behind. :-)

Related

How to prevent automated request to the server?

How to prevent automated request? This is not a duplicate question. The existing answers are not compromised.
What if an attacker using a program which make 1 Million requests per minute? Or the program may use various proxy or vpn and can request millions of request to the server. The server will slow down due to the heavy load. How can this be prevented?
Can IP Tables handle millions of request per second?
You cannot prevent someone from attacking you. You simply have to deal with it.
You either spin up enough server capacity to handle the brute force attack, or if you don't want your servers to have to handle the load then you have to deal with the attack closer to the edge of the network instead.
Have a look at the following:
https://www.cloudflare.com/learning/ddos/ddos-mitigation/
https://www.cloudflare.com/learning/ddos/glossary/ddos-blackhole-routing/
https://en.wikipedia.org/wiki/DDoS_mitigation
https://en.wikipedia.org/wiki/Denial-of-service_attack

JMeter for Clustered Scenarios

I have to perform load testing on a load balanced (clustered) system composed of three servers.
Is it a good practice to test via JMeter each server ? Or maybe it would be better testing the whole cluster calling the load balancer dedicated endpoint ?
Thanks !
Well behaved load test needs to mimic real life application usage as close as possible therefore if the load balancer acts as a single entry point to the system - JMeter needs to hit this endpoint only so the whole system will be like a "black box".
With regards to distributed systems testing best practices you can also consider the following couple of areas:
Load balancers may route requests depending on the origin so it might be a good idea to implement IP Spoofing so each JMeter virtual user could have its own source IP address.
Load Balancer endpoint host(s) may have multiple IP addresses so consider DNS Cache Manager to your Test Plan so each JMeter virtual user could resolve endpoint address on its own as due to caching of DNS calls on OS or JVM level your test can hit one node only while others will be idle.
Testing the whole system is always better. I mean you can find out problem with the load balancing management. It's always better to be in the same condition as the production environment.
After your assessment of the first test. You can regulate and find out that maybe one server is slowing down the chain with another test.
The answer is both (and you should find more cases.), You need to test your system on load as much as close to real environment to know its capabillities.
But also ,for example, when upgrading a version, sometimes only a few or even one server remain online and you need to know what load it can sustain .

How to load test an Apache HTTP Load balanced servers

Apache Jmeter allows us to hit the server with simultaneous connections. On, the other hand I have 4 webservers - one acting as a load balancer and other 3 acting as a application server. So, i want to load test these servers at once to check its performance. Is there a way to load test a load balancer. Any tools that will be helpful to carry out. I will edit this question further with more information. For time being could someone point out a starting point.
Ramp your normal app-test as usual (through the load balancer).
Eventually, you'll get high response times. If you see your application servers are running fine, then it's (probably*) your load balancer that's the issue. If the application servers are falling over, then you don't need to worry about the performance of your load balancer- it's not the bottleneck.
*obviously, there could be other problems, eg, simple network throughput. But you should be able to tell what's going on with some simple monitoring.
Yes you can make a load test on your load balancer Apache server.
Target your http requests to the load balancer apache server. I'm assuming the LB will distribute the load evenly through the 3 backend servers. After the test you evaluate the response times. Are they good? Great.
If they aren't good you can make a second test targeting the 3 backend servers (don't let the requests pass by the LB). If the response times are better now then you know your LB is the problem, otherwise you may need to add more backend servers or optimize your applications (i guess this is what you'll do).

How is Ruby Mechanize fast after first get request?

I recently programmed a scraper with Ruby's Mechanize gem for the first time. It had to hit the server (some 'xyz.com/a/number') where the number will be generated by the script. Like 'xyz.com/a/2' and 'xyz.com/a/3'.
It turned out that the first request took a lot of time -- around 1.5s on a 512kbps connection. But the next request was done in 0.3ms.
How could it be done so fast? Did it have some caching mechanism?
There are lots of possible sources for a speed change between requests. A few that immediately spring to mind:
DNS lookup cached on your client. The first call must convert "xyz.com" to "123.45.67.89", involving a DNS lookup which may be slow.
HTTP keep-alive. There is an initial conversation between client and server to start an HTTP data transfer. On a high-latency connection you will notice this. If server and client both respect HTTP keep-alive, then a connection can be established once to cover multiple requests.
Server-side caching. The server you are scraping uses caching to speed up multiple similar requests. It might be caching data to do with your current session for example, or even just not fully compiled the script yet until your first request.
Server-side VM resource allocation. If the server is sharing space on a virtualised system, and does not serve high traffic, then it may become more responsive after the first request ensures everything is in RAM and has CPU allocated.
This is by no means exhaustive. The above examples are just to illustrate that this behaviour - initial slow response, followed by faster ones - is very common for web services, and has multiple causes.

Measure performance of a Web Server

Which tools can be used to measure performance of a webserver?
To test a webserver, you can use Apache Jmeter.
To see where is the bottleneck you have to flood your server application.
ApacheBench (ab) can do this. Here is a tool to get the server HTTP response code (ab) just says there is an HTTP error, and to automate test runs:
dsec.com/source/ab.c.txt
This program also gives useful tips about how to configure Linux and Windows (TCP/IP system options) to get the best possible performances.
It always depends on the setup.
Depending on the application there can be different bottlenecks.
Sometimes its the CPU, sometimtes the database connections, sometimes the sockets, sometimes the hard disc etc...
Most common practice is to use siege (simple command line tool) and increase the concurrent connections and see how many transactions per second go through.
It will increase per connection until an optimum is reached, then it will slowly decrase.
You can produce a set of urls that are randomly accessed, maby biased and/or send random data, request random ids etc to simulate more "real" clients.
Completely depends on your application whether this is relevant.

Resources