Socket slowing down

newprog

New Member
I have a problem that has shown up whilst load testing sockets in that the speed of the socket response becomes slower after each request.

First time I've used sockets so hopefully the technique is OK.:)

I am on 10.2a, appserver, unix server.


Client side code. (client.p)
Code:
DEFINE VARIABLE mytext      AS CHARACTER  NO-UNDO.
DEFINE VARIABLE i           AS INTEGER    NO-UNDO.
DEFINE VARIABLE mysocket    AS HANDLE     NO-UNDO.
DEFINE VARIABLE mymemptr    AS MEMPTR     NO-UNDO.
DEFINE VARIABLE ret         AS LOGICAL    NO-UNDO.
DEFINE VARIABLE iMemmorySize AS INTEGER   NO-UNDO INITIAL 15.
 
CREATE SOCKET mysocket.
ret = mysocket:CONNECT("-H dev -S 6666"). 
IF NOT ret THEN DO: 
    MESSAGE "Unable to connect to server" VIEW-AS ALERT-BOX.
END.
/* Build a message to send */
mytext = "Hello". 
SET-SIZE(mymemptr) = iMemmorySize.
SET-BYTE-ORDER(mymemptr) = BIG-ENDIAN.
PUT-STRING(mymemptr, 1, iMemmorySize) = mytext.
mysocket:WRITE(mymemptr, 1, GET-SIZE(mymemptr)). 
SET-SIZE(mymemptr) = 0.
mytext = "Goodbye". 
SET-SIZE(mymemptr) = iMemmorySize.
SET-BYTE-ORDER(mymemptr) = BIG-ENDIAN.
PUT-STRING(mymemptr, 1, iMemmorySize) = mytext.
mysocket:WRITE(mymemptr, 1, GET-SIZE(mymemptr)). 
SET-SIZE(mymemptr) = 0.
 
SET-SIZE(mymemptr) = iMemmorySize.
SET-BYTE-ORDER(mymemptr) = BIG-ENDIAN.
mysocket:READ(mymemptr,1,iMemmorySize).
mytext = GET-STRING(mymemptr,1,iMemmorySize).
MESSAGE "The message is: " + TRIM(mytext) VIEW-AS ALERT-BOX. 
SET-SIZE(mymemptr) = 0.
mysocket:DISCONNECT(). /* Point 5 */
DELETE PROCEDURE THIS-PROCEDURE.
DELETE OBJECT mysocket.


Server side code. (server.p)
Code:
CREATE SERVER-SOCKET mysocket NO-ERROR. 
ret = mysocket:ENABLE-CONNECTIONS("-S 6666"). 
 
mysocket:SET-CONNECT-PROCEDURE("ConnectionProcedure"). 
WAIT-FOR "CLOSE" OF THIS-PROCEDURE.
DELETE OBJECT mysocket.
 
 
PROCEDURE ConnectionProcedure:
    DEFINE INPUT PARAM clienthandle AS HANDLE. 
 
    clienthandle:SET-READ-RESPONSE-PROCEDURE("readProcedure"). 
 
END PROCEDURE.
 
 
PROCEDURE readProcedure:
 
    /* Command / Instruction */
    SET-SIZE(mymemptr) = iMemmorySize. 
    SET-BYTE-ORDER(mymemptr) = BIG-ENDIAN. 
    SELF:READ(mymemptr,1,iMemmorySize). 
    gcCommandText = GET-STRING(mymemptr,1,iMemmorySize).
    SET-SIZE(mymemptr) = 0.
 
    /* Find Data */
    SET-SIZE(mymemptr) = iMemmorySize. 
    SET-BYTE-ORDER(mymemptr) = BIG-ENDIAN. 
    SELF:READ(mymemptr,1,iMemmorySize). 
    gcDataText = GET-STRING(mymemptr,1,iMemmorySize).
    SET-SIZE(mymemptr) = 0.
 
    ASSIGN gcDataText = "From Server".
 
    RUN returnmessage(INPUT gcDataText).
    SELF:DISCONNECT().
 
