[jboss-jira] [JBoss JIRA] (WFLY-4693) Slow HTTPS Upload provokes High CPU Load

Serge Mürset (JIRA) issues at jboss.org
Thu May 28 05:10:02 EDT 2015


     [ https://issues.jboss.org/browse/WFLY-4693?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Serge Mürset updated WFLY-4693:
-------------------------------
    Steps to Reproduce: 
- Install Wildfly 9.0.0 CR1
- Activate HTTPS in config
- Deploy a sample webappliction (e.g. https://tomcat.apache.org/tomcat-6.0-doc/appdev/sample/ should work too, although no doPost implemented)
- Adjust the following client code (https address, upload file)
- Run the code
- CPU Load will increase to 100% during the sleeps of the HTTPS client

{code:title=TestUndertowLoad.java|borderStyle=solid}
package undertowtest;

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;

/**
 * Tests the Undertow module, how it behaves in case of a HTTPS client which sends
 * its POST data very slowly.
 */
public class TestUndertowLoad {
	/**
	 * Starter method of the test.
	 *
	 * @param args Arguments,  not used
	 *
	 * @throws IOException If a connection to webserver occured.
	 */
	public static void main(String[] args) throws IOException {
		String host = "localhost:8443";
		String uploadFile = "/opt/import/testfile.bin";
		int chunkSize = 50;
		int sleepTime = 1000;

		String url = "https://" + host + "/sample/hello";
		URL obj = new URL(url);
		HttpsURLConnection con = (HttpsURLConnection)obj.openConnection();
		con.setRequestMethod("POST");

		byte[] data = readFile(new File(uploadFile));
		con.setFixedLengthStreamingMode(data.length);

		// send data using outputstream
		con.setDoOutput(true);

		System.out.println("Sending 'POST' request to URL : " + url+"\n");
		DataOutputStream wr = new DataOutputStream(con.getOutputStream());
		int index = 0;
		while (index < data.length) {
			// slow upload to provoke https://issues.jboss.org/browse/UNDERTOW-345
			// CPU load will rise to 100 percent during the sleeps
			wr.writeByte(data[index]);
			System.out.print(".");
			
			if ((index % chunkSize) == (chunkSize-1)) {
				try {
					System.out.println("Chunk sent, sleeping...");
					Thread.sleep(sleepTime);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			index++;
		}

		wr.flush();
		wr.close();

		int responseCode = con.getResponseCode();
		System.out.println("Response Code : " + responseCode);
	}

	private static byte[] readFile(File file) throws IOException {
		byte[] ret;

		try {
			RandomAccessFile f = new RandomAccessFile(file, "r");

			try {
				ret = new byte[(int)f.length()];
				f.read(ret);
			} finally {
				f.close();
			}
		} catch (FileNotFoundException e) {
			ret = null;
		}

		return ret;
	}
}

{code}


  was:
- Install Wildfly 9.0.0 CR1
- Activate HTTPS in config
- Deploy a sample webappliction (e.g. https://tomcat.apache.org/tomcat-6.0-doc/appdev/sample/ should work too, although no doPost implemented)
- Adjust the following client code (https address, upload file)
- Run the code
- CPU Load will increase to 100% during the sleeps of the HTTPS client

{code:title=TestUndertowLoad.java|borderStyle=solid}
package undertowtest;

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;

/**
 * Tests the Undertow module, how it behaves in case of a HTTPS client which sends
 * its POST data very slowly.
 */
public class TestUndertowLoad {
	/**
	 * Starter method of the test.
	 *
	 * @param args Arguments,  not used
	 *
	 * @throws IOException If a connection to webserver occured.
	 */
	public static void main(String[] args) throws IOException {
		String host = "localhost:8443";
		String uploadFile = "/opt/import/testfile.bin";
		int chunkSize = 50;
		int sleepTime = 1000;

		String url = "https://" + host + "/sample/hello";
		URL obj = new URL(url);
		HttpsURLConnection con = (HttpsURLConnection)obj.openConnection();
		con.setRequestMethod("POST");

		byte[] data = readFile(new File(uploadFile));
		con.setFixedLengthStreamingMode(data.length);

		// send data using outputstream
		con.setDoOutput(true);

		DataOutputStream wr = new DataOutputStream(con.getOutputStream());
		int index = 0;

		while (index < data.length) {
			// slow upload to provoke https://issues.jboss.org/browse/UNDERTOW-345
			// CPU load will rise to 100 percent during the sleeps
			wr.writeByte(data[index]);
			System.out.print(".");
			
			if ((index % chunkSize) == (chunkSize-1)) {
				try {
					System.out.println("Chunk sent, sleeping...");
					Thread.sleep(sleepTime);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			index++;
		}

		wr.flush();
		wr.close();

		int responseCode = con.getResponseCode();
		System.out.println("\nSending 'POST' request to URL : " + url);
		System.out.println("Response Code : " + responseCode);
	}

	private static byte[] readFile(File file) throws IOException {
		byte[] ret;

		try {
			RandomAccessFile f = new RandomAccessFile(file, "r");

			try {
				ret = new byte[(int)f.length()];
				f.read(ret);
			} finally {
				f.close();
			}
		} catch (FileNotFoundException e) {
			ret = null;
		}

		return ret;
	}
}

{code}




> Slow HTTPS Upload provokes High CPU Load
> ----------------------------------------
>
>                 Key: WFLY-4693
>                 URL: https://issues.jboss.org/browse/WFLY-4693
>             Project: WildFly
>          Issue Type: Bug
>          Components: Web (Undertow)
>    Affects Versions: 9.0.0.CR1
>            Reporter: Serge Mürset
>            Assignee: Stuart Douglas
>              Labels: undertow, web
>
> This issue is a reopen of https://issues.jboss.org/browse/UNDERTOW-345.
> This Issue is not fixed with Wildfly 9.0 CR1 (contrary to what was indicated in above mentioned ticket). Issue is fixed when XNIO trunk (https://github.com/xnio/xnio)  is built and replaces XNIO 3.3.1 module.
> This is a major bug, as just one client with bad connectivity will cause a 100% CPU Load on Wildfly whilst the HTTPS upload is being read. It's also a real-world bug, as every note-worthy productive server will have at least one client with bad connectivity at any given time. Duration of the high CPU load directly correlates to the duration it takes the client to send all his POST data.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)



More information about the jboss-jira mailing list