Skip to main content

Spring Boot Apache HTTP Client Performance Tuning

 Spring Boot Apache HTTP Client Performance Tuning

How do you optimize pooled connections to downstream services using Apache HttpClient?
Here is an experiment.


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""
        <relativePath/> <!-- lookup parent from repository -->
    <description>Demo project for Spring Boot</description>


    <!-- -->




Java Code;

package com.efeyopixel.myclient;

import org.apache.http.HttpHost;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

public class IwsclientApplication {

    public static void main(final String[] args) {;

    public CloseableHttpClient connectionManager() {
        final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
        final HttpHost host = new HttpHost("localhost"8083);
        connManager.setMaxPerRoute(new HttpRoute(host), 8);
        final CloseableHttpClient client = 
        return client;


class IndexController {

    private final DownstreamService dService;

    public ResponseEntity<?name() {"pass endpoint");
        return ResponseEntity.ok(;


class DownstreamService {

    final CloseableHttpClient client;
    public String name() {
        String response = null;
        CloseableHttpResponse execute = null;
        try {

            execute = client.execute(new HttpGet("http://localhost:8083/apage"));

            response = EntityUtils.toString(execute.getEntity());

        } catch (final IOException e) {
            log.error(e.getMessage(), e);
        } finally {
            if (response != null) {
                log.debug("closing response");

        return response;


Popular posts from this blog

๐Ÿ†•Maven Spring Boot Run Command Line Arguments ๐Ÿฝ๐Ÿ‘‰๐Ÿพ Spring Boot Project Intellij Idea Run

This video is presents how to properly use maven spring boot run command line arguments.

Staying Connected While Travelling Abroad With Free International Data Roaming

Staying connected with your loved ones while travelling abroad used to be a challenge. Previously your cell phone didn’t work abroad, roaming charges were ridiculous and you may have had to use a sketchy computer at an airport to let your folks keep up with where you are if delays happen.   For long layovers, getting a local SIM card may not be practical or even possible. You can use free airport Wi-Fi but that only works within the Airport most of the times. Welcome To Germany Text from T-Mobile In my case with T-Mobile, I get free roaming and texting in over 200 countries, so as soon as I get into a new country, my phone has service! The data is throttled but it is enough to make calls and browse the web to get my boarding pass, itinerary etc. Even after arriving at my final destination, I tried to use local SIM card and buy data plans but they were ridiculously expensive and these expire nightly. T-Mobile offers faster speeds at $5 per day, but I did manage without