Vova Bilyachat

Melbourne, Australia

High traffic usage on Azure Web App + Sql Server on VM

21 May 2016

Preavious post was about trafic, and this one is not an exception. When i log in to azure portal into billing i was a bit surprices to see
Well for somebody it could be ok but for my project where i have around 3000-4000 people everyday it is too much.

The first thing I've done was writing to support, but they just confirmed that everything is right and i am actively using all what i am billed. 

By coincidence at the same time i started playing with Azure sql and it was extremaly slow, some queries were running almost twice time more than in my current setup, at that point I debug queries and was a bit of surprise how much data i am transfering from database to webapp, since in many queries i am using entityframework Include (I will start optimizin that and will write one more blog post about that) and it means it try to get everything in one request but using joins.

After that i understood that actually issue is with traffic between database and webapp, so i went to azure and start reading again about gateway and i found that all traffic which is going throw gateway is paid.  

Solution

I should never ever use gateway to connect to any server inside of azure. Gateway should be used ONLY when database machine is out of azure network.
Open end point in Azure Database VM


Connection String to Sql Server on Azure VM should look like 
"Server=mydbserver.cloudapp.net,57500;Integrated Security=false;User ID=<login_name>;Password=<your_password>"
If you have same problem please vote for suggestion it would help to understand which service is using.

Result




Lesson learned

Read More

Save traffic for your website and improve loading speed, Azure CDN, Asp.Net MVC

20 April 2016

Last month I started monitoring how much my website cost to host on Azure, and I was surprised that I am paying around 25USD for traffic which I should not generate. Firstly I did not understand what is going on and what is generating so much traffic, since before I was using VPS and i did not pay for that so I started investigation

Chrome

I am using chrome by default so it was easy to get what is going on (Pressing F12->Network).
So each visit to my site generates only on one script 534Kb + 18.6 and its only on javascript but i have css, images so on.

Use cache

First step to improve that was enabling cache in web.config
<staticContent>
      <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="90.00:00:00" />
</staticContent>

Now if we compare network in chrome its possible to see that script is loading from cache


CDN

To speed up even more loading of static files I created new CDN on Azure. And cool thing about it that it actually require zero configuration. After CDN its pretty easy to configure it, usig existing web app.

How CDN works

It will check in browser cache if file exists, if not it will check if file is in CDN cache and if not it will load from WebApp. (This solution its not right, since better would be if I have deployment tasks which will deploy binary to webapp, and static file to CDN, but this private project and I dont have much time to do everything right :( ) 


Read More

Elmah filter by exception type

14 December 2015

In Elmah there two ways to filter exception

  1. by code
  2. by config
In this post i will just show how to filter exception using config file this is pretty simple 


  <elmah>
    <errorFilter>
      <test>
        <or>
          <equal binding="HttpStatusCode" value="404" type="Int32" />
          <is-type binding="BaseException" type="Namespace.BaseException, AssembyName" />
        </or>
      </test>
    </errorFilter>
  </elmah>

So current config will ignore all 404 and exception who inherited from BaseException.  But note that important thing is that assembly name is specified or elmah will try to search in Elmah assembly which will cause an error

Read More

Ionic2 with Typescript and Visual Studio support

29 November 2015

Intro

I love development its not my job its part of my life :) So i am always opened to new technologies languages, except python (Actually i tried it but i dont like syntax of it so). So since I am working with Angular I am following version 2 to get some news and understand what would be in the future.
This blog post will not be an expert post I would say is more for dummies people like me who use to use Visual Studio but want to play with TypeScript.
When firstly i saw TypeScript  I ask question my self why? why to have compiler when you write code and then its compiled to Javascript, I can easily write just vanilla js and I dont want to learn this language, but new languages are not created to make complexity, so i was again reading a bit more about typescript and finally i understood benfits of it

  • You can compile and catch exception. This is really awesome for people like me who really use to compile and found basic exceptions
  • ES and browsers, EcmaScript is changing dynamically adding new features, but generally browsers are not so fast to implement that, here TS solve this issue because when you compile sources you choose target ES version to compile.
  • Much easier to start for people who know C#, Java and other similar languages.
Since again i like to work with new stuff i am fun of Ionic framework and i started playing with new Alpha version. I will not write how to setup all of that i will just write how to run project in Visual Studio.

Let go

First step would be to create project
Next depends if ionic project was already created then copy files to new folder, if not then run ionic create commands from project folder.
Go to Visual Studio and include files to Project

As you can see in my project there is typings folder. This is magic folder since it contains all definitions for classes and this helps intellisence

To manage typing install tsd manager
npm install -g tsd
now we can install all typing definitions
tsd install angular2/angular2
For ionic2 there is not yet official defenitions yet but there is opened issue on github but jksoftpro posted his typing which works pretty cool. But i did download file and placed to typing folder.
Please note to make it work all typedefinitions must be included in project. So if something is not working make sure that you have included .d.ts
 And now everything work visual studio now suggests methods

Read More

Iphone scroll issue with bootstrap Modal after any item is selected in select

29 November 2015

Few days ago i figured out strange bug in Bootstrap v3.3.5 modals scroll. So when modal is opened everything is ok and scroll works properly. But when user modals contains any <select> item and user choose option from it then after that modal is not scrollable but BODY is so users can't scroll up down.
I was googling and i found one suggestion how to fix it

@media (max-width: 480px) {
body.modal-open {
overflow: hidden;
position:fixed;
}
}

So after that issue is gone

Read More