Loading images via http vs bytearray

Load images via http or using bytearray? which the best way?
It was long time since I wanted to perform this kind of test, but for different reasons I never had the time to do that.
Some days ago fnally I’ve found the time thanks to a project I’m involved into.
The problem.
A local webserver running flash remoting via pyamf and a flash standalone application which need to load tons of images locally.
I’ve noticed that sending from amf the list of images path to be loaded required too much time (for me), even if they’re loaded locally.
Because of this I decided to try a first benchmark loading a single image using the standard way: send the link from amf and then load it using the classic actionscript Loader.
The second test was to send directly from amf the image stream using a ByteArray and then loading the image in flash using the Loader.loadBytes method.
In this way I’ve noticed that the second task requires less time than the first one (more or less 40% less).
Unfortunately our application needs to load something like 50/100 images at the same time.
For this reason I did a new test loading 22 images of 500Kb each (10Mb total). For a better result I decided to use both pyamf and blazeds, to be sure there’s no problems in the language used. Moreover I used charles to register the benchmark of these tasks.
The results were unexpected!
First test: passing form amf the list of url images and loading using the standard flash Loader to load all of them simultaneously.
The time elapsed from the flash method call to the results was about 40 milliseconds. Then from the remote method result to the completion of all Loader about 1400 milliseconds.

Second test: passing from amf an arraycollection of bytearrays containing all the images stream to be loaded directly in flash.
The time elapsed form the flash method call to its result: about 2900 milliseconds. Time elapsed from the result to the all Loaders completion: about 900 milliseconds.
This results were unexpected for me, expecially because both with blazeds and pyamf sending 10Mb of bytearrays tooks something like 3 seconds!
At a first impression I thought the problem was the time for java and python to create the amf stream data, but after a deeper test I discovered that they took more or less 30ms to generate the amf stream and the real bottleneck was the http transfer of this stream data.

I’m attaching here the screenshots of the charles sessions using blazeds:

Here you can find also the complete benchmark result using flash trace within the swf:
————————–
BlazeDS
————————–
Method Elapsed-Time
call.test1 0
result.test1 40
complete.test1 1453
TEST1 TOTAL TIME: 1493
call.test2 0
result.test2 2919
complete.test2 921
TEST2 TOTAL TIME: 3840
————————–
PyAMF
————————–
call.test1 0
result.test1 32
complete.test1 953
TEST1 TOTAL TIME: 1049
call.test2 0
result.test2 2805
complete.test2 908
TEST2 TOTAL TIME: 4763
Here you can see the source code used for these tests:
In conclusion. While sending 10Mb of data ( for example bytearray ) requires more or less 2.5 seconds using flash remoting as single requests ( because the transfer rate of the webserver it’s about 4Mb/sec ), loading simultaneusly 20 images from the webserver, using http, tooks 1 second.
This is because the webserver for each requests opens a different thread to dispatch the request and in this way the total time to perform this task is less than the first method.

Stress test with apache ab

I didn’t know at all apache ab sine yesterday when a guy who is working with us told me about this tool included in apache distribution.
Then I used with my site on localhost using this command line:

ab -n 9000 -c 900 localhost:8080/index.php

I got this results:

 Completed 900 requests Completed 1800 requests Completed 2700 requests Completed 3600 requests Completed 4500 requests Completed 5400 requests Completed 6300 requests Completed 7200 requests Completed 8100 requests Finished 9000 requests

 Server Software:        Apache/2.0.55 Server Hostname:        localhost Server Port:            8080

 Document Path:          /index.php Document Length:        37949 bytes

 Concurrency Level:      10 Time taken for tests:   407.890625 seconds Complete requests:      9000 Failed requests:        25    (Connect: 0, Length: 25, Exceptions: 0) Write errors:           0 Total transferred:      342093375 bytes HTML transferred:       340598850 bytes Requests per second:    22.06 [#/sec] (mean) Time per request:       453.212 [ms] (mean) Time per request:       45.321 [ms] (mean, across all concurrent requests) Transfer rate:          819.03 [Kbytes/sec] received

 Connection Times (ms)               min  mean[+/-sd] median   max Connect:        0    0   2.7      0      78 Processing:   140  452 217.8    359    2265 Waiting:       31  402 194.0    328    2218 Total:        140  452 218.0    359    2265

 Percentage of the requests served within a certain time (ms)   50%    359   66%    390   75%    421   80%    515   90%    750   95%    968   98%   1156   99%   1281  100%   2265 (longest request)

Mmhh.. 25 errors with 9000 connection and 900 concurrency level?
I must admit I never used stress test tool at all by my own, just one time I see it used when working for a big java based project.
Do you use some kind of benchmarking tool?