0

I am testing wso2 apim 4.0.0. The problem is that a direct request to the endpoint works pretty fast. But calling it through wso2 apim (gateway) somehow adds some time (1000-15000 ms). It used to work just fine. After observing the wso2carbon logs I found out that the request mediation latency is occasionally high (1000-15000 ms).

Also the analytics data is being sent to rabbitmq (followed this instruction). Following class for collecting metrics:

public class LogCounterMetric implements CounterMetric {

private static final Logger log = LoggerFactory.getLogger(LogCounterMetric.class);
private String name;
private MetricSchema schema;

public LogCounterMetric(String name, MetricSchema schema) {
    this.name = name;
    this.schema = schema;
}

@Override
public int incrementCount(MetricEventBuilder metricEventBuilder) throws MetricReportingException {
    Map<String, Object> properties = metricEventBuilder.build();
    String metricValue=properties.toString().replaceAll("[\r\n]", "");
    log.info("Metric Name: " + name.replaceAll("[\r\n]", "") + " Metric Value: "
            + metricValue);

    try {
        MessageSender messageSender=new MessageSender();
        messageSender.send(metricValue);
    } catch (IOException e) {
        e.printStackTrace();
        return 0;
    } catch (TimeoutException e) {
        e.printStackTrace();
        return 0;
    }
    return 0;
}
// other methods ommitted

}

This class for sending the metrics to rabbitmq

public class MessageSender {
private final static String EXCHANGE_NAME = "analytics_pipe_exchange";
private final static String PRIMARY_QUEUE_NAME = "analytics_pipe";
private final static String PRIMARY_ROUTING_KEY = "analytics.pipe_key";

public void send(String message) throws IOException, TimeoutException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("host");
    factory.setUsername("user");
    factory.setPassword("user");
    try (Connection connection = factory.newConnection();
         Channel channel = connection.createChannel()) {
        channel.queueDeclare(PRIMARY_QUEUE_NAME, true, false, false, null);
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC, true);
        channel.queueBind(PRIMARY_QUEUE_NAME, EXCHANGE_NAME, "analytics.*");
        channel.basicPublish(EXCHANGE_NAME, PRIMARY_ROUTING_KEY, null, message.getBytes());
    }
}

}

From the rabbitmq analytics data in its turn is being persisted in postgres by another custom application. If the issue is related to scalability then, the gateways are running in two instances with nginx in front.

Any navigation and tips to address the issue is appreciated

Frank
  • 178
  • 1
  • 12
  • DId you apply any message mediations, and if yes, what sort of message mediation logic is that? Message mediations can slow down the API as well. – Joy Rathnayake Feb 22 '23 at 07:13
  • If you remove the matrics collection logic does it work as expected? Your MessageSender seems inefficient, you seem to create a new connection per request. – ycr Feb 22 '23 at 12:20

1 Answers1

0

You can enable correlation logs and narrow down the issue. https://apim.docs.wso2.com/en/4.0.0/observe/api-manager/monitoring-correlation-logs/

Pubci
  • 3,834
  • 1
  • 13
  • 28