Jump to content

LoadTesting WebServer


Recommended Posts

Hi,

Presently I am working on a script to load test a webservice created using Node.JS . However, I am unable to speed up the processing. The following code is a work-around , but I would like to increase its over-all performance. 

Hints , appreciated.

Since,

1: InetGet provides a non-blocking method / ASYNC , it is being used .

2: Writing the results to the file using Little-Endian - as it is the fastest and requires least amount of code conversion.

#include <Array.au3>

Global Const $HTTPREQUEST_PROXYSETTING_DIRECT = 1
Global Const $HTTP_STATUS_OK = 200
Global $URL
Global $count, $SecondCount
Global $MaintainCount[100]
Global $sFileData, $hFile

FileDelete('consolidated.txt')
$hFile = FileOpen('consolidated.txt', 34)
For $i = 0 To 99 Step 1
    $MaintainCount[$i] = 0
Next
AdlibRegister('WriteToFile', 2000)
;~ AdlibRegister('Chk_Array', 150)
$URL = 'http://192.168.1.14/getdata/default.aspx?adrm=TINGTONG&adrh=SomeDynamicValue' 
;SomeDynamicValue is read from a txt file and that logic is not included. Presently using a static value.
$count = 0
$SecondCount = 0
$begin = TimerInit()
While 1
    If $MaintainCount[$count] <> 0 Then
        If InetGetInfo($MaintainCount[$count], 2) Then
;~          AdlibUnRegister('Chk_Array')
            InetClose($MaintainCount[$count])
            $fileContents = FileRead(@ScriptDir & '\1\' & $count & '.txt')
;           FileDelete(@ScriptDir & '\1\' & $count & '.txt')
            $sFileData &= @HOUR & @MIN & @SEC & '|' & $fileContents & @CR
            $MaintainCount[$count] = 0
            Call('geturl', $count)
            ConsoleWrite('IF    : ' & $count & ' : ' & $SecondCount & @CRLF)
;~          AdlibRegister('Chk_Array', 150)
        EndIf
    Else
        Call('geturl', $count)
        ConsoleWrite('Else  : ' & $count & ' : ' & $SecondCount & @CRLF)
    EndIf
    $count += 1
    If $count = 100 Then
        $count = 0
        Chk_Array()
    EndIf
    If $SecondCount == 1000 Then ExitLoop
;~  Sleep(10)
WEnd
AdlibUnRegister('WriteToFile')

ConsoleWrite('Completed: ' & TimerDiff($begin) / 1000 & @CRLF)
Local $FinalCounter = 0
While 1
    For $i = 0 To 99 Step 1
        If $MaintainCount[$i] <> 0 Then
            If InetGetInfo($MaintainCount[$i], 2) Then
                InetClose($MaintainCount[$i])
                $fileContents = FileRead(@ScriptDir & '\1\' & $i & '.txt')
;               FileDelete(@ScriptDir & '\1\' & $i & '.txt')
                $sFileData &= @HOUR & @MIN & @SEC & '|' & $fileContents & @CR
                $MaintainCount[$i] = 0
                ConsoleWrite('Final : ' & $i & ' : ' & $FinalCounter & @CRLF)
                $FinalCounter += 1
            EndIf
        EndIf
    Next
    If $FinalCounter == 99 Then
        FileWrite($hFile, $sFileData)
        ExitLoop
    EndIf
WEnd
ConsoleWrite('Finally Completed: ' & TimerDiff($begin) / 1000 & @CRLF)
Func Chk_Array()
;~  AdlibUnRegister('Chk_Array')
    For $i = 0 To 99 Step 1
        If $MaintainCount[$i] <> 0 Then
            If InetGetInfo($MaintainCount[$i], 2) Then
                InetClose($MaintainCount[$i])
                $fileContents = FileRead(@ScriptDir & '\1\' & $i & '.txt')
                $sFileData &= @HOUR & @MIN & @SEC & '|' & $fileContents & @CR
                $MaintainCount[$i] = 0
                ConsoleWrite('Adlib : ' & $i & ' : ' & $SecondCount & @CRLF)
            EndIf
        EndIf
    Next
;~  AdlibRegister('Chk_Array', 150)
EndFunc   ;==>Chk_Array

Func WriteToFile()
    If StringInStr($sFileData, @CR, 2, 100) <> 0 Then
        FileWrite($hFile, $sFileData)
        $sFileData = ''
    EndIf
EndFunc   ;==>WriteToFile

Func geturl($counter)
    $sdata = InetGet($URL, @ScriptDir & '\1\' & $counter & '.txt', 8, 1)
    $MaintainCount[$counter] = $sdata
    $SecondCount += 1
EndFunc   ;==>geturl

Is there any alternative for InetGet ? So that instead of writing it into the file, it will store the results into the buffer , that way , Disk I/O wont play a spoilsport ?

A bit of the Past : The initial script completed 4 requests per second, now its around 8 requests per second.

Regards

[Final Update]

Since there has been no reply to this thread, I presume this to be the present final solution.

Edited by DeltaRocked
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...