Wednesday, September 25, 2019

Performance Testing using Jmeter


Jmeter offers testing of resources which are both static or dynamic in nature. For e.g.

-Static pages, javascript , html
-Dynamic content - JSP, servlet, sjsx call, rest api endpoint.

This tool help us find the
-Max concurrent users the application can support
-Average throughput application serves with the available configuration
-Performance Report, 95%tile, 99 %tile response time. The respective response time tells us x% of the requests took y ms. So the administration can decide if the response can be treated as an acceptable behavior based on the SLA.

The testing performed are Load Testing and Stress Testing (max number of users application can work).

Configuration required:
Number of threads: Number of users going to access simultaneously.
Loop count-: Number of time the testing would be executed.
Ramp-up Period: The time it takes to start all the threads
Check the proxy configuration to connect to internet. remove it if internet is connected via a proxy.
If your application is deployed on n nodes which will be accessing the endpoint. Consider total load from all the client nodes to  get the performance stats.

Throughput: Higher the throughput better is the server performance.
Deviation: Deviation from the average. Lower the deviation, better is the consistency

Sunday, September 15, 2019

Elastic Search Aggregation


ES Provides aggregated data based on  a search query.

Aggregation Structure:
"aggregations" : {
    "<aggregation_name>" : {
        "<aggregation_type>" : {
            <aggregation_body>
        }
        [,"meta" : {  [<meta_data_body>] } ]?
        [,"aggregations" : { [<sub_aggregation>]+ } ]?
    }
    [,"<aggregation_name_2>" : { ... } ]*
}

#Sub Aggregation; Aggregation can be further refined after adding inner aggregation
#Aggregation_name is a logical name that user defines it.
#aggregation_type is added based on the nature of aggregation. For eg avg_price to calculate average of the price bucket.

GET employees/_search
{
  "_source": false,
  "query": {
    "exists": {
      "field": "employee.address"
    }
  },
  "aggs": { // aggregations
    "address": {
      "terms": {
        "field": "employee_name",
        "size": 500
      }
    }
  }
}
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-min-aggregation.html

Elastic Search Analyzer


During query processing, the content is analysed by the analysis module. It consists of  analyzer, tokenizer, tokenfilters and charfilters.


POST _analyze
{
   "analyzer": "standard",
   "text": "Today's weather is beautiful"
}
The above will produce tokens based on the standard analyser.

analyzer, tokenizer, tokenfilters and charfilters.
POST _analyze
{
   "analyzer": "standard",
   "text": "Today's weather is beautiful"
}

Token produced: today's, weather ,is,beautilful

PUT index_mapping_analysis
{
   "settings": {
      "analysis": {
         "analyzer": {
            "my_grammar_analyzer": {
               "type": "standard",
               "max_token_length": 5,
               "stopwords": "_english_"
            }
         }
      }
   }
}
POST index_4_analysis/_analyze
{
   "analyzer": "my_grammar_analyzer",
   "text": "Today's weather is beautiful"
}
Token Produced: today,s,weath,er,beaut,iful 

Sunday, September 8, 2019

Elastic Search - Update Indexed Data

POST twitter/_update_by_query
{
  "script": {
    "source": "ctx._source.likes++",
    "lang": "painless"
  },
  "query": {
    "term": {
      "user": "kimchy"
    }
  }
}

Adding/Removing aliases
POST /_aliases
{
"actions" : [
    {
        "add/remove" : {
             "index" : "<index_name>",
             "alias" : "<alias_name>",
             "is_write_index" : true
        }
    }
  ]
}

Elastic Search Re-indexing Data






POST _reindex
{
  "source": {
    "index": "twitter"
  },
  "dest": {
    "index": "new_twitter",
    "version_type": "internal"
  }
}


Setting version_type to external will cause Elasticsearch to preserve the version from the source, create any documents that are missing, and update any documents that have an older version in the destination index than they do in the source index:

When we want to create the missing document in the target index

POST _reindex
{
  "conflicts": "proceed",
  "source": {
    "index": "twitter"
  },
  "dest": {
    "index": "new_twitter",
    "op_type": "create"
  }
}