SlideShare a Scribd company logo
Axis2 client memory leak
Outline
• Issue & diagnosis
• Postmortem from technique point
  – Axis2 1.4/1.4.1/1.5.6 client
  – Implement & design issue
Issue




CServer exhaust 8G memory -> memory leak
diagnosis
      jmap –histo               pid

num     #instances         #bytes class name
----------------------------------------------
   1:       1001744      246906600 [C //char array
   2:       2855952      137085696 edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap$Segment
   3:        282338      115692192 [I // int array
   4:        677362      102508648 [Ljava.util.HashMap$Entry;
   5:        192117       99164392 [B // byte array
   6:       2856122       91732120 [Ledu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap$HashEntry;
   7:       2855952       91390464 edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock$NonfairSync
   8:       1337498       53499920 java.lang.String
   9:        433634       43130120 [Ljava.lang.Object;
  10:        597908       38266112 java.util.HashMap




      From the histogram, the memory leak is caused by Axis2.
       1) The main change in this release is using web service client (axis2 1.4.1)
       2) char[] / edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap
       3) Google ‘axis2 1.4.1 concurrentHashMap memory leak‘
diagnosis
 jmap –dump:file=cdump pid

• We got a 2.39G memory heap dump
  – Very fast, less than 30 seconds (because 8G
    memory in production)
• Problem : too big to open in dev box
  – Need enough physical memory
  – (May) need 64 bit OS
  – Try Jhat/Jprofile/YJP/Jmat eclipse plugin
    (windows/2G)
                             Open by Jmat standalone application
diagnosis




AxisConfiguration retain 540.9m heap
diagnosis




Hashtable allEndPoints holds more than 2k axis2 endpoint instances
diagnosis




All of the endpoint instances are about FavoriteService
1) Confirm in the code, only FavoriteService related did not call cleanup
Axis2 1.4 memory leak
• Reproduce

for( int i=0;i<count; i++) {
    VersionStub stub = new VersionStub(configContext,null);
    GetVersion request = new GetVersion();
    stub.getVersion(request);
}
Axis2 1.4 memory leak
 • Informal Model (OO design)



AxisConfiguration

Map allServices = new Hashtable();
Map allEndpoints = new Hashtable();
Axis2 1.4 memory leak
• Cause : Stub Initiation, add into AxisConfiguration




   //Init, Add
   allServices.put(serviceName, axisService);
   ..
   allEndpoints.put(serviceName + "." + endpointName, axisService);
Axis2 1.4 memory leak
• Cause : Stub Finalize
  //Stub
  protected void finalize() throws Throwable {
          super.finalize();
          cleanup();
  }

  public void cleanup() throws AxisFault {
          _service.getAxisConfiguration().removeService(_service.getName());
  }



 //AsixConiguration
 public synchronized void removeService(String name) throws AxisFault {
         AxisService service = (AxisService) allServices.remove(name);
         if (service != null) {
             AxisServiceGroup serviceGroup = service.getAxisServiceGroup();
             serviceGroup.removeService(name);
             log.debug(Messages.getMessage("serviceremoved", name));
         }
     }
Axis2 1.4 memory leak
• Cause : Client Finalize
  //ServiceClient
  protected void finalize() throws Throwable {
          super.finalize();
          cleanup();
  }

  public void cleanup() throws AxisFault {
    …
          axisConfiguration.removeServiceGroup(serviceGroupName);
    …
  }



 //AsixConiguration
 public AxisServiceGroup removeServiceGroup(String serviceGroupName) throws AxisFault {
            …
            Iterator services = axisServiceGroup.getServices();
            while (services.hasNext()) {
                          AxisService axisService = (AxisService) services.next();
                          allServices.remove(axisService.getName());
                          …
            }
            …
Axis2 1.4 memory leak
• Cause
  //Init, Add
  allServices.put(serviceName, axisService);
  ..
  allEndpoints.put(serviceName + "." + endpointName, axisService);




  //Cleanup(Finalize), Remove
  allServices.put(serviceName, axisService);




• Memory Leak :             allEndpoints
Axis2 1.4.1 fix
• Fix the bug AXIS2-3870
//AsixConiguration.removeServiceGroup

//removes the endpoints to this service
String serviceName = axisService.getName();
String key = null;
for (Iterator iter = axisService.getEndpoints().keySet().iterator(); iter.hasNext();){
   key = serviceName + "." + (String)iter.next();
   this.allEndpoints.remove(key);
}
Axis2 1.4.1 memory leak
• Reproduce

for( int i=0;i<count; i++) {
    VersionStub stub = new VersionStub(configContext,null);
    GetVersion request = new GetVersion();
    stub.getVersion(request);
    stub.cleanup();
}



   Programmer: 1.4 has memory leak issue, so call cleanup
Axis2 1.4.1 memory leak
• Cause : Stub Finalize (no change)
  //Stub
  protected void finalize() throws Throwable {
          super.finalize();
          cleanup();
  }

  public void cleanup() throws AxisFault {
          _service.getAxisConfiguration().removeService(_service.getName());
  }



 //AsixConiguration
 public synchronized void removeService(String name) throws AxisFault {
         AxisService service = (AxisService) allServices.remove(name);
         if (service != null) {
             AxisServiceGroup serviceGroup = service.getAxisServiceGroup();
             serviceGroup.removeService(name);
             log.debug(Messages.getMessage("serviceremoved", name));
         }
     }
Axis2 1.4.1 memory leak
• Cause: Client Finalize (no change)
  //ServiceClient
  protected void finalize() throws Throwable {
          super.finalize();
          cleanup();
  }

  public void cleanup() throws AxisFault {
    …
          axisConfiguration.removeServiceGroup(serviceGroupName);
    …
  }
Axis2 1.4.1 memory leak
• Cause: Client Finalize (no change)
//AsixConiguration
public AxisServiceGroup removeServiceGroup(String serviceGroupName) throws AxisFault {
           …
           Iterator services = axisServiceGroup.getServices();
           while (services.hasNext()) {
                         AxisService axisService = (AxisService) services.next();
                         allServices.remove(axisService.getName());

                   …
                   for (Iterator iter = axisService.getEndpoints().keySet().iterator(); iter.
                          key = serviceName + "." + (String)iter.next();
                          this.allEndpoints.remove(key);
                   }
                   …

          }

                  Servce are already removed from ServiceGroup in Stub cleanup
          …
}
                  The while loop would never enter
Axis2 1.4.1 memory leak
• Cause
  – Stub cleanup and ServiceClient cleanup have
    dependency
  – Can not call in below order

      Stub.cleanup
      ServiceClient.cleanup



• Two are two memory leak bugs in 1.4, 1.4.1 only
  fix 1 bug
Axis2 1.5(.6) fix
• Fix the bug AXIS2-4007 AXIS2-4163
  //Stub
  protected void finalize() throws Throwable {
          super.finalize();
          cleanup();
  }

  public void cleanup() throws AxisFault {
          // _service.getAxisConfiguration().removeService(_service.getName());
          _serviceClient.cleanup();
  }
Implement issue
• Forget to cleanup
  – Container object: add only, no remove
  – Resource object: apply only, no return/close


• Cleanup dependency
  – One object cleanup depend on other objects
  – Two object cleanup/two method has order
    dependency
Design Issue
• AxisConfiguration   is a global shared object
  – Usually only 1 instance even in client side.


• Purpose for put service/endpoint map in this
  global object AxisConfiguration ?
Design Issue
• Message Dispatch in server side
// RequestURIBasedServiceDispatcher
public AxisService findService(MessageContext messageContext) throws AxisFault {

          AxisConfiguration registry = configurationContext.getAxisConfiguration();

           AxisService axisService = registry.getService(values[0]);

           // If the axisService is not null we get the binding that the request came to add
           // add it as a property to the messageContext
           if (axisService != null) {
                 Map endpoints = axisService.getEndpoints();
                 if (endpoints != null) {
                     if (endpoints.size() == 1) {
                            messageContext.setProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME,
                           endpoints.get(axisService.getEndpointName()));
                     } else {
                         String endpointName = values[0].substring(values[0].indexOf(".") + 1);
                         messageContext.setProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME,
                         endpoints.get(endpointName));
                     }
                 }
            }

           return axisService;
}
Design Issue
• Service is ‘singleton’ in server side
   // AxisConfiguration
   public AxisService getService(String name) throws AxisFault {
           AxisService axisService = (AxisService) allServices.get(name);
           if (axisService != null) {
               if (axisService.isActive()) {
                    return axisService;
               } else {
                    throw new AxisFault(Messages
                             .getMessage("serviceinactive", name));
               }
           } else {
               axisService = (AxisService) allEndpoints.get(name);
               if (axisService != null) {
                    if (axisService.isActive()) {
                        return axisService;
                    } else {
                        throw new AxisFault(Messages
                                 .getMessage("serviceinactive", name));
                    }
               }
           }
           return null;
       }
Design Issue
• Client side
  – (Usually) New instance every method invocation
  – No need for message routing
     • Why still register in Axi2Configuration ?

      axisConfig = configContext.getAxisConfiguration();
      if (axisService == null) {
          axisService = createAnonymousService();
      }
      this.axisService = axisService;
      if (axisConfig.getService(axisService.getName()) == null) {
          axisService.setClientSide(true);
          axisConfig.addService(axisService);
      } else {
          …
      }

       …

More Related Content

What's hot

Sql injection
Sql injectionSql injection
Sql injection
Hemendra Kumar
 
Use ScyllaDB Alternator to Use Amazon DynamoDB API, Everywhere, Better, More ...
Use ScyllaDB Alternator to Use Amazon DynamoDB API, Everywhere, Better, More ...Use ScyllaDB Alternator to Use Amazon DynamoDB API, Everywhere, Better, More ...
Use ScyllaDB Alternator to Use Amazon DynamoDB API, Everywhere, Better, More ...
ScyllaDB
 
Paper sharing_Edge based intrusion detection for IOT devices
Paper sharing_Edge based intrusion detection for IOT devicesPaper sharing_Edge based intrusion detection for IOT devices
Paper sharing_Edge based intrusion detection for IOT devices
YOU SHENG CHEN
 
Kafka replication apachecon_2013
Kafka replication apachecon_2013Kafka replication apachecon_2013
Kafka replication apachecon_2013
Jun Rao
 
How to use packet tracer
How to use packet tracerHow to use packet tracer
How to use packet tracer
Yunita Siswanti
 
Level Up! - Practical Windows Privilege Escalation
Level Up! - Practical Windows Privilege EscalationLevel Up! - Practical Windows Privilege Escalation
Level Up! - Practical Windows Privilege Escalation
jakx_
 
Lessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmarkLessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmark
Sergey Petrunya
 
Redis vs Infinispan | DevNation Tech Talk
Redis vs Infinispan | DevNation Tech TalkRedis vs Infinispan | DevNation Tech Talk
Redis vs Infinispan | DevNation Tech Talk
Red Hat Developers
 
Redshift performance tuning
Redshift performance tuningRedshift performance tuning
Redshift performance tuning
Carlos del Cacho
 
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricksQuery Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Jaime Crespo
 
Scylla Summit 2022: Migrating SQL Schemas for ScyllaDB: Data Modeling Best Pr...
Scylla Summit 2022: Migrating SQL Schemas for ScyllaDB: Data Modeling Best Pr...Scylla Summit 2022: Migrating SQL Schemas for ScyllaDB: Data Modeling Best Pr...
Scylla Summit 2022: Migrating SQL Schemas for ScyllaDB: Data Modeling Best Pr...
ScyllaDB
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
Manikanda kumar
 
Introduction to Storm
Introduction to Storm Introduction to Storm
Introduction to Storm
Chandler Huang
 
Apache Kafka
Apache KafkaApache Kafka
Apache Kafka
Diego Pacheco
 
Firewall DMZ Zone
Firewall DMZ ZoneFirewall DMZ Zone
Firewall DMZ Zone
NetProtocol Xpert
 
Deep Dive into Cassandra
Deep Dive into CassandraDeep Dive into Cassandra
Deep Dive into Cassandra
Brent Theisen
 
Square Engineering's "Fail Fast, Retry Soon" Performance Optimization Technique
Square Engineering's "Fail Fast, Retry Soon" Performance Optimization TechniqueSquare Engineering's "Fail Fast, Retry Soon" Performance Optimization Technique
Square Engineering's "Fail Fast, Retry Soon" Performance Optimization Technique
ScyllaDB
 
Monitoring Kafka without instrumentation using eBPF with Antón Rodríguez | Ka...
Monitoring Kafka without instrumentation using eBPF with Antón Rodríguez | Ka...Monitoring Kafka without instrumentation using eBPF with Antón Rodríguez | Ka...
Monitoring Kafka without instrumentation using eBPF with Antón Rodríguez | Ka...
HostedbyConfluent
 
Choosing A Proxy Server - Apachecon 2014
Choosing A Proxy Server - Apachecon 2014Choosing A Proxy Server - Apachecon 2014
Choosing A Proxy Server - Apachecon 2014
bryan_call
 
Oracle GoldenGate and Apache Kafka: A Deep Dive Into Real-Time Data Streaming
Oracle GoldenGate and Apache Kafka: A Deep Dive Into Real-Time Data StreamingOracle GoldenGate and Apache Kafka: A Deep Dive Into Real-Time Data Streaming
Oracle GoldenGate and Apache Kafka: A Deep Dive Into Real-Time Data Streaming
Michael Rainey
 

What's hot (20)

Sql injection
Sql injectionSql injection
Sql injection
 
Use ScyllaDB Alternator to Use Amazon DynamoDB API, Everywhere, Better, More ...
Use ScyllaDB Alternator to Use Amazon DynamoDB API, Everywhere, Better, More ...Use ScyllaDB Alternator to Use Amazon DynamoDB API, Everywhere, Better, More ...
Use ScyllaDB Alternator to Use Amazon DynamoDB API, Everywhere, Better, More ...
 
Paper sharing_Edge based intrusion detection for IOT devices
Paper sharing_Edge based intrusion detection for IOT devicesPaper sharing_Edge based intrusion detection for IOT devices
Paper sharing_Edge based intrusion detection for IOT devices
 
Kafka replication apachecon_2013
Kafka replication apachecon_2013Kafka replication apachecon_2013
Kafka replication apachecon_2013
 
How to use packet tracer
How to use packet tracerHow to use packet tracer
How to use packet tracer
 
Level Up! - Practical Windows Privilege Escalation
Level Up! - Practical Windows Privilege EscalationLevel Up! - Practical Windows Privilege Escalation
Level Up! - Practical Windows Privilege Escalation
 
Lessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmarkLessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmark
 
Redis vs Infinispan | DevNation Tech Talk
Redis vs Infinispan | DevNation Tech TalkRedis vs Infinispan | DevNation Tech Talk
Redis vs Infinispan | DevNation Tech Talk
 
Redshift performance tuning
Redshift performance tuningRedshift performance tuning
Redshift performance tuning
 
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricksQuery Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
 
Scylla Summit 2022: Migrating SQL Schemas for ScyllaDB: Data Modeling Best Pr...
Scylla Summit 2022: Migrating SQL Schemas for ScyllaDB: Data Modeling Best Pr...Scylla Summit 2022: Migrating SQL Schemas for ScyllaDB: Data Modeling Best Pr...
Scylla Summit 2022: Migrating SQL Schemas for ScyllaDB: Data Modeling Best Pr...
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 
Introduction to Storm
Introduction to Storm Introduction to Storm
Introduction to Storm
 
Apache Kafka
Apache KafkaApache Kafka
Apache Kafka
 
Firewall DMZ Zone
Firewall DMZ ZoneFirewall DMZ Zone
Firewall DMZ Zone
 
Deep Dive into Cassandra
Deep Dive into CassandraDeep Dive into Cassandra
Deep Dive into Cassandra
 
Square Engineering's "Fail Fast, Retry Soon" Performance Optimization Technique
Square Engineering's "Fail Fast, Retry Soon" Performance Optimization TechniqueSquare Engineering's "Fail Fast, Retry Soon" Performance Optimization Technique
Square Engineering's "Fail Fast, Retry Soon" Performance Optimization Technique
 
Monitoring Kafka without instrumentation using eBPF with Antón Rodríguez | Ka...
Monitoring Kafka without instrumentation using eBPF with Antón Rodríguez | Ka...Monitoring Kafka without instrumentation using eBPF with Antón Rodríguez | Ka...
Monitoring Kafka without instrumentation using eBPF with Antón Rodríguez | Ka...
 
Choosing A Proxy Server - Apachecon 2014
Choosing A Proxy Server - Apachecon 2014Choosing A Proxy Server - Apachecon 2014
Choosing A Proxy Server - Apachecon 2014
 
Oracle GoldenGate and Apache Kafka: A Deep Dive Into Real-Time Data Streaming
Oracle GoldenGate and Apache Kafka: A Deep Dive Into Real-Time Data StreamingOracle GoldenGate and Apache Kafka: A Deep Dive Into Real-Time Data Streaming
Oracle GoldenGate and Apache Kafka: A Deep Dive Into Real-Time Data Streaming
 

Similar to Axis2 client memory leak

Programming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidProgramming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for Android
Emanuele Di Saverio
 
Think Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJS
Adam L Barrett
 
Avoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.js
cacois
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disqus
zeeg
 
Aplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e JetpackAplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e Jetpack
Nelson Glauber Leal
 
Seastar @ NYCC++UG
Seastar @ NYCC++UGSeastar @ NYCC++UG
Seastar @ NYCC++UG
Avi Kivity
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015
Leonardo Borges
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
Bruno Scopelliti
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
Stuart Roebuck
 
Grand Central Dispatch
Grand Central DispatchGrand Central Dispatch
Grand Central Dispatch
cqtt191
 
Celery - A Distributed Task Queue
Celery - A Distributed Task QueueCelery - A Distributed Task Queue
Celery - A Distributed Task Queue
Duy Do
 
Node.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListenerNode.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListener
Islam Sharabash
 
MongoDB World 2019: Life In Stitch-es
MongoDB World 2019: Life In Stitch-esMongoDB World 2019: Life In Stitch-es
MongoDB World 2019: Life In Stitch-es
MongoDB
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
KatyShimizu
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
KatyShimizu
 
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixOSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
Manish Pandit
 
FaaS by Microsoft: Azure Functions and Azure Durable Functions
FaaS by Microsoft: Azure Functions and Azure Durable FunctionsFaaS by Microsoft: Azure Functions and Azure Durable Functions
FaaS by Microsoft: Azure Functions and Azure Durable Functions
Christian Lechner
 
An Introduction to Celery
An Introduction to CeleryAn Introduction to Celery
An Introduction to Celery
Idan Gazit
 
Seastar @ SF/BA C++UG
Seastar @ SF/BA C++UGSeastar @ SF/BA C++UG
Seastar @ SF/BA C++UG
Avi Kivity
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
Alex Tumanoff
 

Similar to Axis2 client memory leak (20)

Programming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidProgramming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for Android
 
Think Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJS
 
Avoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.js
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disqus
 
Aplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e JetpackAplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e Jetpack
 
Seastar @ NYCC++UG
Seastar @ NYCC++UGSeastar @ NYCC++UG
Seastar @ NYCC++UG
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Grand Central Dispatch
Grand Central DispatchGrand Central Dispatch
Grand Central Dispatch
 
Celery - A Distributed Task Queue
Celery - A Distributed Task QueueCelery - A Distributed Task Queue
Celery - A Distributed Task Queue
 
Node.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListenerNode.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListener
 
MongoDB World 2019: Life In Stitch-es
MongoDB World 2019: Life In Stitch-esMongoDB World 2019: Life In Stitch-es
MongoDB World 2019: Life In Stitch-es
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
 
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixOSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
 
FaaS by Microsoft: Azure Functions and Azure Durable Functions
FaaS by Microsoft: Azure Functions and Azure Durable FunctionsFaaS by Microsoft: Azure Functions and Azure Durable Functions
FaaS by Microsoft: Azure Functions and Azure Durable Functions
 
An Introduction to Celery
An Introduction to CeleryAn Introduction to Celery
An Introduction to Celery
 
Seastar @ SF/BA C++UG
Seastar @ SF/BA C++UGSeastar @ SF/BA C++UG
Seastar @ SF/BA C++UG
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
 

More from feng lee

Guice in athena
Guice in athenaGuice in athena
Guice in athena
feng lee
 
Bloom filter
Bloom filterBloom filter
Bloom filter
feng lee
 
Hadoop 安装
Hadoop 安装Hadoop 安装
Hadoop 安装
feng lee
 
Mysql story in poi dedup
Mysql story in poi dedupMysql story in poi dedup
Mysql story in poi dedup
feng lee
 
Effective java - concurrency
Effective java - concurrencyEffective java - concurrency
Effective java - concurrency
feng lee
 
Maven
MavenMaven
Maven
feng lee
 

More from feng lee (6)

Guice in athena
Guice in athenaGuice in athena
Guice in athena
 
Bloom filter
Bloom filterBloom filter
Bloom filter
 
Hadoop 安装
Hadoop 安装Hadoop 安装
Hadoop 安装
 
Mysql story in poi dedup
Mysql story in poi dedupMysql story in poi dedup
Mysql story in poi dedup
 
Effective java - concurrency
Effective java - concurrencyEffective java - concurrency
Effective java - concurrency
 
Maven
MavenMaven
Maven
 

Recently uploaded

Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 

Recently uploaded (20)

Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 

Axis2 client memory leak

  • 2. Outline • Issue & diagnosis • Postmortem from technique point – Axis2 1.4/1.4.1/1.5.6 client – Implement & design issue
  • 3. Issue CServer exhaust 8G memory -> memory leak
  • 4. diagnosis jmap –histo pid num #instances #bytes class name ---------------------------------------------- 1: 1001744 246906600 [C //char array 2: 2855952 137085696 edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap$Segment 3: 282338 115692192 [I // int array 4: 677362 102508648 [Ljava.util.HashMap$Entry; 5: 192117 99164392 [B // byte array 6: 2856122 91732120 [Ledu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap$HashEntry; 7: 2855952 91390464 edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock$NonfairSync 8: 1337498 53499920 java.lang.String 9: 433634 43130120 [Ljava.lang.Object; 10: 597908 38266112 java.util.HashMap From the histogram, the memory leak is caused by Axis2. 1) The main change in this release is using web service client (axis2 1.4.1) 2) char[] / edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap 3) Google ‘axis2 1.4.1 concurrentHashMap memory leak‘
  • 5. diagnosis jmap –dump:file=cdump pid • We got a 2.39G memory heap dump – Very fast, less than 30 seconds (because 8G memory in production) • Problem : too big to open in dev box – Need enough physical memory – (May) need 64 bit OS – Try Jhat/Jprofile/YJP/Jmat eclipse plugin (windows/2G) Open by Jmat standalone application
  • 7. diagnosis Hashtable allEndPoints holds more than 2k axis2 endpoint instances
  • 8. diagnosis All of the endpoint instances are about FavoriteService 1) Confirm in the code, only FavoriteService related did not call cleanup
  • 9. Axis2 1.4 memory leak • Reproduce for( int i=0;i<count; i++) { VersionStub stub = new VersionStub(configContext,null); GetVersion request = new GetVersion(); stub.getVersion(request); }
  • 10. Axis2 1.4 memory leak • Informal Model (OO design) AxisConfiguration Map allServices = new Hashtable(); Map allEndpoints = new Hashtable();
  • 11. Axis2 1.4 memory leak • Cause : Stub Initiation, add into AxisConfiguration //Init, Add allServices.put(serviceName, axisService); .. allEndpoints.put(serviceName + "." + endpointName, axisService);
  • 12. Axis2 1.4 memory leak • Cause : Stub Finalize //Stub protected void finalize() throws Throwable { super.finalize(); cleanup(); } public void cleanup() throws AxisFault { _service.getAxisConfiguration().removeService(_service.getName()); } //AsixConiguration public synchronized void removeService(String name) throws AxisFault { AxisService service = (AxisService) allServices.remove(name); if (service != null) { AxisServiceGroup serviceGroup = service.getAxisServiceGroup(); serviceGroup.removeService(name); log.debug(Messages.getMessage("serviceremoved", name)); } }
  • 13. Axis2 1.4 memory leak • Cause : Client Finalize //ServiceClient protected void finalize() throws Throwable { super.finalize(); cleanup(); } public void cleanup() throws AxisFault { … axisConfiguration.removeServiceGroup(serviceGroupName); … } //AsixConiguration public AxisServiceGroup removeServiceGroup(String serviceGroupName) throws AxisFault { … Iterator services = axisServiceGroup.getServices(); while (services.hasNext()) { AxisService axisService = (AxisService) services.next(); allServices.remove(axisService.getName()); … } …
  • 14. Axis2 1.4 memory leak • Cause //Init, Add allServices.put(serviceName, axisService); .. allEndpoints.put(serviceName + "." + endpointName, axisService); //Cleanup(Finalize), Remove allServices.put(serviceName, axisService); • Memory Leak : allEndpoints
  • 15. Axis2 1.4.1 fix • Fix the bug AXIS2-3870 //AsixConiguration.removeServiceGroup //removes the endpoints to this service String serviceName = axisService.getName(); String key = null; for (Iterator iter = axisService.getEndpoints().keySet().iterator(); iter.hasNext();){ key = serviceName + "." + (String)iter.next(); this.allEndpoints.remove(key); }
  • 16. Axis2 1.4.1 memory leak • Reproduce for( int i=0;i<count; i++) { VersionStub stub = new VersionStub(configContext,null); GetVersion request = new GetVersion(); stub.getVersion(request); stub.cleanup(); } Programmer: 1.4 has memory leak issue, so call cleanup
  • 17. Axis2 1.4.1 memory leak • Cause : Stub Finalize (no change) //Stub protected void finalize() throws Throwable { super.finalize(); cleanup(); } public void cleanup() throws AxisFault { _service.getAxisConfiguration().removeService(_service.getName()); } //AsixConiguration public synchronized void removeService(String name) throws AxisFault { AxisService service = (AxisService) allServices.remove(name); if (service != null) { AxisServiceGroup serviceGroup = service.getAxisServiceGroup(); serviceGroup.removeService(name); log.debug(Messages.getMessage("serviceremoved", name)); } }
  • 18. Axis2 1.4.1 memory leak • Cause: Client Finalize (no change) //ServiceClient protected void finalize() throws Throwable { super.finalize(); cleanup(); } public void cleanup() throws AxisFault { … axisConfiguration.removeServiceGroup(serviceGroupName); … }
  • 19. Axis2 1.4.1 memory leak • Cause: Client Finalize (no change) //AsixConiguration public AxisServiceGroup removeServiceGroup(String serviceGroupName) throws AxisFault { … Iterator services = axisServiceGroup.getServices(); while (services.hasNext()) { AxisService axisService = (AxisService) services.next(); allServices.remove(axisService.getName()); … for (Iterator iter = axisService.getEndpoints().keySet().iterator(); iter. key = serviceName + "." + (String)iter.next(); this.allEndpoints.remove(key); } … } Servce are already removed from ServiceGroup in Stub cleanup … } The while loop would never enter
  • 20. Axis2 1.4.1 memory leak • Cause – Stub cleanup and ServiceClient cleanup have dependency – Can not call in below order Stub.cleanup ServiceClient.cleanup • Two are two memory leak bugs in 1.4, 1.4.1 only fix 1 bug
  • 21. Axis2 1.5(.6) fix • Fix the bug AXIS2-4007 AXIS2-4163 //Stub protected void finalize() throws Throwable { super.finalize(); cleanup(); } public void cleanup() throws AxisFault { // _service.getAxisConfiguration().removeService(_service.getName()); _serviceClient.cleanup(); }
  • 22. Implement issue • Forget to cleanup – Container object: add only, no remove – Resource object: apply only, no return/close • Cleanup dependency – One object cleanup depend on other objects – Two object cleanup/two method has order dependency
  • 23. Design Issue • AxisConfiguration is a global shared object – Usually only 1 instance even in client side. • Purpose for put service/endpoint map in this global object AxisConfiguration ?
  • 24. Design Issue • Message Dispatch in server side // RequestURIBasedServiceDispatcher public AxisService findService(MessageContext messageContext) throws AxisFault { AxisConfiguration registry = configurationContext.getAxisConfiguration(); AxisService axisService = registry.getService(values[0]); // If the axisService is not null we get the binding that the request came to add // add it as a property to the messageContext if (axisService != null) { Map endpoints = axisService.getEndpoints(); if (endpoints != null) { if (endpoints.size() == 1) { messageContext.setProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME, endpoints.get(axisService.getEndpointName())); } else { String endpointName = values[0].substring(values[0].indexOf(".") + 1); messageContext.setProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME, endpoints.get(endpointName)); } } } return axisService; }
  • 25. Design Issue • Service is ‘singleton’ in server side // AxisConfiguration public AxisService getService(String name) throws AxisFault { AxisService axisService = (AxisService) allServices.get(name); if (axisService != null) { if (axisService.isActive()) { return axisService; } else { throw new AxisFault(Messages .getMessage("serviceinactive", name)); } } else { axisService = (AxisService) allEndpoints.get(name); if (axisService != null) { if (axisService.isActive()) { return axisService; } else { throw new AxisFault(Messages .getMessage("serviceinactive", name)); } } } return null; }
  • 26. Design Issue • Client side – (Usually) New instance every method invocation – No need for message routing • Why still register in Axi2Configuration ? axisConfig = configContext.getAxisConfiguration(); if (axisService == null) { axisService = createAnonymousService(); } this.axisService = axisService; if (axisConfig.getService(axisService.getName()) == null) { axisService.setClientSide(true); axisConfig.addService(axisService); } else { … } …