{"id":195412,"date":"2017-01-22T13:30:28","date_gmt":"2017-01-22T11:30:28","guid":{"rendered":"http:\/\/mybroadband.co.za\/news\/?p=195412"},"modified":"2017-01-22T14:02:00","modified_gmt":"2017-01-22T12:02:00","slug":"faster-websites-with-fewer-bugs","status":"publish","type":"post","link":"https:\/\/mybroadband.co.za\/news\/cloud-hosting\/195412-faster-websites-with-fewer-bugs.html","title":{"rendered":"Faster websites with fewer bugs"},"content":{"rendered":"<p>Today, loading a web page on a big website usually involves a database query \u2014 to retrieve the latest contributions to a discussion you\u2019re participating in, a list of news stories related to the one you\u2019re reading, links targeted to your geographic location, or the like.<\/p>\n<p>But database queries are time consuming, so many websites store \u2014 or \u201ccache\u201d \u2014 the results of common queries on web servers for faster delivery.<\/p>\n<p>If a site user changes a value in the database, however, the cache needs to be updated, too.<\/p>\n<p>The complex task of analyzing a website\u2019s code to identify which operations necessitate updates to which cached values generally falls to the web programmer. Missing one such operation can result in an unusable site.<\/p>\n<p>This week, at the Association for Computing Machinery\u2019s Symposium on Principles of Programming Languages, researchers from MIT\u2019s Computer Science and Artificial Intelligence Laboratory presented a new system that automatically handles caching of database queries for web applications written in the web-programming language Ur\/Web.<\/p>\n<p>Although a website may be fielding many requests in parallel \u2014 sending different users different cached data, or even data cached on different servers \u2014 the system guarantees that, to the user, every transaction will look exactly as it would if requests were handled in sequence.<\/p>\n<p>So a user won\u2019t, for instance, click on a link showing that tickets to an event are available, only to find that they\u2019ve been snatched up when it comes time to pay.<\/p>\n<p>In experiments involving two websites that had been built using Ur\/Web, the new system\u2019s automatic caching offered twofold and 30-fold speedups.<\/p>\n<p>\u201cMost very popular websites backed by databases don\u2019t actually ask the database over and over again for each request,\u201d says Adam Chlipala, an associate professor of electrical engineering and computer science at MIT and senior author on the conference paper.<\/p>\n<p>\u201cThey notice that, \u2018Oh, I seem to have asked this question quite recently, and I saved the result, so I\u2019ll just pull that out of memory.\u2019\u201d<\/p>\n<p>\u201cBut the tricky part here is that you have to realize when you make changes to the database that some of your saved answers are no longer necessarily correct, and you have to do what\u2019s called \u2018invalidating\u2019 them.<\/p>\n<p>And in the mainstream way of implementing this, the programmer needs to manually add invalidation logic. For every line of code that changes the database, the programmer has to sit down and think, \u2018Okay, for every other line of code that reads the database and saves the result in a cache, which ones of those are going to be broken by the change I just made?\u2019\u201d<\/p>\n<p>Chlipala is joined on the paper by Ziv Scully, a graduate student in computer science at Carnegie Mellon University, who worked in Chlipala\u2019s lab as an MIT undergraduate.<\/p>\n<h3 class=\"my-4\">Exhaustive search<\/h3>\n<p>Ur\/Web, which Chlipala invented, lets web developers completely specify their sites\u2019 functionality using just one programming language.<\/p>\n<p>The Ur\/Web compiler then automatically generates all the different types of code required to power a website \u2014 HTML, JavaScript, SQL database queries, and cascading style sheets \u2014 while providing certain performance and security guarantees.<\/p>\n<p>Chlipala and Scully\u2019s new system is a modification of the compiler, so Ur\/Web users can simply recompile their existing code to get all the benefits of database caching. The language itself remains unchanged.<\/p>\n<p>The new compiler begins by analyzing the Ur\/Web code and determining what data to cache and how to organize it. For instance, if certain types of queries are almost always performed in conjunction with each other, Ur\/Web will cache the associated data in a single table.<\/p>\n<p>The compiler also decides whether to cache raw data, HTML code, or, if the program structure permits it, entire webpages.<\/p>\n<p>Then the compiler goes through the code and compares every operation that updates a value in the database with every operation that queries the database, to determine which cached values need to be invalidated when, and it adds the appropriate cache-invalidation commands in the appropriate places.<\/p>\n<p>Like many programming languages, Ur\/Web has an associated \u201cruntime,\u201d a small program that runs in the background to manage the execution of applications written in the language. Chlipala and Scully also updated the Ur\/Web runtime to monitor the frequency with which cached database queries are reused.<\/p>\n<p>Any that prove superfluous are deleted, which improves the system\u2019s efficiency.<\/p>\n<h3 class=\"my-4\">Painless improvements<\/h3>\n<p>In addition to testing the system on two full websites, Chlipala and Scully also tested it on a handful of smaller programs, also written in Ur\/Web, which are part of a standard set of benchmarks used to compare different Web development frameworks.<\/p>\n<p>On those, the new system offered speedups of between twofold and fivefold.<\/p>\n<p>They did not, however, compare sites developed using their system to sites that use hand-coded caching because, as Chlipala explains, \u201cUr\/Web\u2019s so much faster than everything else.\u201d<\/p>\n<p>\u201cEven if it turns out that someone could put in the extra work and get a tripling of the throughput, our argument is that it\u2019s a pretty good deal to get a doubling of your throughput with no extra work,\u201d he adds.<\/p>\n<p>\u201cMany websites and other programs that use databases use caches to improve performance,\u201d says Andrew Myers, a professor of computer science at Cornell University. \u201cHowever, it&#8217;s quite tricky to do this correctly, since the results of database queries can become invalid.<\/p>\n<p>So the attempt to speed up applications in this way leads to bugs that can be very challenging to find. Rather than requiring the programmer to identify the results that need to be discarded, the [MIT researchers\u2019] system does this automatically, by analyzing the different requests that the application makes to the database.\u201d<\/p>\n<p>Source: <a href=\"http:\/\/news.mit.edu\/2017\/faster-websites-fewer-bugs-0120\" target=\"_blank\">MIT News<\/a><\/p>\n<h3 class=\"my-4\">Now read:\u00a0<a href=\"https:\/\/mybroadband.co.za\/news\/internet\/195316-most-popular-google-searches-in-south-africa.html\" rel=\"bookmark\">Most popular Google searches in South Africa<\/a><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>Loading a web page on a big website usually involves a database query, but database queries are time consuming, so many websites cache the results of common queries on web servers.<\/p>\n","protected":false},"author":340957,"featured_media":155132,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[40774,40772,35],"class_list":["post-195412","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cloud-hosting","tag-bugs","tag-fast-website","tag-headline"],"_links":{"self":[{"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/posts\/195412"}],"collection":[{"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/users\/340957"}],"replies":[{"embeddable":true,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/comments?post=195412"}],"version-history":[{"count":1,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/posts\/195412\/revisions"}],"predecessor-version":[{"id":195414,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/posts\/195412\/revisions\/195414"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/media\/155132"}],"wp:attachment":[{"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/media?parent=195412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/categories?post=195412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/tags?post=195412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}