END PROCEDURE.
 
PROCEDURE returnMessage:
 
DEFINE INPUT PARAMETER pcClientText AS CHARACTER NO-UNDO.
 
/* Build a message to send */
SET-SIZE(mymemptr) = iMemmorySize.
SET-BYTE-ORDER(mymemptr) = BIG-ENDIAN.
PUT-STRING(mymemptr, 1, iMemmorySize) = pcClientText.
SELF:WRITE(mymemptr, 1, GET-SIZE(mymemptr)). 
SET-SIZE(mymemptr) = 0.
SELF:DISCONNECT().
 
END PROCEDURE.


I have load tested this by running

Code:
DEF VAR iCount AS INTEGER NO-UNDO.
 
DO iCount = 1 to 200:
    RUN client.p.
END.

If I run this load test several times the socket takes longer & longer. I have a 'feeling' that I'm not disconnecting correctly or tidying something up but am stuck as to what this is.

I am running the server socket on a V9 db and passing info back to the v10 client.

Sorry it's so long but any help would be appreciated.
Thanks.
 
Hi ,

I've tested the supplied code on Linux RH 10.2A SP2 and the only problem I can see was the "DELETE PROCEDURE THIS-PROCEDURE." as this was causing problems at runtime.

The response was very rapid and there was no noticeable increase in time for each execution of client.p.

Also on another note when dealing with memprt I fined that you should always set the size to zero before setting the actual size. Memptr don't seem to handle the same way as other datatypes as they linger about for the whole ABL session.

Code:
DEFINE VARIABLE mpData     AS MEMPTR  NO-UNDO.
DEFINE VARIABLE Imptrtsize AS INTEGER NO-UNDO.

Imptrtsize = 0.
SET-SIZE(mpData ) = Imptrtsize. /* Memptr reset.*/

Imptrtsize = 100.
SET-SIZE(mpData ) = 100.        /* First time setting the size of the Memptr.*/

Imptrtsize = 200.
SET-SIZE(mpData ) = 200.        /* second time setting the size of the Memptr. */

IF GET-SIZE(mpData ) NE Imptrtsize THEN
DO:

  MESSAGE SUBSTITUTE('Hang on a darn minute! I set the size to &1 not &2 ?',
                     Imptrtsize,
                     get-size(mpData)
                     )
    VIEW-AS ALERT-BOX ERROR.
  
  MESSAGE 'Let~'s try that again.'
    VIEW-AS ALERT-BOX INFO.

    Imptrtsize = 0.
    SET-SIZE(mpData ) = Imptrtsize. /* Memptr reset.*/

    Imptrtsize = 100.
    SET-SIZE(mpData ) = 100.        /* First time setting the size of the Memptr.*/

    Imptrtsize = 200.
    SET-SIZE(mpData ) = 0.    /* Memptr reset needs to be done before re-setting the size of the memptr*/
    SET-SIZE(mpData ) = 200.  /* second time setting the size of the Memptr. */

    IF GET-SIZE(mpData ) EQ Imptrtsize THEN
    DO:
        MESSAGE SUBSTITUTE('That~'s better! I set the size to &1 and it is &2 ?',
                     Imptrtsize,
                     GET-SIZE(mpData)
                     )
          VIEW-AS ALERT-BOX INFO.

    END.
END.[/B]
 
Cecil

Thanks for the pointer about resetting memptr to zero before setting the size. I've also removed the "DELETE PROCEDURE THIS-PROCEDURE.".

After some more testing I have discovered what the problem was. In the server.p program I had also put a display statement, that I hadn't included in my example, to show when a connection happened.

As you said your testing was OK I removed this display as it was the only difference and everything now runs OK for me as well. Without your help I proabably wouldn't have tried that so Thanks again.
 
Back
Top