I’m developing an API and want to (of course) optimize performance in terms of number of concurrent users.
I have run some tests using Blitz (my app is on Appfog, PHP, 512MB, 1 instance) according to those tests my API can handle 11 concurrent users before response times get too high (>1000 ms).
For me it is surprisingly low. I can add more RAM and instances to improve the results but I suspect that my code could be smarter.
I did some tests, always with same hardware config. Result is number of concurrent users before exceeding 1000 ms in response time.
- Using my actual API (with db-queries) –> 11 users
- Using script that just outputs text (minimum processing) –> 40 users
- Using script with sleep(2) function to simulate long response time –> 52 users (before exceeding (2000 + 1000 ms)
- Using a memory intensive script (building data with for-loop): 95 users
I really don’t see any correlation in the results (each test has been run many times with similar results). The more processing for the script – the more concurrent users?
What is that affects the number concurrent users (apart from hardware config)?
Generally there are two aspects you should think of:
bottlenecks like database or external APIs. You are as slow as the slowest component
look for locks that turn your concurrent code into sequential. See: Amdahl’s law
The second point is related to the first one. Database or whatever you use in your code might be internally synchronized or might not cope well with concurrency.