Topic
19 replies Latest Post - ‏2014-02-08T17:36:25Z by souciance
HermannSW
HermannSW
4129 Posts
ACCEPTED ANSWER

Pinned topic sleep N

‏2011-02-01T12:00:10Z |
Just learned this from a colleage.

Unix sleep command "sleep 5" allows to wait 5 seconds before proceeding:
http://en.wikipedia.org/wiki/Sleep_%28Unix%29

This can be used in DataPower stylesheets as "equivalent" -- do a dp:url-open() to a non-existent URL with timeout set:
...
    <!-- do 10 second delay -->
    <dp:url-open target="http://2.3.4.5" response="ignore" timeout="10" />
...


The advantage is that this adds zero to CPU usage.

But this should be used for debugging/development, only
(eg. in MPGW with var://service/mpgw/skip-backside set to 1 for backend simulation).

Hermann.
Updated on 2014-03-25T03:35:03Z at 2014-03-25T03:35:03Z by iron-man
  • rrwood
    rrwood
    79 Posts
    ACCEPTED ANSWER

    Re: sleep N

    ‏2011-02-01T18:09:29Z  in response to HermannSW
    I'm very curious as to why you want to introduce deliberate latency in a policy. Can you describe where you would find this useful?
    • HermannSW
      HermannSW
      4129 Posts
      ACCEPTED ANSWER

      Re: sleep N

      ‏2011-02-01T19:44:37Z  in response to rrwood
      > I'm very curious as to why you want to introduce deliberate latency in a policy.
      > Can you describe where you would find this useful?

      Good that you ask.
      In fact it was a customer who asked for that.

      As stated above:
      But this should be used for debugging/development, only
      (eg. in MPGW with var://service/mpgw/skip-backside set to 1 for backend simulation).
      


      So if wou want to test a service you are developing and the backend is not avbaliable,
      just set skip-backside to 1 and simulate the backend processing time by a delay as above.

      You are right, it does not make any sense in production to add latency.

      Hermann.
      Updated on 2014-03-25T03:35:10Z at 2014-03-25T03:35:10Z by iron-man
      • arun_tcs
        arun_tcs
        144 Posts
        ACCEPTED ANSWER

        Re: sleep N

        ‏2011-02-02T03:28:27Z  in response to HermannSW
        Thanks Herman for sharing . It will be of great help in the development.
      • swlinn
        swlinn
        1344 Posts
        ACCEPTED ANSWER

        Re: sleep N

        ‏2011-02-03T13:38:06Z  in response to HermannSW
        To expand on Hermann's point to the question:

        > I'm very curious as to why you want to introduce deliberate latency in a policy.
        > Can you describe where you would find this useful?

        When doing performance and capacity testing, i.e., driving the appliance itself to the maximum load to determine maximum throughput, test environments may not have backend servers that can handle the traffic volumes that the appliances can handle, even when those backend servers are specialized "responder" applications. The solution is to create a DataPower "responder" service that determines the desired request service or operation, gets a template xml response for that request, perhaps updates that template with some generic information such as a current timestamp, appliance id, perhaps a uuid in a reference field, etc. The problem now is the performance test has 1-2 ms response times from the backend, which isn't a realistic performance test. Using a delay in this type of test service makes these response times realistic.

        Glad to know about this trick of url-open with timeout. I was using a http server with a cgi that did a sleep for 500ms, but that approach puts quite a load on the http server itself while under load. I will definitely use this approach.

        Regards,
        Steve
  • HaranathK
    HaranathK
    1 Post
    ACCEPTED ANSWER

    Re: sleep N

    ‏2011-02-02T08:39:27Z  in response to HermannSW
    I have created a loop back MultiProtocal Gateway and used ur suggestion to make delay in sending responses.But i am not finding any delay in responses.we have used the attached xsl in the multi protocal gateway.

    Multi protocal gateway details.

    Has 2 actions(set var action,transform)

    set var action sets the service variable(var://service/mpgw/skip-backside ) to 1.

    Transform action uses the attached xsl in sending the responses back.
    • HermannSW
      HermannSW
      4129 Posts
      ACCEPTED ANSWER

      Re: sleep N

      ‏2011-02-02T13:58:48Z  in response to HaranathK
      Hello,

      > I have created a loop back MultiProtocal Gateway and used ur suggestion to make delay in sending responses.
      > But i am not finding any delay in responses.we have used the attached xsl in the multi protocal gateway.
      >
      > Multi protocal gateway details.
      >
      > Has 2 actions(set var action,transform)
      >
      > set var action sets the service variable(var://service/mpgw/skip-backside ) to 1.
      >
      > Transform action uses the attached xsl in sending the responses back.

      I took your stylesheet and it reported 15 seconds of delay.
      Then I changed the IP address you provided (10.0.1.0) to 2.3.4.5.
      And now 30 seconds delay is reported (no idea why 10.0.1.0 is different -- I cannot ping it, please use non-existent IP address):
      
      $ time curl --data-binary 
      "<x/>" http:
      //dp5-l3.boeblingen.de.ibm.com:4040 <?xml version=
      "1.0" encoding=
      "UTF-8"?> <TimeSpentonBackend>15626</TimeSpentonBackend><response><msg>This is a dummy response</msg></response> real    0m15.644s user    0m0.007s sys     0m0.005s $ time curl --data-binary 
      "<x/>" http:
      //dp5-l3.boeblingen.de.ibm.com:4040 <?xml version=
      "1.0" encoding=
      "UTF-8"?> <TimeSpentonBackend>30010</TimeSpentonBackend><response><msg>This is a dummy response</msg></response> real    0m30.029s user    0m0.005s sys     0m0.008s $
      


      This is the stylesheet working fine (30 seconds delay):
      
      <xsl:stylesheet version=
      "1.0" xmlns:xsl=
      "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
      "http://www.datapower.com/extensions" extension-element-prefixes=
      "dp" > <xsl:output method=
      "xml" /> <xsl:template match=
      "/"> <!-- <dp:url-open target=
      "http://2.3.4.5" response=
      "ignore" timeout=
      "10" /> <done/> --> <xsl:variable name=
      "dummy-response"> <response> <msg>This is a dummy response</msg> </response> </xsl:variable>   <xsl:variable name=
      "start_time" select=
      "dp:variable('var://service/time-elapsed')"/> <xsl:variable name=
      "URL" select=
      "'http://2.3.4.5'"/>   <dp:url-open target=
      "{$URL}" response=
      "ignore" timeout=
      "30"> </dp:url-open>   <xsl:variable name=
      "end_time" select=
      "dp:variable('var://service/time-elapsed')"/> <xsl:variable name=
      "time_spent_on_backend" select=
      "number($end_time)-number($start_time)"/>   <TimeSpentonBackend> <xsl:value-of select=
      "$time_spent_on_backend"/> </TimeSpentonBackend>   <xsl:copy-of select=
      "$dummy-response"/>   </xsl:template> </xsl:stylesheet>
      


      Hermann.
      • arun_tcs
        arun_tcs
        144 Posts
        ACCEPTED ANSWER

        Re: sleep N

        ‏2011-02-03T09:10:17Z  in response to HermannSW
        Herman ,

        I used the same stylesheet , but its reporting different time every time i fire a request. For the first time it gives 30 seconds , but the subsequent calls dont give that value.

        Regards,
        Arun
      • souciance
        souciance
        181 Posts
        ACCEPTED ANSWER

        Re: sleep N

        ‏2014-02-07T15:49:36Z  in response to HermannSW

        Thanks Hermann for this awesome code, we are using it with some tweak in production due to some strange customer requirements!!

        • HermannSW
          HermannSW
          4129 Posts
          ACCEPTED ANSWER

          Re: sleep N

          ‏2014-02-07T16:24:56Z  in response to souciance

          Please do NOT use that in production!

          I said this in initial posting, perhaps should have written it in bold ...

          "But this should be used for debugging/development, only"


          Hermann<myXsltBlog/> <myXsltTweets/> <myCE/> <myFrameless/> <GraphvizFiddle/> <xqib/>

          • souciance
            souciance
            181 Posts
            ACCEPTED ANSWER

            Re: sleep N

            ‏2014-02-07T17:22:55Z  in response to HermannSW

            Hi Hermann..

            Besides not being the prettiest solution is there any other reason not to use this code in production? Any risks? Any other way you recommend to put in a delay? Thanks in advance.

            Souciance

            Updated on 2014-02-07T17:23:17Z at 2014-02-07T17:23:17Z by souciance
            • HermannSW
              HermannSW
              4129 Posts
              ACCEPTED ANSWER

              Re: sleep N

              ‏2014-02-07T18:36:16Z  in response to souciance

              Hi Souciance,

              > Besides not being the prettiest solution is there any other reason not to use this code in production? Any risks?
              >
              any in process transaction consumes resources (memory, connection, ...).

              In production you will have many concurrent transactions.
              And the box might run into ressource problems and become unstable.

              > Any other way you recommend to put in a delay?
              >
              Very simple, implement a sleep service on any server as service (java, perl, ...) and target <dp:url-open> against that.


              Hermann<myXsltBlog/> <myXsltTweets/> <myCE/> <myFrameless/> <GraphvizFiddle/> <xqib/>

              • souciance
                souciance
                181 Posts
                ACCEPTED ANSWER

                Re: sleep N

                ‏2014-02-08T16:04:36Z  in response to HermannSW

                Hi Hermann.

                One thing which I don't understand, in the blog post regarding this feature you have written that this is a good which does not load the CPU either. In what way can this approach consume resources that might make the system unstable?

                Basically we are running short on time and hence cannot build a sleep service on a server in the timespan we are talking about. Essentially once in a while we reach a batch load and this is split inside the message broker and sent via MQ to a cluster of datapower boxes (2 of them with an F5 infront). Hence either one of the boxes can receive and sent at any one time. The backend in this case is quit fragile and hence why for the batch we want to introduce a short delay.

                Thanks for any further comments on this matter.

                Best Regards

                Souciance

                • HermannSW
                  HermannSW
                  4129 Posts
                  ACCEPTED ANSWER

                  Re: sleep N

                  ‏2014-02-08T16:51:21Z  in response to souciance

                  Hi,

                  > In what way can this approach consume resources that might make the system unstable?
                  >
                  as I said above the memory of the transaction remains allocated as long as the transaction is not fully completed. In case of SSL that memory can be 1MB per transaction just because of SSL.

                  And the (back)ports of the connection remain allocated (the one over which DataPower returns data to client and the one over which DataPower sends data to backend). As you know the total number of ports is quite limited (16bit).

                  > Basically we are running short on time and hence cannot build a sleep service on a server
                  > in the timespan we are talking about.
                  >
                  If all works well with your configuration and workload -- fine.

                  But if you do not have time to setup a simple sleep service your project schedule seems to be wrong. And in case you will face problems on DataPower fixing that will likely cost you more time, and the response on a PMR you would raise will be to use an external sleep service because <dp:url-open> method is not a best practice (for production and for high load in non-prod).


                  Hermann<myXsltBlog/> <myXsltTweets/> <myCE/> <myFrameless/> <GraphvizFiddle/> <xqib/>

                  Updated on 2014-02-08T16:53:54Z at 2014-02-08T16:53:54Z by HermannSW
                  • souciance
                    souciance
                    181 Posts
                    ACCEPTED ANSWER

                    Re: sleep N

                    ‏2014-02-08T17:36:25Z  in response to HermannSW

                    Hi Hermann.

                    The problem is that, just like in any normal project requirements were changing constantly but deadline time was constant. We found out on friday that we need to add a 10-15 second delay for the occasions we need to do a batch load. The system needs to be up and running on Tuesday in production.

                    I tried using a count monitor and a SLM Policy with interval of 80 sec and 2 messages. However I could see in the probe that more than 2 messages were being processed within that interval. Is this no the right approach if I want to limit or create a delay`? Thanks in advance.

                    Souciance

                • ted.jump
                  ted.jump
                  209 Posts
                  ACCEPTED ANSWER

                  Re: sleep N

                  ‏2014-02-08T16:56:51Z  in response to souciance

                  It's like Hermann stated, memory use is the primary resource. Every 'open' transaction has some memory locked up, if you have a busy system this could equate to a lot of memory artificially busied out. I'm pretty sure that if a DP appliance gets into a critical state that it will pro-actively restart itself. This is probably better than the system mysteriously starting to misbehave.

                  To me, if you have a situation where your back-side system can't keep up with the client transaction levels then that is a problem to be robustly addressed either by increasing the back-side resources or by limiting the traffic (via DP enforced SLA) to prevent systemic issues.

  • arun_tcs
    arun_tcs
    144 Posts
    ACCEPTED ANSWER

    Re: sleep N

    ‏2011-02-02T09:01:40Z  in response to HermannSW
    Herman ,

    When i am using url-open to connect to non-existing ip address, iam seeing below error in the system logs .

    "url-open: Remote error on url ".

    It appears to me that DP is detecting connection failure before the timeout can occur.

    Any guess?

    Regards,
    Arun
    • HermannSW
      HermannSW
      4129 Posts
      ACCEPTED ANSWER

      Re: sleep N

      ‏2011-02-02T14:07:15Z  in response to arun_tcs
      Arun,

      > When i am using url-open to connect to non-existing ip address, iam seeing below error in the system logs .
      >
      > "url-open: Remote error on url ".
      >
      > It appears to me that DP is detecting connection failure before the timeout can occur.
      >
      > Any guess?
      >

      Find below the log entries from my last request with the 30s sample from Haranath above.
      You can see that the Remote error is reported on 08:52.25 which is 30 seconds after begin of transaction 08:51:55 ...

      Again, this sleep method is intended to be used for debugging/development and not in production.

      
      08:52:25   mpgw      info          64545           9.152.201.53    0x80e0010f      mpgw (sleep): Early completion detected - back side will not be executed 08:52:25       multistep info          64545   >    9.152.201.53    0x80c00002      mpgw (sleep): rule (all_rule_0): #2 xform: 
      'Transforming INPUT with local:///404.xsl results stored in OUTPUT' completed ok. 08:52:25 network   error         64545   >    9.152.201.53    0x80e00040      mpgw (sleep): url-open: Remote error on url 
      'http://2.3.4.5/' 08:51:55        xslt      info          64545           9.152.201.53    0x80a002a4      xmlmgr (
      
      default): xslt Compilation Request: Compilation complete of URL local:
      ///404.xsl 08:51:55       multistep info          64545   >    9.152.201.53    0x80c00002      mpgw (sleep): rule (all_rule_0): #1 setvar: 
      'setting var://service/mpgw/skip-backside in context INPUT to be 1' completed ok. 08:51:55        mpgw      info          64545           9.152.201.53    0x80e00115      mpgw (sleep): Will not process backside due to var:
      //service/mpgw/skip-backside 08:51:55 mpgw      info          64545   >    9.152.201.53    0x80e000b4      stylepolicy (all): rule (all_rule_0): selected via match 
      'all' from processing policy 
      'all' 08:51:55        mpgw      info          64545           9.152.201.53    0x80e0013a      source-http (4040): Received HTTP/1.1 POST 
      
      for / from 9.152.201.53
      


      Hermann.
  • HermannSW
    HermannSW
    4129 Posts
    ACCEPTED ANSWER

    Re: sleep N

    ‏2011-02-02T14:21:38Z  in response to HermannSW
    The difference between "2.3.4.5" and "10.0.1.0" ...

    "10.0.1.0" is an IANA-reserved private IPv4 A network address:
    http://en.wikipedia.org/wiki/Ip_address#IPv4_private_addresses

    Hermann.
    • arun_tcs
      arun_tcs
      144 Posts
      ACCEPTED ANSWER

      Re: sleep N

      ‏2011-02-02T15:51:48Z  in response to HermannSW
      Thats a good catch,Herman.

      I never thought that the ipaddress is a reserved one.

      Regards,
      Arun