How to do load testing of a PHP website from both ends - php

We have developed a website in PHP for small services. Before production, we have to do performance and load testing from server side (that is Apache) and from client side.
From Client side, I want to know what is the average response time overall and for each object etc. For back-end side (apache web-server), I want to know how many request (clients) it can handle before its performance start to degrade.
Is there any open source tool as we are on Linux platform, for this purpose. Or is there any website(s) available (freely) that can do all of these testing.
We are more concerned about load testing where we want to request to our website from 1000 users at same time (for example) and want want to check client and server side different performance metrics.

Since you are running Apache, you could use ab to stress test the server side of your application.
Apache HTTP server benchmarking tool
ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.
Let's look an example:
ab -k -c 100 -n 10000 example.com/
By issuing the command above, you will be hitting http://example.com/ with 100 simultaneous connections until 10 thousand requests are met.
Here you have another tutorial how to use ab
Stress-Test Your PHP App With ApacheBench
Some other helpful tools are:
Apache JMeter
httperf
If you want a more in-detail view of your php objects and all that stuff I would suggest you to check blackfire. As I know they offer a free version for local testing and only one application. But I don't think that you need this one for now.
For your front end I would suggest you a set of tools that help you to see how your page performs in different devices:
Lighthouse
PageSpeed Insights
Pingdom

You can find the list of free and open source load testing tools at http://www.opensourcetesting.org/category/testing-tools-overview/performance/?menu-page=overview, currently there are 59 (and counting).
The narrowed down list of the most advanced cross-platform open source load testing tools can be found in Open Source Load Testing Tools: Which One Should You Use? article, it also has feature comparison matrix, sample scripts and reports.
Given your application is in PHP my expectation is that you don't have a lot of expertise in other programming languages so the most obvious choices would be in:
Tsung where you can create your load test using XML files
Apache JMeter which also stores test scripts in XML format, however you can use GUI for test logic creation which might be faster and easier.
Both tools provide record-and-replay functionality so you will be able to build your test scenario skeleton using browser.

Related

PHP web application performance measurement tool

Need some web application performance measurement tool.. Can you guys suggest me some better ones..
Purpose: First, app is built on Lumen and Dashboard is built upon Laravel. So why I want something is to measure all requests performance to app and then I can to note down results of each and every requests' time consumption, based on that app can be optimized in better way
I did some google found JMeter is most of the people's choice, as its from apache and does the job but it looks lil complex, also found https://locust.io/ interesting, that I'm gonna give it a try
But I would more like to get experts suggestions or advice on this
Thanks!
There is quite a number of free load testing tools and the absolute majority of them supports HTTP protocol so feel free to choose any.
Regarding JMeter and Locust, if you can develop code in Python - go for Locust as you won't have to learn new things and will be able to start right away.
If your Python programming skills are not that good I would recommend reconsidering JMeter as it is not that complex at all:
JMeter is GUI based so you can create your test using mouse.
JMeter comes with HTTP(S) Test Script Recorder so you will be able to create test plan "skeleton" in few minutes using your favourite browser
JMeter supports way more protocols, i.e. you can load test databases via JDBC, mail servers via SMTP/IMAP/POP, MQ servers via JMS, etc. while Locust is more HTTP-oriented, if you need more - you have to code
If above points sound promising check out JMeter Academy - the fastest and the most efficient way of ramping up on JMeter as of now.
XHProf you can use it check every function exec time! it can show you with a web gui!
https://pecl.php.net/package/xhprof
XHProf is a function-level hierarchical profiler for PHP and has a simple HTML based navigational interface. The raw data collection component is implemented in C (as a PHP extension). The reporting/UI layer is all in PHP. It is capable of reporting function-level inclusive and exclusive wall times, memory usage, CPU times and number of calls for each function. Additionally, it supports ability to compare two runs (hierarchical DIFF reports), or aggregate results from multiple runs.

Best strategy for sending commands to Arduino: Send UDP packet OR get configuration from a dynamic web page?

I would like to send some configuration parameters to an Arduino Ethernet board, and I came up with two potential solutions. I would be grateful if you could give your thoughts on using either one of those.
The first (obvious) option is to send a UDP command containing the configuration to the Arduino. This, however, requires a reconfiguration for most routers to enable port-forwarding or disabling the firewall.
So my second option is to get the configuration by accessing a web page from Ardino which will contain all the required information (this will be updated using a PHP script on the server). This page will be checked every minute or so and update the configuration if a new one is found. The requirement for communication every minute is not a problem since there is also traffic on the other direction (my Arduino logs temperatures in a web site).
Which method is the best and are there any pitfalls I should avoid?
I recently finished my WebPlayer.ino where it got pushed commands over the web as to what files to play from the SD card to the MP3 chip, along with volume and speed control. Similar to your goals, I had to pull a bunch of pieces from all over into it. So it may be a nice example of how to parse the web commands.
In either UDP or TCP and using the native Ethernet library, one needs to read the character string from the ethernet.client. Regardless of direction and TCP vs UDP. The one advantage I have seen with UDP is that there are some examples using the "String" type to get the data as a whole, but that is insignificant. I would stick with TCP, look at my example as how to read the web servers requests.
Additionally, the Webduino library is a wrapper that simplifies getting the commands. It provides JSON and the like. So that would be very useful for what your doing. But it uses a huge chunk of RAM and ROM. Hence my project did not use it.

