3

My api runs fine when it's local but when i deloy it to run it is unusually slow is , is this because of my server how do i check that.

Here are some of the responses I got

// vue

import axios from '@axios';
import { defineStore } from 'pinia';

export const useGanttStore = defineStore('GanttStore', {
  actions: {
    //  Fetch users data
    fetchDatas(params) { 
      return new Promise((resolve, reject) => {
        axios.get('link').then(response => resolve(response)).catch(error => reject(error))
      })
    },

//server : I just tried to print out a string but it took almost 2s

Route::group(['as' => 'api.', 'middleware' => 'auth:api'], function () {
    
// Route::post('/projects-view',function(){
//     return "projects-view";
// });

enter image description here

server real api: load with full data enter image description here

local: full data enter image description here

postman - local : enter image description here

postman - server : enter image description here

I am using laravel 7 and vue3. even though it says api response is 2 seconds but the feeling i get it should be around 4-5 seconds

Something related

enter image description here

enter image description here

curl progress meter : skip auth and just return string

server

enter image description here

local:

enter image description here

kennofizet
  • 45
  • 6
  • Have you ensured that this is not an IPv4 vs IPv6 issue? Like the browser first trying to connect via IPv6 and then falling back to IPv4? This can happen when the DNS response includes an IPv6 address but the server is only bound to the IPv4 address. – Daniel F Apr 27 '23 at 19:49
  • I don't know about it, do you have any documentation about that or an example – kennofizet Apr 27 '23 at 19:52
  • `nslookup www.example.com` would return an IPv6 address as well as an IPv4. Then you'd need to post the code here which you use to start the server. – Daniel F Apr 27 '23 at 19:54
  • it returns me 2 ip address it is my server address, i am using aapanel is there any tool available at apanel to check – kennofizet Apr 27 '23 at 20:01
  • I haven't learned anything related to server management, so many concepts are quite new – kennofizet Apr 27 '23 at 20:03
  • ```"OPTIONS /api/projects-status-data HTTP/2.0" 204 - "domain" "......" "OPTIONS /api/projects-view HTTP/2.0" 204 - "domain" "......" "POST /api/projects-status-data HTTP/2.0" 200 195 "domain" "......." "POST /api/projects-view HTTP/2.0" 200 6211 "domain" "......."``` this is the response i get in the server log when i try to call the above 2 api – kennofizet Apr 27 '23 at 20:12
  • One thing you can try is to run a `curl` command on an address (locally to the server) that is a route that does not require authorization so it is easier to test. Check this example so you know what to write to get the timing: https://stackoverflow.com/a/22625150/1998801. Remember to use `http://localhost` or `https` on the server, so it is local. If it goes fast, do it again with the real domain. – matiaslauriti Apr 27 '23 at 20:20
  • I get total query time - skip auth and just return string: server - time_total 0.950292s and local time_total 0.340384s – kennofizet Apr 27 '23 at 20:49
  • so, it is vey fast when it is local, the `0.95s` server, is it using `http://yourdomain.com`? or what did you use? `local` is, of course, `http://localhost` ON THE SERVER, right? – matiaslauriti Apr 27 '23 at 20:52
  • I not really understand http://localhost on the server is. i am using https – kennofizet Apr 27 '23 at 21:00
  • curl i tried on ```https://mydomainserver/api/projects-view``` and local is ```http://localhost::port/api/projects-view``` – kennofizet Apr 27 '23 at 21:03

1 Answers1

0

First, you must ensure you don't have a network problem. You must cal use this command in the server without Vue and axios.

curl -vvv http://localhost:8000/projects-view

If your request is fast you have network problem, but if you have slowly in this request you must use Laravel telescope to trace the request and find slow process.

Pirooz Jenabi
  • 440
  • 5
  • 7
  • i don't think my network is the problem, it's in the range of 7-8Mbps, my curl response when calling the server is 1s however i don't know why when i actually call it through axios it sometimes goes up 3s. my internal server runs stable at 600ms response with axios and 300ms with curl – kennofizet Apr 28 '23 at 14:14
  • Please install Laravel telescope and send log. before that run php artisan optimize. – Pirooz Jenabi Apr 28 '23 at 18:24
  • i don't know why you suggest to use telescope, if it is to check query time it is superfluous and makes my production app slow, my local app is fine, even with api actually, I'm using the debugbar to do that. However, here I give the test is 2 cases: the api has real data and the api only returns letters for testing (no direct database query returns response) so telescope is not necessary for the current case, I can use many other tools to check. Or maybe I'm misunderstanding what you mean – kennofizet Apr 29 '23 at 13:13
  • of course i ran the command ```php artisan optimize``` – kennofizet Apr 29 '23 at 13:22