0

Hey guys hopefully the title wasn't too bad, hard to describe succinctly.

So I have an ASP.net core 2.0 server running (via Kestrel) on a VPS hosted in Australia (I'm in New Zealand, ~50ms latency to server). An HTTP Get action causes the following code on the ASP.net server to run, where I query an SQL server (also running on the vps) and return the result:

public async Task<string> GetTopContactPhoto(int contactUID)
    {
        // Open connection if not already open
        if (conn.State != System.Data.ConnectionState.Open) { conn.Open(); }

        // Get number of rows
        string sqlRequest = string.Format("select top 1 imageData from IMAGES where contactUID=@contactID;");

        // Return value
        using (SqlCommand cmd = new SqlCommand(sqlRequest, conn))
        {
            cmd.Parameters.AddWithValue("@contactID", contactUID);
            return Convert.ToBase64String((byte[])await cmd.ExecuteScalarAsync());
        }
    }

Now this whole process takes pretty consistently ~5-6 seconds from the time the HTTP Get request is made, to the time the result is given, image sizes ~2MB.

But here's the thing, when I compile and run the ASP.Net core server on my development PC, on a separate continent altogether to the VPS (still running the SQL server), the whole process takes only ~2 seconds, less if I resize the image before responding to Get request.

Any ideas what could be going wrong? This problem has vexed me for months, with no amount of googling doing the trick.

  • Have you worked out exactly where the time is being taken? e.g. db access or web server? I doubt googling is going to solve this. You will need to profile your application and db in both environments and work out the difference. – SpruceMoose Apr 10 '18 at 08:13
  • The time seems to be spent on the return statement, having timed everything else it comes to ~2 seconds, but from the time return is hit to the time the data is received, about 4 seconds is unaccounted for – Matthew Minish Apr 11 '18 at 07:31
  • Just to confirm, are you connecting to the same SQL Server instance in both cases/environments? – SpruceMoose Apr 11 '18 at 08:05
  • Yes I am indeed – Matthew Minish Apr 11 '18 at 09:07

0 Answers0