Jetty server overloaded ?

Alan Lobo3 months ago

I am continuously getting this error from my client

PHP Warning:  file_get_contents(http://xxx.in:5055/?deviceid=GA07F9336&speed=8&lat=15.494112&lon=73.830178×tamp=1718637097): Failed to open stream: HTTP request failed! in /var/www/.../tanker-location.php on line 61

However I cant find anything in the traccar logs.
I suspect the jetty server is getting overloaded but wanted some way to confirm
background : I have two worker threads that pull data from external sources and push to the traccar server.

Anton Tananaev3 months ago

It doesn't even go through Jetty. What did you base your suspicion on?

Alan Lobo3 months ago

I am not getting any HTTP response code other than HTTP request failed!
and no entry in the traccar logs.
So I didnt have anything to go in any other direction

Anton Tananaev3 months ago

Are you sure you're not getting code or you're not getting content?

Alan Lobo3 months ago

my code is like this

file_get_contents($this->base_url . http_build_query($datum), false, stream_context_create(array('http' => array(
          'timeout' => 1,
          'ignore_errors' => false,
        ))));
        $this->http_response_header = $http_response_header;
        if ($this->http_response_header[0] != 'HTTP/1.1 200 OK') {
          var_dump($this->http_response_header);

I am anyways not expecting any content. I just check the status code.

Anton Tananaev3 months ago

The method is called file_get_contents probably for a reason.

Alan Lobo3 months ago

:)
after the creation of the function, it has since been overloaded to make curl requests as well.
Note that I am not even saving or examining the response data.
I am directly checking the HTTP status through the variable $http_response_header and that is where I get an empty array.

Alan Lobo3 months ago

any chance of getting failure reason in the logs ?

Anton Tananaev3 months ago

There's no plan for that. You should be able to get any failures through the API response.

Alan Lobo3 months ago

I think I got the issue.
Earlier, the default timeout for the curl request was 30s. Since it was taking very long, I had overridden it and set to 1 sec.
This works for the most part except when the server takes slightly longer.
But this is an issue with any timeout value set. larger values will make the script run longer, shorter values risk aborting requests midway.

is there anyway the server running on 5055 can terminate the connection upon completion of saving the data to the db ?

Anton Tananaev3 months ago

No, you should terminate it from the client side once you receive the response.

Alan Lobo3 months ago

Would it be possble to send some sample code (in any language) so that i can get an idea of the ideal way to do it

Anton Tananaev3 months ago
Alan Lobo3 months ago
use GuzzleHttp\Client;
  $client = new Client(['timeout' => 2]);
  $response = $client->get($this->base_url, ['query' => $datum]);
  if ($response->getStatusCode() <> 200) {
    print_r($response->getHeaders());
  }

no luck after changing the HTTP client.

Alan Lobo3 months ago

this change to guzzle http client appears to fail the call.
here is the stack trace

#2 /var/www/wrd/addon-services/vendor/guzzlehttp/guzzle/src/Middleware.php(31): GuzzleHttp\PrepareBodyMiddleware->__invoke()
#3 /var/www/wrd/addon-services/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php(71): GuzzleHttp\Middleware::GuzzleHttp\{closure}()
#4 /var/www/wrd/addon-services/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\RedirectMiddleware->__invoke()
#5 /var/www/wrd/addon-services/vendor/guzzlehttp/guzzle/src/HandlerStack.php(75): GuzzleHttp\Middleware::GuzzleHttp\{closure}()
#6 /var/www/wrd/addon-services/vendor/guzzlehttp/guzzle/src/Client.php(333): GuzzleHttp\HandlerStack->__invoke()
#7 /var/www/wrd/addon-services/vendor/guzzlehttp/guzzle/src/Client.php(169): GuzzleHttp\Client->transfer()
#8 /var/www/wrd/addon-services/vendor/guzzlehttp/guzzle/src/Client.php(189): GuzzleHttp\Client->requestAsync()
#9 /var/www/wrd/addon-services/vendor/guzzlehttp/guzzle/src/ClientTrait.php(44): GuzzleHttp\Client->request()
#10 /var/www/wrd/addon-services/tanker-location.php(58): GuzzleHttp\Client->get()
#11 /var/www/ddd/addon-services/tanker-location.php(38): AbstractGPSProvider->pushData()
#12 /var/www/wrd/addon-services/tanker-location.php(403): AbstractGPSProvider->__construct()
#13 {main}