How to test speed between web servers

my web pages are hosted on company A. I have moved to company B. My account at company A will be active for a few days. How can I test and therefore compare the speed of those two?
Thank you.
I am using webserver through cPanel, so I guess a PHP script or something would be great.
you can use JMeter. easy to use. you can have some regression test for various scenarious which you actually want to do. ie: see how web servers perform under different loads and compare the companies.
Or you can use Pingdom tools even firebug will give you how long each web server takes to load the same resources.
Note that, your speed tet mostly will depend on latency, ie: your distance to one webserver vs the other one. Plus how many applications are running in one server on company A vs the other server on Company B if that s shared hosting.
As mentioned before:
See the 'hops' to your server with traceroute or tracert
There are some great server tools like Nagios which will give you a LOT of info about the server & network.
If they are your own servers you could even try a DDOS attack on them to see how much stress they can take.
You could simply run a php script with 50k loop iterations of different actions like file I/O, database queries etc etc to see how the 2 servers compare in milliseconds wit the different actions.
You could setup a jsperf script to run a few hundred ajax requests to see how each perform.
It really depends on what you suspect to be the problem? There are tools & methods to test each thing (network, hardware storage, cpu etc)
If you are using apache have a look at ab the benchmarking tool.
You can also do tracert or traceroute depending on the OS you're using to test the actual connection speed.
For the server speed itself, you can monitor your scripts directly inside of them (start a timer at the beginning of the load and display it when the page loading ends).
There are several things to consider on a "server speed", not only the horsepower :)

Scaling for TYPO3 site

I'm asked by a customer to deliver a TYPO3 based website with the following parameters:
- small amount of content (about 50 pages)
- very little change frequency
- average availabilty about 95%/day
- 20% of pages are restricted, only available after login
- No requirements for fancy typo3 extensions or something else (only Typo3 core)
- Medium sized pages
- Only limited digital assets (images etc.) included
I have the requirements to build an infrastructure to serve up to 1000 concurrent users. With the assumption of having an average think time of 30 sec. this would result in 33 Requests per second.
How could an infrastructure look like?
I know that system scaling is a highly individual task depending on the implementation of the system and needs testing, but I need a first indication where to start (single server, separating components to different servers,...).
Any idea?
Easier solution is EXT:nc_staticfilecache. This saves the static pages as HTML and your web server automatically delivers them through rewrite rules (in case of Apache through mod_rewrite). This works very well for static content and should already enable you to do >100req/s.
The even more fancier way is to use Varnish Cache. Varnish is a reverse proxy server that holds your web site content in memory and can run on a dedicated host. If you configure it correctly (send correct cache headers!), it serves you line speed (some million req/s). There is also a TYPO3 Extension moc_varnish, which e.g. purges the varnish cache, when a page is changed in TYPO3. Also support for edge side includes exists to e.g. only retrieve the user-specific data from TYPO3 and use the static parts of a page from varnish cache (everything except the "Welcome user Foo Bar".. ;)).
As mentioned: Don't forget to configure correct cache headers (Expires etc) for your assets. This already removes some load from your web server.
It's quite possible, already made something like this. You need at least one dedicated server with >= 8GB of RAM.
If we are speaking about infrastructure, the minimal combination is :
nginx/Varnish for front/load balancing
Apache HTTP Server
MySQL could be on standalone server, could be clustered
Performance optimization is very important in such cases.
Some links for further reading :
http://techblog.evo.pl/en/how-to-boost-speed-up-your-typo3-website-with-nginx/
http://www.fabrizio-branca.de/nginx-varnish-apache-magento-typo3.html
http://wiki.typo3.org/Performance_tuning
I'd put this on a single dedicated server (or well specified VPS) but maybe keep all the static assets on a third party CDN so you can focus on the dynamic stuff. I don't know Typo3 but can't see any reason why you couldn't have your db on the same server for this level of usage - there is sure to be caching options of various kinds. Or perhaps consider a cloud server, so if you need more oomph, just add more resources.
Edit: I don't think it is a good idea to build a scalable architecture just yet e.g. proxy servers and all that stuff. If it is slow and you find you really can't cope with one machine, scale up at that point. I'm of the view you can make do with a much simpler architecture given your expected traffic.
I would look into a virtual sserver or a ksm and a good mysql and php configuration. When I have a ksm I would tweak Linux and use iptables for traffic shaping. A dedicated root server would be nice but it's expensive. Then I would think about using a nginx or lighttpd webserver with eaccellerator and memcache. If that doesn't help I would try to compile php and mysql with optimize flags or I would try to compile it with the Intel C Compiler. ICC can optimize C code better then gcc. If the server has many ram I would use ramdisk.

How to implement chat using jQuery, PHP, and MySQL?

I have made a chat script using php, mysql and jquery. It uses json to get data from the server. It makes fixed interval requests to the server with the lastly fetched message id to get new messages from the server. But when multiple users will be chatting then thousands and crores of requests will be made to the server within an hour and the hosting people will block it for sure.
Th gmail chat uses socket I think. Because it does not sends fixed interval requests for sure. Could any one of you please give me some sample code or some direction to solve this issue.
Please I need help desperately.
Many thanks in advance. My respect and regards for all.
If the host you are using would "block it for sure" if it's making that many requests, then you may want to consider getting a different host or upgrading your hosting package before worrying about your code. Check out how Facebook implements their chat:
The method we chose to get text from
one user to another involves loading
an iframe on each Facebook page, and
having that iframe's Javascript make
an HTTP GET request over a persistent
connection that doesn't return until
the server has data for the client.
The request gets reestablished if it's
interrupted or times out. This isn't
by any means a new technique: it's a
variation of Comet, specifically XHR
long polling, and/or BOSH.
You may find it useful to see an example of 'comet' technology in action using Prototype's comet daemon and a jetty webserver. The example code for within the jetty download has an example application for chat.
I recently installed jetty myself so you might find a log of my installation commands useful:
Getting started trying to run a comet service
Download Maven from http://maven.apache.org/
Install Maven using http://maven.apache.org/download.html#Installation
I did the following commands
Extracted to /home/sdwyer/apache-maven-2.0.9
> sdwyer#pluto:~/apache-maven-2.0.9$ export M2_HOME=/home/sdwyer/apache-maven-2.0.9
> sdwyer#pluto:~/apache-maven-2.0.9$ export M2=$M2_HOME/bin
> sdwyer#pluto:~/apache-maven-2.0.9$ export PATH=$M2:$PATH.
> sdwyer#pluto:~/apache-maven-2.0.9$ mvn --version
-bash: /home/sdwyer/apache-maven-2.0.9/bin/mvn: Permission denied
> sdwyer#pluto:~/apache-maven-2.0.9$ cd bin
> sdwyer#pluto:~/apache-maven-2.0.9/bin$ ls
m2 m2.bat m2.conf mvn mvn.bat mvnDebug mvnDebug.bat
> sdwyer#pluto:~/apache-maven-2.0.9/bin$ chmod +x mvn
> sdwyer#pluto:~/apache-maven-2.0.9/bin$ mvn –version
Maven version: 2.0.9
Java version: 1.5.0_08
OS name: “linux” version: “2.6.18-4-686″ arch: “i386″ Family: “unix”
sdwyer#pluto:~/apache-maven-2.0.9/bin$
Download the jetty server from http://www.mortbay.org/jetty/
Extract to /home/sdwyer/jetty-6.1.3
> sdwyer#pluto:~$ cd jetty-6.1.3//examples/cometd-demo
> mvn jetty:run
A whole stack of downloads run
Once it’s completed open a browser and point it to:
http://localhost:8080 and test the demos.
The code for the example demos can be found in the directory:
jetty-6.1.3/examples/cometd-demo/src/main/webapp/examples
Right or wrong, a hosting company might get cranky for a couple reasons:
1) Odds are good they are using apache prefork. Each chat request is probably gonna be a new connection and thus hog up a single apache process. Each apache process eats anywhere from 1mb of memory to 100mb of memory.
2) If they maintain the database server and you, the client, suck at database programming, you can hammer their database. "Suck" means anything from "no proper indexing" to "makes a bazillion tiny queries instead of nice fat ones".
As has been suggested above, make sure your code uses persistent connections. Also:
1) Implement a back-off algorithm on the client. Poll the server once a second during activity, then back off to five seconds, then ten, twenty, etc... That way you dont hammer the server when there is no activity.
2) Multiple tabs will kill you. User opens 10 tabs and they all have your chat widget polling the server once a second? Bad news. Even if your host doesn't get pissed, your performance will degrade.
If this thing gets huge, design your system in a way that you can run the chat-server bits independently from the rest of your web application. In otherwords, the clients would be making a request to "chat.yourwebapp.com", which in turn is running on something like lighttpd.
try socket in javascript
http://code.google.com/p/jsocket/
Why would the host block that? Your making a standard http request for a page, if your host doesn't allow that then it's time to switch.
As for using sockets, there is no native ability to connect to a socket via javascript, although I believe JSocket is a lib that allows you to bridge a socket through an embedded flash which is actually connected to your server. Haven't looked for a jquery plugin that does this, might be one.
Your server side code would also change drastically (persistent vs polling is very different) so you'd have your work cut out for you.
I recommend just doing what you are doing and upgrade your host if it can't handle it. Unless your going to have a huge number of users on at a time? A caching system so your not hitting the db on every single request can probably speed things up if it gets that busy.
You think about embedding a small Flash movie in the page and then use sockets to handle the communication with server. This will take a lot of the load from the server and would make much more easier to keep everything in sync. The UI could still make with JavaScript.
It you will stay with your JavaScript solution then silently ignore my answer :-)

Categories