Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using Apache on my server. I'm testing my Android application, which gets content from server frequently. The first 10 to 20 or more tries are ok, but then at some point, my Android application seems not receiving any content from server.

Running top on my server, it says

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
27679 www-data 20 0 247m 12m 2252 S 18.6 10.5 0:56.99 apache2

This process just stopped or is just blocked. You've see it takes %18.6 of CPU and $10.5 memory constantly.

I couldn't figure out what's going on. What I only know is to restart Apache, but it's not a good idea.

Here is my code (I'm using Apache's HttpClient):

public class WebUtil {

private static final String TAG = "WebUtil";

public static String getContent(String url) {
    StringBuilder builder = new StringBuilder();
    HttpClient client = getThreadSafeClient();
    HttpGet httpGet = new HttpGet(url);

    try {
        HttpResponse response = client.execute(httpGet);

        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));

            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }

            reader.close();
            content.close();
            httpGet.abort();
        } else {
            Log.e(WebUtil.TAG, "Failed to download file " + url);
        }
    } catch (ClientProtocolException e) {
        Log.e(WebUtil.TAG, e.getMessage(), e);
    } catch (IOException e) {
        Log.e(WebUtil.TAG, e.getMessage(), e);
    }

    return builder.toString();
}

private static HttpClient _initHttpClient() {
    HttpParams params = new BasicHttpParams();
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, registry);
    HttpClient client = new DefaultHttpClient(cm, params);
    return client;
}

private static HttpClient client;

public synchronized static HttpClient getThreadSafeClient() {

    if (client != null)
        return client;

    client = _initHttpClient();

    return client;
} 
}

update:

There are not really some logs related, but here is some log when I restart the server:

[Fri Sep 02 15:57:14 2011] [warn] child process 27933 still did not exit, sending a SIGTERM
[Fri Sep 02 15:57:14 2011] [warn] child process 27934 still did not exit, sending a SIGTERM
[Fri Sep 02 15:57:16 2011] [warn] child process 27933 still did not exit, sending a SIGTERM
[Fri Sep 02 15:57:16 2011] [warn] child process 27934 still did not exit, sending a SIGTERM
[Fri Sep 02 15:57:18 2011] [warn] child process 27933 still did not exit, sending a SIGTERM
[Fri Sep 02 15:57:18 2011] [warn] child process 27934 still did not exit, sending a SIGTERM
[Fri Sep 02 15:57:20 2011] [error] child process 27933 still did not exit, sending a SIGKILL
[Fri Sep 02 15:57:20 2011] [error] child process 27934 still did not exit, sending a SIGKILL
[Fri Sep 02 15:57:21 2011] [notice] caught SIGTERM, shutting down
[Fri Sep 02 15:57:22 2011] [notice] Apache/2.2.17 (Ubuntu) mod_ruby/1.2.6 Ruby/1.8.7(2010-08-16) configured -- resuming normal operations
share|improve this question
1  
Are there any errors in the logs? –  Zypher Sep 2 '11 at 15:59
    
@Zypher♦ I add some log in the question. –  draw Sep 2 '11 at 21:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.