Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Regarding the Service Bus, if there are zero messages, what causes the process to take so long to complete using php code? #1018

Open
yuki-0310 opened this issue Apr 28, 2021 · 1 comment

Comments

@yuki-0310
Copy link

yuki-0310 commented Apr 28, 2021

[Contents]
When the Service Bus receiving process is executed based on the following reference material, it takes about 6 seconds to complete the execution when the message to be received is 0.
If the message to be received is 0, it takes about 6 seconds to complete the process. If the message is 1 or more, it takes about 1 second to complete the process.
We have obtained and checked the network trace (HAR file), but could not find the cause of the delay.

In order to determine which process is taking the longest time, we used the TIME function in the PHP process to verify.

Source code for receiving process.

<html>
<head><title>PHP TEST</title></head>
<body>
 
<?php
 
require_once 'vendor/autoload.php';
use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Common\ServiceException;
use WindowsAzure\ServiceBus\Models\ReceiveMessageOptions;
 
$connectionString = "Endpoint=https://[Resource Name].servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=[SharedAccessKey]";
echo "section 1 start time : ".time()."<br />";
$serviceBusRestProxy = ServicesBuilder::getInstance()->createServiceBusService($connectionString);
echo "section 1 end time : ".time()."<br />";
 
try {
    // Set receive mode to PeekLock (default is ReceiveAndDelete)
    $options = new ReceiveMessageOptions();
    echo "section 2 start time : ".time()."<br />";
    $options->setPeekLock();
    echo "section 2 end time : ".time()."<br />";
    
    // Get message.
    echo "section 3 start time : ".time()."<br />";

    $message = $serviceBusRestProxy->receiveSubscriptionMessage("
    [Service Bus Topic]", "[Service Bus Subscription]", $options);

    echo "section 3 end time : ".time()."<br />";
    
    if ($message !== null) {
        echo "Body: ".$message->getBody()."<br />";
        echo "MessageID: ".$message->getMessageId()."<br />";
        
        // Delete message. Not necessary if peek lock is not set.
        echo "Deleting message...<br />";
        echo "section 4 start time : ".time()."<br />";
        $serviceBusRestProxy->deleteMessage($message);
        echo "section 4 end time : ".time()."<br />";
    } else {
        echo "Not Exists<br />";
    }
 
}
catch(ServiceException $e){
    // Handle exception based on error codes and messages.
    // Error codes and messages are here:
    // https://docs.microsoft.com/rest/api/storageservices/Common-REST-API-Error-Codes
    $code = $e->getCode();
    $error_message = $e->getMessage();
    echo $code.": ".$error_message."<br />";
}
 
?>
</body>
</html>
Messages 0 : 5.86 seconds

image
section 3 start time : 1618902752
section 3 end time : 1618902758
It took about 6 seconds to receive the message.
I ran it several times, and it took about 5 or 6 seconds at all the same receiving points.

One message: 1.43 seconds
image
If the message is 1 or more, the receiving process will be completed in about 1 second.

https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-php-how-to-use-topics-subscriptions#receive-messages-from-a-subscription

And, we also checked the source code of the SDK below, but could not find the reason why it takes so long to complete the receiving process when there are zero messages.
https://github.com/Azure/azure-sdk-for-php/blob/e80e1a2de183d9894613a19ac243c4f4796a67ee/src/ServiceBus/ServiceBusRestProxy.php#L 224

[Question.]
If there are zero messages, what causes the process to take so long to complete?

@tomb-yellowgrid
Copy link

F

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants