ajax 重新加载view,Ajax View

Remotely Monitoring Client-Side Web App Performance and Behavior

By Emre Kıcıman and Benjamin LivshitsDo you know what your users are experiencing when they visit your AJAX application?  Is your JavaScript code running fast, slow, or generating errors in your users’ browsers?

The Ajax View project at Microsoft Research aims to give developers easy visibility into their web apps’ performance and behavior as the apps run in end-users’ browsers.   Ajax View uses a server-side proxy to rewrite JavaScript “on-the-fly” and automatically inject instrumentation code into a web application.  This instrumentation provides end-to-end visibility into app performance, behavior and critical state.  “On-the-fly” rewriting allows Ajax View to serve different instrumentation across users and over time, capturing more detail about app behavior while minimizing per-user performance overhead.

In this lab, you will use an early prototype of Ajax View technology to quickly enable cross-browser performance profiling of web apps, without modifying the original web app code or the client-side browser.   First, you will startup Ajax View as a client-side proxy.  Then, you will browse a web application while Ajax View monitors its function-level performance, and see the resulting profile information.

Research Prototype Warning:  Ajax View is an early preview of work we have been doing at Microsoft Research.  Our prototype is often rough around the edges, not as fast as it could be, not scalable, etc.

Performance Profiling Walk-Through

First, if you haven’t already, download and install the Ajax View prototype.

Then, let’s start the Ajax View client-side proxy:

Start Ajax View by clicking on the Ajax View Proxyicon in your start menu.

If you are running Windows Vista, you should see a dialog asking you to allow Ajax View to run with administrator privileges. Click allow.

Ajax View is now running as a proxy, ready to intercept and rewrite web applications’ JavaScript code.  By default, Ajax View listens for connections on port 8888.74e567f49954b9ad9caa2b15eb69872d.png

Next, let’s open a web browser and use a web application:

Open either Internet Explorer or Firefox.

Because Ajax View does not require browser plugins or ActiveX controls, it can profile and monitor app behavior as they run in either Internet Explorer or Firefox.

Note: Both browsers’ proxy settings have already been preset to use the Ajax View proxy

Set the browser’s proxy settings to localhost port 8888:

Open the Tools menu, and click on the Internet Options menu item.3f987792e4cce03a297498073b3fb9c4.png

Click on the Connections tab in the Internet Options dialog box.787c6d69d7428abaff3ec5d38641e0b0.png

Click on the LAN Settings button in the Connections pane.db11b02ac321644cc50b55001dd87851.png

Uncheck “Automatically detect settings.”

Check “Use proxy server for your LAN” and ensure that the address is set to localhost and the port is set to 8888.

6296fd3f9d49e65f918bf3d1d35397c5.png

Note: The Ajax View proxy does not support HTTPS / SSL connections.  If you want to browse HTTPS sites while Ajax View is enabled, click through to the Advanced settings, uncheck the option to “use the same proxy server for all protocols,” and enter Ajax View only for the HTTP protocol.  Leave the Secure, FTP  and SOCKS protocol proxies blank or set to your previous proxy.

Once the page has loaded, search for hotels in las vegas by typing “hotels” in the top search box, and “las vegas, nv” in the address box.0426f05a38354c8f2701bc704d65ff6e.png

Double-click a few times in the middle of the map to zoom into the center of Las Vegas.  While you use maps.live.com, Ajax View is monitoring and capturing the applications behavior.04741389826de382e92674f115b9829c.png

Now, it’s time to look at the information that Ajax View has gathered.

Press CTRL+T to open a new tab.

This URL will be intercepted by the Ajax View proxy.  Instead of sending this request to “fakeurl.com”, Ajax View will return its own statistics page.

Click the “JS Performance Statistics” link.a06d6ba4ae3758ef2585765df9029d98.png

The right pane is now showing a list of urls that we have visited while running our application, grouped by top-level domain. The first column shows the URL itself, the second column shows the number of JavaScript functions and scripts that are defined within the file, and the third column displays the performance of the slowest function within the file.a8312ea6e4937d20578b5865a138e0ea.png

Let’s click on one of these URLs, the “mapcontrol” file, shown as the link:sc1.local.live.com/mapcontrol.asjx?…

Now, the right pane is showing a list of all the JavaScript functions defined in this file.  The columns of data show performance information for each function.0d392736ee6835d9d07ad06d5c26a4d4.png

Let’s see what the slowest functions were. Click on the “Mean Time (ms)” column to sort the table by this column.3eeea25c60401a73cf8871481e93c0fe.png

Let’s get more detail about the performance profile of double-clicking to zoom in on the map.   Click on the “Details” link next to the “this.Init” function.

Now, we see a list of the functions that are called by the “this.Init” function, sorted by their average performance.b39ecaef521b14e2cac941aa4418f326.png

Now, try it with your own web application! Just browse to the site and then return to the Ajax View main page to see the statistics.

How It Works

