0

I am new to web applications and to be hones I am trying to update an old web-application, trying to speed it up. I analyze the application and see what's the reason of the slow in loading pages.. Of course it's the http-requests and I tried to read how can I speed up the requests and I found that I should serialize the data but I don't know how to do that in my application. So I need someone to tell me how to use serialization or how can I speed up the request please: first it uses angular-js so the request is like that:

viewModelHelper.apiPost('Book/book_getList', null,
                function (result) {
                    $scope.gridOptions.data = result.data;
                });

and I use simillar methods to have the data...

The viewModelHelper.apiPost in the app.js:

self.apiPost = function (uri, data, success, failure, always) {
            self.modelIsValid = true;
            $http.post(MyApp.rootPath + uri, data)
                .then(function (result) {
                    success(result);
                    if (always != null)
                        always();
                }, function (result) {
                    if (failure != null) {
                        failure(result);

                    }
                    else {
                        var errorMessage = result.status + ':' + result.statusText;
                        if (result.data != null) {
                            if (result.data.Message != null)
                                errorMessage += ' - ' + result.data.Message;
                            if (result.data.ExceptionMessage != null)
                                errorMessage += ' - ' + result.data.ExceptionMessage;
                        }

                    }
                    if (always != null)
                        always();
                });
        }

And then let's say in the bookController there is book_getList method:

public JsonResult book_getList()
        {
            List<BookModels> List = obj.book_getList();
            return Json(List, JsonRequestBehavior.AllowGet);
        }

And the bookModels have properties like this:

 public Guid guid_book_id { get; set; }
         public string code { get; set; }
         public string closet { get; set; }
         public string shelf { get; set; }
      public string title { get; set; }

And the method get_list:

public List<BookModels> book_getList()
        {
            try
            {
                OpenCon();
                List<BookModels> List = con.Query<BookModels>("book_getList", param: null, commandType: CommandType.StoredProcedure).ToList();
                return List.ToList();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                CloseCon();
            }
        }

Thanks

TonySader
  • 47
  • 5
  • Whilst it's true that protobuf has less overhead than JSON, what makes you think that it's the serialisation of your data that is slow and not the things that the call otherwise has to do? – Adam G Jan 28 '19 at 22:01
  • @AdamG I don't know exactly what is making it slow but I tried to read about the slow issue and I found that I could use serialization to speed up.. Do you have other ideas?? – TonySader Jan 28 '19 at 22:03
  • How did you measure the slowness? Can your measuring tool tell you how many seconds the call spent in retrieving the data Vs how many seconds it spent in converting that to JSON? – Adam G Jan 28 '19 at 22:08
  • @AdamG can I measure this in network >--Developer tools of google chrome ?? – TonySader Jan 28 '19 at 22:20
  • @AdamG it shows me that my request of data is taking 3.62s of Waiting(TTFB) – TonySader Jan 28 '19 at 22:21
  • If you're talking about protobuf and angular.js, then you'd need a JavaScript protobuf API. Google has one of those, but I can't comment on it as I haven't used it. In truth, for browsers, JSON is usually the tool of choice. If nothing else, it is much simpler to use – Marc Gravell Jan 28 '19 at 22:27
  • *I don't know exactly what is making it slow* - In that case, you should use a [profiler](https://stackoverflow.com/q/3927) and find out. Then, once you have identified the problem, you can ask a concrete programming question about how to resolve the issue. In any event asking us to rewrite your client and server code to use protocol buffers looks to be too broad of a question. You might start [here](https://stackoverflow.com/q/6912981) for the client side and [here](https://stackoverflow.com/q/35348747/3744182) for the server. – dbc Jan 28 '19 at 22:30
  • Chrome has no capacity to measure the time of the individual tasks performed within the IIS process in response to your call. It is literally measuring the whole time from when it starts the POST until it receives the data. That does include serialisation time, but also includes time that your server had to do work. If serialisation is taking more than a dozen milliseconds for this call, I'd be surprised. If you are unsatisfied with your car's fuel efficiency, replacing your heavy jackets with slightly lighter ones is unlikely to give you a noticeable improvement. – Adam G Jan 28 '19 at 22:39
  • @dbc ok thank you for your links, but unfortunately as one of your links and Marc mentioned that protobuf is not working with angularjs :(.. but just to be clear I want opinions about the slowness issue and if it's the serilization that make it slow or other things, I am not asking anyone to rewrite the code.. Thanks – TonySader Jan 29 '19 at 11:18
  • @AdamG hummmm ok I got you.. Thanks – TonySader Jan 29 '19 at 11:18

0 Answers0