-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi
How to evaluate the bandwidth consumption of zk, (criteria used)
Thanks in advance for your help
I have created for myself some HTTP filter that sizes request and response.
This is the page that this output if from
Log results are
com.trade4stas.view.filters.TrafficFilter URL [zkau/web/9317420/zul/css/zk.wcs]. request_size=[-1] bytes, response_size=[0] bytes com.trade4stas.view.filters.TrafficFilter URL [zkau/web/9317420/js/zul.lang.wpd]. request_size=[-1] bytes, response_size=[1353] bytes com.trade4stas.view.filters.TrafficFilter URL [zkau/web/9317420/zul/css/zk.wcs]. request_size=[-1] bytes, response_size=[0] bytes com.trade4stas.view.filters.TrafficFilter URL [zkau/view/g6r2/z_6r_3/1/c/chart1270767896873.png]. request_size=[-1] bytes, response_size=[14753] bytes com.trade4stas.view.filters.TrafficFilter URL [zkau/view/g6r2/z_6r_51/1/c/chart1270767897092.png]. request_size=[-1] bytes, response_size=[20075] bytes
In case of a partial refresh of a little bit more sophisticated page
com.trade4stas.view.filters.TrafficFilter URL . request_size=[119] bytes, response_size=[5375] bytes com.trade4stas.view.filters.TrafficFilter URL [zkau/view/g7r2/z_7r_91/3/c/chart1270768017714.png]. request_size=[-1] bytes, response_size=[15153] bytes com.trade4stas.view.filters.TrafficFilter URL [zkau/view/g7r2/z_7r_ck/1/c/chart1270768017324.png]. request_size=[-1] bytes, response_size=[20179] bytes
Source code of filter
package com.trade4stas.view.filters; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; /** * Created by IntelliJ IDEA. * User: Stan Sokolov * Date: Apr 8, 2010 * Time: 11:46:38 AM * To change this template use File | Settings | File Templates. */ public class TrafficFilter implements Filter { private final Log log = LogFactory.getLog(this.getClass()); private FilterConfig fc; /********************************************************************************************* * Check traffic *********************************************************************************************/ public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws IOException, ServletException { if ( ! (req instanceof HttpServletRequest && res instanceof HttpServletResponse)) { log.debug("URL ["+req.getLocalAddr()+"]. not HTTP request. Size not calculated."); chain.doFilter(req, res); return; } final HttpServletResponse response = (HttpServletResponse) res; final HttpServletRequest request = (HttpServletRequest) req; final String full_url = request.getRequestURL().toString(); final String short_url = full_url.replaceAll("http://([A-Za-z0-9:]*)/",""); final CharResponseWrapper wrapRes = new CharResponseWrapper(response); int request_size=request.getContentLength(); try { chain.doFilter(request, wrapRes); } catch (final Throwable e) { log.error("Traffic Filter execution failed",e); } final byte[] res_bytes = wrapRes.getData(); final int response_size = res_bytes.length; log.debug("URL ["+short_url+"]. request_size=["+request_size+"] bytes, response_size=["+response_size+"] bytes"); response.setContentLength(res_bytes.length); response.getOutputStream().write(res_bytes); } public void init(FilterConfig filterConfig) { this.fc = filterConfig; } public void destroy() { this.fc = null; } }
Source code of response wrapper
package com.trade4stas.view.filters; import org.apache.log4j.Logger; import java.io.*; import java.util.Arrays; import java.util.Enumeration; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; public class CharResponseWrapper extends HttpServletResponseWrapper { private ByteArrayOutputStream output; private CharResponseOutputStream outputStream; /***************************************************************************************************** * Internal class to emulate writing to the response *****************************************************************************************************/ private class CharResponseOutputStream extends ServletOutputStream { @Override public void print(String s) throws IOException { output.write(s.getBytes()); } @Override public void write (int i) throws IOException { print(""+i); } @Override public void print(boolean b) throws IOException { print(String.valueOf(b)); } @Override public void print(char c) throws IOException { print(String.valueOf(c)); } @Override public void print(int i) throws IOException { print(String.valueOf(i)); } @Override public void print(long l) throws IOException { print(String.valueOf(l)); } @Override public void print(float f) throws IOException { print(String.valueOf(f)); } @Override public void print(double d) throws IOException { print(String.valueOf(d)); } @Override public void println() throws IOException { print(String.valueOf("\n")); } @Override public void println(String s) throws IOException { print(s); println(); } @Override public void println(boolean b) throws IOException { print(b); println(); } @Override public void println(char c) throws IOException { print(c); println(); } @Override public void println(int i) throws IOException { print(i); println(); } @Override public void println(long l) throws IOException { print(l); println(); } @Override public void println(float f) throws IOException { print(f);; println(); } @Override public void println(double d) throws IOException { print(d);; println(); } @Override public void write(byte[] b) throws IOException { output.write(b); } @Override public void write(byte[] b, int off, int len) throws IOException { output.write(b,off,len); } } /***************************************************************************************************** * Get byte array of whatever been written in the response *****************************************************************************************************/ public byte[] getData() { return output.toByteArray(); } /***************************************************************************************************** * Create a new instance of this wrapper *****************************************************************************************************/ public CharResponseWrapper(final HttpServletResponse response) { super(response); //Use these arrays to put response body outputStream = new CharResponseOutputStream(); output = new ByteArrayOutputStream(); } public ServletOutputStream getOutputStream() { return outputStream; } }
I am not sure if this response wrapper/filter work for all occasions but they pretty good for the purpose.
Configure filter in web.xml
<filter> <filter-name>trafficFilter</filter-name> <filter-class>com.trade4stas.view.filters.TrafficFilter</filter-class> </filter> <!-- Traffic filter web pattern --> <filter-mapping> <filter-name>trafficFilter</filter-name> <url-pattern>/zkau/*</url-pattern> </filter-mapping>
I apologize for the derangement
@Stas283,
Thanks for your response
-i want to evaluate the bandwidth consumption of zk in order to compare it with other Framework.
For ex,Flex ( exchange SOAP (HTTP / XML)).
Really,i didn't understand best your response(how i can use to evaluate the bandwidth it in my project zk ).
-i didn't understand the text of your link "This is the page that this output if from",Please more explaination
-Can you share with me a project that i can run in Eclipse.
Well, the only what I can suggest is to put some HTTP filter that can measure HTTP traffic and run some examples from ZK and other framework. You should have substantial competence to be able to configure HTTP filter in front of the framework modules. My example gives you an example of HTTP filter that is configured to measure HTTP traffic of ZK framework. If you want you can configure the same filter to measure traffic of Vaadin or another framework. So far I did not notice that ZK consumes a lot of bandwidth. As you see on example, partial page update requires 119 bytes of request and around 5000 coming back on the response.
In my experience, the bandwidth is more consumed by javascript, images, css, etc. So you have to play with the settings to properly cache this stuff by the browser (ZK 5.0.1 has some new setting regarding resource caching.). It is an issue of every AJAX RIA, do not know much about Flex.
Asked: 2010-04-08 06:48:07 +0800
Seen: 626 times
Last updated: Jan 07 '14