Ajax View works by using a proxy to intercept and rewrite the JavaScript code of a web application and automatically inject instrumentation code.  The rewriting is controlled by one or more instrumentation policies, embedded within the proxy.

In this demo, you have seen a simple performance profiling policy that adds log statements to the beginning and end of every script block and function definition within the JavaScript code of a web application.  This rewriting policy takes a script that looks like:

7c89256e6124415ab45d8309649d2ad5.png

And turns it into a script that looks like:

563dbc82179501f035f62b172e510b0d.png

Our prototype actually does a little more rewriting than is shown here.  For example, it inlines the logging functions to reduce performance overhead, rewrites return statements, and keeps track of the line number and character offset of the function to help identify anonymous functions and disambiguate functions with the same name.

Whenever the injected instrumentation logs an event, such as a function enter or exit, the event is timestamped and added to a queue. A timer event handler periodically empties the queue of messages and reports them back to the proxy via an HTTP post request.  The proxy is responsible for analyzing the results and generating the per-function performance statistics.

Conclusion

You have used the Ajax View proxy to gather performance profile information for a web application, without modifying the original web application, and without installing any extra plugins, ActiveX controls or extensions in the web browser.

As Ajax View is currently an early research prototype, we are considering several future directions for the project, including further research into instrumentation policies to help developers debug their application, and the possibilities of integrating this technology into developer tools and/or web server infrastructure.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
jquery的treeview 在显示大层次树是会卡死浏览器,我结合http://www.cnblogs.com/xuanye/archive/2009/10/26/1590250.html的改进版做的这个改进版(因为很多人没读他的源码,不知道怎么请求节点的处理页面),把asp.net的json序列化 都做了进去(Newtonsoft.jsonnet2.0.dll),,采用ajax+wrapperpage+usercontrol的模式生成json(因为牵涉公司两个配置文件,必须读配置信息连接数据库,绕了一下其实可以更轻量级的handler来处理,例子不能运行,但可以看看),同时扩展了很多的配置项都有说明,希望对大家有帮助 使用例如: <link href="lib/jquery/plugins/treeview/jquery.tree.css" rel="stylesheet" type="text/css" /> <script src="lib/jquery/jquery.js" type="text/javascript"></script> <script src="lib/jquery/plugins/treeview/js/jquery.tree.js" type="text/javascript"></script> <%--<script src="lib/jquery/plugins/treeview/js/getData.js" type="text/javascript"></script>--%> <script src="lib/jquery/plugins/treeview/js/common.js" type="text/javascript"></script> <%--<script src="lib/jquery/plugins/treeview/js/tree3.js" type="text/javascript"></script>--%> <!--你可以把下面的代码放到一个js文件当中--> <script type="text/javascript"> var checknodes = "HJH8,HJA5"; //你事先要传给树控件的 已选中节点 id $(document).ready(function() { var o = { isAsync: false, //是否异步获取节点,根据咱的要求 设为false url: "AjaxWrapperPages/AsyncGetTreeNodes.aspx", //请求节点的页面,如果没有改变文件路径 不用关心 cbiconpath: "lib/jquery/plugins/treeview/images/icons/", //同上 checkbox icon的目录位置 //icons: ["checkbox_0.gif", "checkbox_1.gif", "checkbox_2.gif"],//不用配置 emptyiconpath: "lib/jquery/plugins/treeview/images/s.gif", //checkbxo三态的图片 animate: true, //不用配置,动画没有效果 theme: "bbit-tree-lines", //bbit-tree-lines ,bbit-tree-no-lines,bbit-tree-arrows有线、没线、箭头 三个样式中选择 showcheck: true //是否显示复选框 , checkNodes: checknodes //上面 你事先要传给树控件的 已选中节点 id的变量 , rootText: "中石化单位"//根节点的文本 可为空 则没有根节点 建议起个有意义的名字描述这棵树 //,onnodeclick: function(item) { alert(item.text); } , dbconfigPath: "~/hanwayDbConfig.hwdb" //可去掉,这是我做测试用 可不用此配置 , conStr: "conStr" //连接字符串 你可直接传,考虑安全 可不用此配置 /************ 必填项 ****************/ , sqlPath: "~/Db.hwSql" //sql语句存放的文件位置 , sqlID: "dwdyinfo" //sql对应的sqlid , dtFields: "dm,zhdm,mc" //表的结构 控件之关心3个:“主键id 外(父)键id 节点文本” 依次','分开 , pnodeMark: "dyzhgx" //和上面的dtFields中的外键 用来构造过滤条件 如"zhdm='dyzhgx'" 查询出所有一级节点 }; $("#tree").treeview(o); //到服务器处理选中节点 $("#showchecked").click(function(e) { var changnodes = $("#tree").getTSVs(); //得到所有选中节点的id if (changnodes != null) { changnodes = changnodes.join(","); $.ajax({ type: "get", url: "some.aspx", data: "nodes="+changnodes, success: function(msg) { alert("Data Saved: " + msg); } }); } });

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值