Thursday, 28 July 2022

Git Prune


Agenda

  • Introduction

  • Git Prune

  • Usage

  • Example

  • Differences

    • git prune

    • git fetch --prune

    • git remote prune

  • Conclusion


Introduction

We do commit after every small change we make in the source code to be sure all the changes are reserved. But in reality when we make final push to master there would be several commits we may need to ignore or detach. 

As we know git is very careful of about deleting data, and hard to lose any commits. Due to this the downside is lots of stale data is reserved even if its not going to used.

One of the method to do clean up is using prune.


Git Prune

The git prune command is an internal house keeping utility that is used to clean up the unreachable or orphaned git objects.


Unreachable objects are those which are not accessible by any refs.

For an example, say you have made two commits. And the latest have reset commit to different head, by calling the git reset <commit id> command. Though the git log command will not show the commit info. But internally git still stores as dangling object.

Usually we as users need not call git prune directly whereas call git gc the git garbage collection command. As this will prune along with many other house keeping tasks.


Usage


Here we will prune syntax and its options.


  • git prune –-dry-run

      To not to perform the prune operation rather show the output what it will be performed


  • git prune –-verbose

      Will report all the actions and its associated objects 


  • git prune –-progress

      Will show the progress made by the command


  • git prune –-expire <time>

      Will remove only for the objects which are older than the given time


Example


# Cloning one of the git repository, else you can create your own repository using git init

% git clone https://github.com/hasura/graphql-engine.git

Cloning into 'graphql-engine'...

remote: Enumerating objects: 66417, done.

remote: Counting objects: 100% (5997/5997), done.

remote: Compressing objects: 100% (2118/2118), done.

remote: Total 66417 (delta 3840), reused 5775 (delta 3718), pack-reused 60420

Receiving objects: 100% (66417/66417), 77.20 MiB | 3.11 MiB/s, done.

Resolving deltas: 100% (44018/44018), done.

Updating files: 100% (5104/5104), done.


# Create sample file and insert first line

% cat >> hello.txt

This is the first line 


# Add and commit the file

% git add hello.txt

% git commit -m "add the file hello"

[master bec274f52] add the file hello

1 file changed, 1 insertion(+)

create mode 100644 hello.txt


# Update the file adding second line

% cat >> hello.txt

This is the second line

% cat hello.txt

This is the first line

This is the second line


# Add and commit the same file again

% git add hello.txt

% git commit -m "added second line in the file hello"

[master 3af6fea8d] added second line in the file hello

1 file changed, 1 insertion(+)


# Check the log, need to find two git commit

% git log

commit 3af6fea8dbb44973ddeed856036d0792d15a4ad7 (HEAD -> master)

Author: xxxxxxx <xxxxxxx@xxxxxxx>

Date: Sun Jun 13 20:29:00 2021 +0530

added second line in the file hello


commit bec274f5264140c9ff1f9b8b6f956c69295a29d4

Author: xxxxxxx <xxxxxxx@xxxxxxx>

Date: Sun Jun 13 20:27:39 2021 +0530

add the file hello


# Lets now reset the head version of the file to the previous commit

% git reset --hard bec274f5264140c9ff1f9b8b6f956c69295a29d4

HEAD is now at bec274f52 add the file hello 


# Check the git log, the last created commit would have been vanished

% git log

commit bec274f5264140c9ff1f9b8b6f956c69295a29d4 (HEAD -> master)

Author: xxxxxxx <xxxxxxx@xxxxxxx>

Date: Sun Jun 13 20:27:39 2021 +0530

add the file hello


# Find the dangling commit, as said git still remembers

% git fsck --lost-found

Checking object directories: 100% (256/256), done.

Checking objects: 100% (66417/66417), done.

dangling commit 3af6fea8dbb44973ddeed856036d0792d15a4ad7


# Check the detail if it was the same commit

% git show 3af6fea8dbb44973ddeed856036d0792d15a4ad7

commit 3af6fea8dbb44973ddeed856036d0792d15a4ad7

Author: xxxxxxx <xxxxxxx@xxxxxxx>

Date: Sun Jun 13 20:29:00 2021 +0530

added second line in the file hello

diff --git a/hello.txt b/hello.txt

index d3e2104b9..81bc58de5 100644

--- a/hello.txt

+++ b/hello.txt

@@ -1 +1,2 @@

This is the first line

+This is the second line


# When prune is run now, there might be no affect. As git might be maintaining the reference, possibly not fully detached.

# Run the reflog to expire all the entries that are older than now 

# Note: This is not advisable to do, prefer git gc always than git prune

% git reflog expire --expire=now --expire-unreachable=now --all


# Before running the prune, always run the dry run to check the changes

% git prune --dry-run --verbose --progress --expire=now 

142cc07007d0107e8ff91b28e2a7b078a6f56d1c tree

3af6fea8dbb44973ddeed856036d0792d15a4ad7 commit

81bc58de5525b0c16f8cb74b89799017b6986981 blob


# Run the actual prune command

% git prune --verbose --progress --expire=now

142cc07007d0107e8ff91b28e2a7b078a6f56d1c tree

3af6fea8dbb44973ddeed856036d0792d15a4ad7 commit

81bc58de5525b0c16f8cb74b89799017b6986981 blob


# Now the dangling commit would have been cleared

% git fsck --lost-found

Checking object directories: 100% (256/256), done.

Checking objects: 100% (66417/66417), done.



Differences

  • git fetch --prune

    • Another way to clean up, is for the branches by again using prune option but now with git fetch and git remove. 

    • Orphaned branches are branches that are not connected to any others and have been left unused.

    • It is a good practice to prune the branches that are not being used.

    • The simplest way to prune is by using git fetch -–prune. This will fetch all the remote branch refs and delete the remote refs that are no longer in used in the remote repository.

    • Its advisable to use the dry run before execution, such as,

        $ git fetch --prune origin --dry-run 


  • git remote prune

    • Same as git fetch -–prune, this command will also remove the refs to the branches which don't exist on the remote.

    • But the difference, we can use git remote prune when we would want to perform prune and do not fetch the remote data.

    • The git maintains both the local/origin and remote /origin refs. Using this command it will only prune the refs from the remote/origin. This way it will safely leave the local/origin untouched.


  • git prune

    • As seen above this is different from git remote prune, as it deletes only locally the detached commits. 


Conclusion

Today we have seen the usage and different options of the git prune. Hope henceforth you will have handy way to maintain your git clean.



Reference and Credits: 

https://www.atlassian.com/git/tutorials/git-prune

https://external-preview.redd.it/Tboo_FCn9vTgptJmXn5-rcz-SQEyjpl7hitfpihXYAY.jpg?auto=webp&s=4a4d37b370447857ec1a3254a81e261c1ad89e48


Original Blog Posted in OSFY

https://www.opensourceforu.com/2021/11/git-prune-check-out-this-housekeeping-utility/

For further research and updates maintaining the blog here.


Thursday, 21 July 2022

Hash in C

 

Agenda

  • Hash
  • Hash Collision
  • Rehashing
  • Chaining
  • Algorithm
  • Application


Hash

Hash is most common used data structure in every day programming. If you are python developer every time you use dict or set, it internally uses hashing. In perl you call it as hash using {}. Or HashSet or HashMap in Java.

There are different ways to save data, for example in a variable, arrays, structures and so on. Hash is yet another way to save data. To say the most simple reason is if we have key and value pair we can use hash for quick save and retrieval.

There are three perquisites for hashing, given below:

    • key
    • value
    • hash function
      • Key: Unique data to store the value
      • Value: Data which needs to be associated with the Key

Hash Function: Function used compute the hash code from the given key. The given hash code will be the index for us to save value. For each key the hash function is expected to give us unique hash code(index).

Fig 1: Explains each key goes through hash function and based on its output index values are saved.

Credits: https://www.tutorialspoint.com/data_structures_algorithms/hash_data_structure.htm


Hash Collision

Hash Collision is a flaw of the hash function which generates same hash code for two different keys.

Eg: We have two keys k1 and k2, when the h(k1) and h(k2) generates same hash code, how will the data stored and retrieved.

A good hash function is one that minimizes the collisions and spreads the records uniformly throughout the table.

There are two basic techniques to resolve this,  rehashing and chaining.


Rehashing

The simplest method to place the record in the next available position of the array. This techniques is also  called linear probing.

If array location h(key) is already occupied by a record. A general rehash(rh) function is called rh(h(key)). If it is already occupied then again rh(rh(h(key))) is called.

However it is possible for the rehash function to called in a loop indefinitely, even if there are many empty functions.


Chaining

Another method of resolving the hash clashes is called chaining. It involves keeping the distinct linked list for all the records whose keys hash to the particular value.

Below find the nice representation of chained hash table, credits to wikipedia.

Fig 2: A small phone book as hash table using chaining mechanism

Credits : https://en.wikipedia.org/wiki/Hash_table


Algorithm

  • Create an array of structure
  • Define a hash function to accept key as input and return the index. Note: There are several ways to define the hash function, we have chose the basic one.
  • Search function
    • Get the index by calling the hash function passing the key
    • Validate if the index exists
    • If exists loop through the index
      • Match the given in each of the chain structure pointed to the index
      • If found return the structure address pointer
      • Else return NULL
  • Insert function
    • Call the Search function passing the key to determine whether the given key is already present
    • If it is present, override with the new value
    • Else create a new entry
    • Return NULL if there is no memory for the new entry


Source code:

/* pointer array size */

#define HASHSIZE 101



/* structure to save the key and value */

struct nlist {

struct nlist *next; /* next entry in chain */

char *key; /* defined key */

char *value; /* replacement text which holds value */

}



/* pointer table to save list of structures */

static struct nlist *hashtab[HASHSIZE]



/* hash: form hash value for string s which is key */

unsigned hash(char *s) {

/* unsigned value ensures non negative */

unsigned hashval;



/* adds each character's value of the string to form scrambled combination of the previous ones */

for (hashval =0; *s != '\0'; s++) {

hashval = *s + 31 * hashval;

}


/* modulo ensures the index is within the array size */

return hashval % HASHSIZE

}



/* lookup: look for s in the hash table */

struct nlist *lookup(char *s) {

struct nlist *np;


for (np = hashtab[hash[(s)]; np != NULL; np = np->next) {

if(strcmp(s, np->key) == 0) {

return np;

}

}


/* key not found in hash table */

return NULL;

}



/* insert: add the key and value to the hash table */

struct nlist *insert(char *key, char *value) {

struct nlist *np;

unsigned hashval;


/* call the lookup function to validate if already key exists */

/* if not exists allocate the memory for the new structure */

if ((np = lookup(key)) == NULL) {

np = (struct nlist *) malloc(sizeof*np));



/* if unable to allocate memory for the structure */

/* or unable to copy key in the struct key */

/* return NULL as it no more memory could be allocated */

if (np == NULL || (np->key = strdup(key)) == NULL) {

return NULL;

}


/* get the index for the key, by calling the hash function */

hashval = hash(key);


/* point the newly created structure's next to the existing index value's struct */

np->next = hashtab[hashval];



/* point the current pointer to the head of the index */

/* so the newly created pointer will be pointed as first */

hashtab[hashval] = np;

} else {

/* if already the key is available, free up its value so we can override below */

free((void *) np->value);

}



/* save the value to the key's structure */

if((np->value = strdup(value)) == NULL) {

return NULL;

}

}


Note: Chaining mechanism is used above to avoid hash collisions


Application

Now that we have seen about hash and its implementation, lets see its common applications. 

In Cryptography hash functions are used to produce the hashed output from the input, which is impossible to reverse from output to input.

Password verification is another important usage of cryptography hash function. When you enter the password, from the client the password is hashed and sent to server. As the server already knows the hash of your password it can simply compare it. If there is an middleman attack your password is still unknown to the hacker.

Rabin Karp string search algorithm, uses hashing to find set of patterns in the string. And the real world application of it is to detect plagiarism.


Reference and Credits: 

K&R C Programming Language

Practical Cryptography for DevelopersHash Functions - Practical Cryptography for Developers


Original Blog Posted in OSFY

https://www.opensourceforu.com/2021/10/working-with-hash-in-c/

For further research and updates maintaining the blog here.


Thursday, 14 July 2022

Memory Allocation Methods


Agenda

  • Introduction

  • First Fit

  • Best Fit

  • Worst Fit

  • Conclusion


Introduction

    Each time when malloc (memory allocation) or free is called you get pointer to the allocated memory address or free it back for others to use. Dynamic memory management requires frequent memory allocation and freeing up the space. 

    How to manage the freed and used space. How do we know which address/slots to be used while the next malloc call.  To answer above questions, there are three methods which we can used for managing the memory.

    Let's discuss each method in detail. Below is the current state of one large block of 1024bytes. We will see how each method uses for allocation of memory.

0 1023

Address

0

250

550

700

900

950 - 1023

Allocation

Details


Block 1 allocated


Size = 250

Free 1



Size = 300

Block 2 allocated


Size = 150

Free 2



Size = 200

Block 3 allocated


Size = 50

Free 3



Size = 73

Note: In this blog we would see only first bit algorithm. Each of these methods have their own use cases. But in general First Fit method is usually preferred.


First Fit

In the First Fit method, the free list is traversed sequentially to find the first free block which can hold the requested size. 

Once we the block is found, one the below two operations are performed.

  • If the size is equal to the requested amount, it is removed from the free list

  • Else split into two parts. Here the first portion remains on the list and second is allocated.

    The reason of allocating the second part is the operations of updating the list could be avoided by just making change in size of the free node.

Lets now try to allocate 200, and see how the structure gets changed.

0 1023

Address

0

250

350

550

700

900

950 - 1023

Allocation

Details


Block 1 allocated


Size = 250

Free 1



Size = 100

Block 2 allocated (new)

Size = 200

Block 3 allocated


Size = 150

Free 2



Size = 200

Block 4 allocated


Size = 50

Free 3



Size = 73


As you could see the memory is allocated in the second part, leaving the previous block pointing to the first part. Else if we would have used first part, we need to make change in the list by pointing the previous to the second part. 


Now lets see the algorithm:

p = freeblock;

alloc = null;  // pointer to store the allocated size n's address

q = null;


// find the free node which can allocate the given size n

while ( p != null && size(p) < n) {

q = p;  // previous node

p = next(p); 

} 


// if there is block large enough found

if ( p != null ) {

s = size(p);

alloc = p + s – n; // alloc contains the address of the desired block


// if the block size matches the requested size, remove the block from the free list

if ( s == n) {

// if the match is found in the first block update the pointer of freeblock to point the next of free block

if ( q == null ) {

freeblock = next(p);

} else {

next(q) = next(p);

}

} else {

size(p) = s – n;  // adjust the size of the remaining free block

}

}


Best Fit

    In the Best Fit method, the smallest of the free block is choose whose size is greater than or equal to the requested size n. In this algorithm has to traverse the entire list to find the apt match.

Let's now try to allocate 200, and see how the structure gets changed.

0 1023

Address

0

250

550

700

900

950 - 1023

Allocation

Details


Block 1 allocated


Size = 250

Free 1



Size = 300

Block 2 allocated


Size = 150

Block 3 allocated (new)

Size = 200

Block 4 allocated


Size = 50

Free 2



Size = 73

    As you could see the memory Free 1 was ignored, Free 2 was updated to Block 3. Also now the Free 1 is pointing to Free 3 (now changed to Free 2). As the requested size matches the allocated size and its removed from the free pointer list.


Worst Fit

    In the Worst Fit method, the algorithm always allocates the portion of the largest free block in memory. The logic behind this method that by using a small number of very large blocks repeatedly to satisfy the majority of the requests, many of the moderately sized blocks will be left unfragmented.

Let's now try to allocate 200, and see how the structure gets changed.

0 1023

Address

0

250

350

550

700

900

950 - 1023

Allocation

Details


Block 1 allocated


Size = 250

Free 1



Size = 100

Block 2 allocated (new)

Size = 200

Block 3 allocated


Size = 150

Free 2



Size = 200

Block 4 allocated


Size = 50

Free 3



Size = 73

As Free 1 hold the maximum of 300, the memory is allocated there. Lets try to allocate 100, though we have first Free size with 100 it will still allocate in Free 2 which is the maximum now.


Conclusion

Each method has its own patterns. Let's see it with example.

First Fit is best case

In the below scenario only First Fit was able to serve all the requests. 

Request

Blocks remaining using


First Fit

Best Fit

Worst Fit

Initially

110, 54

110, 54

110, 54

25

85, 54

110, 29

85, 54

70

15, 54

40, 29

15, 54

50

15, 4

Cannot be full filled

15, 4

14

1, 4


1, 4

1

0, 4


1, 3

4

0, 0


Cannot be full filled

Notes: Let's try to understand how the First Fit serves best.

  • Here we have 110 in block 1 and 54 in block 2, initially
  • Now comes the request of 25 to allocate, lets see if we try to allocate in each method:
    • First Fit after allocation 85, 54
    • Best Fit after allocation 110, 29
    • Worst Fit after allocation 85, 54
  • Next we want to allocate 70, 
    • First Fit after allocation 15, 54
    • Best Fit after allocation 40, 29
    • Worst Fit after allocation 15, 54
  • Next we want to allocate 50,
    • First Fit after allocation 15, 4
    • In Best Fit we cannot allocate
    • Worst Fit after allocation 15, 4
  • So now repeating the requests, we could see of the First Fit is able to serve all the requests whereas in other even though there is space it cannot allocate.


Best Fit is best case

In the below scenario only Best Fit was able to serve all the requests. 

Request

Blocks remaining using


First Fit

Best Fit

Worst Fit

Initially

110, 54

110, 54

110, 54

50

60, 54

110, 4

60, 54

100

Cannot be full filled

10, 4

Cannot be full filled


Worst Fit is best case

In the below scenario only Worst Fit was able to serve all the requests. 

Request

Blocks remaining using


First Fit

Best Fit

Worst Fit

Initially

200, 300, 100

200, 300, 100

200, 300, 100

150

50, 300, 100

50, 300, 100

200, 150, 100

100

50, 200, 100

50, 300, 0

100, 150, 100

125

50, 75, 100

50, 175, 0

100, 50, 100 

100

50, 75, 0

50, 75, 0

0, 50, 100

100

Cannot be full filled

Cannot be full filled

0, 50, 0

As said, each have their own patterns. Though first fit method is generally preferred.


References and Credits

https://www.codingninjas.com/blog/2021/09/04/memory-management-techniques-in-operating-system/

Data Structures using C and C++ by Yedidyah Langsam, Moshe J. Augenstein, Aaron M. Tenenbanum 


Original Blog Posted in OSFY

https://www.opensourceforu.com/2021/10/memory-allocation-methods-an-overview/

For further research and updates maintaining the blog here.


Thursday, 7 July 2022

API Testing and Performance Testing Using JMeter




To ensure the quality of the software product different tests has been performed. Once such test is Load Testing. Load Testing is a kind of Performance Testing that helps in determining how the application behaves when multiple users/requests hit the application simultaneously.

From many tools helping us to resolve this, for now we will see how Apache JMeter (JMeter) an Open Source tool helps us to achieve this, what are the pros and cons using this tool.


What is JMeter and Why do we need 

JMeter is an Open Source testing desktop based application. It is 100% pure Java application used as a performance testing tool for analysing and measuring the performance in variety of graphical reports.

We can perform load testing, stress testing and functional testing for the applications.

If there are any flaws in application such as buffer overflow, memory leaks using this we can easily simulate the situation in our own environment, and avoid the Prod issue surprises.

Using JMeter we can achieve all this easily, with minimum to no knowledge in coding. Yay!!


Installation

Please follow the below detailed steps on the installation of JMeter on the respective operating system. 

  • Windows & Linux: https://jmeter.apache.org/usermanual/get-started.html 

  • Mac: https://psychowhiz.medium.com/install-jmeter-on-mac-25531bc2b2ad


JMeter Supports

JMeter supports following and more types of the applications that can be tested with the tool.

  • Websites – HTTPS and HTTP

  • Web services – REST, SOAP and Graphql

  • Database servers

  • FTP servers

  • LDAP servers

  • Mail servers – SMTP, POP3, IMAP

  • TCP Servers


Elements of JMeter

There are different elements in JMeter each performing a task to achieve our goal. Below are few elements which will be important to know perquisites:

  • Thread Group: Collection of Threads, each thread represents one user accessing the application in the thread. Ideally it simulates one real user making one request to the application server. We can have multiple number of threads configured here.

  • Samplers: Type of request, such as FTP, HTTP, etc.

  • Listeners: Shows the results in different formats.

  • Configuration: Setup defaults and variables for later use by the samplers.

  • Assertions: Validate response from the server is expected or not.


Load Testing

Prerequisites

Here we will test Google Home Page

  • Open installed JMeter

  • Click File -> New

  • Update the Name to GoogleHomePageTestPlan

  • Click Save Icon # it will save as the .jmx file 

Figure 1: Save the test plan into .jmx file


Step 1: Thread Group

In the Thread Group, we need to know about the below properties.

  • Number of Threads: N number of users connecting to the target URL

  • Ramp-Up Period: Allows to include delay while requests hitting the target, for example if we have 10 threads and 5 ramp-up period : the 10 requests should hit the target within 5 seconds adding 0.5 seconds delay between each request. This is primarily used when we don't want to over bun the server and as well as client. But if you want to do the Stress Testing try tweaking the property based on the use case. 

  • Loop Count: N number of time the test case to be executed, for example if you have number of threads 5 and loop count as 2, total 10 times the request will hit the target.


Figure 2: Difference between Thread count and Loop count

Credits: https://medium.com/skyshidigital/performance-testing-with-jmeter-for-dummies-541ea9171464


Steps:

  • Right Click GoogleHomePageTestPlan -> Add -> Threads (Users) -> Thread Group

  • Good practices to rename the name, readability matters. For this am updating the name as GoogleHomePageTestSearch

  • Update “Number of Threads (users)”: 5

Note: Please do not give more than 10, they might block us ;)



Figure 3: Thread group creation page


Step 2: Samplers

  • Right Click GoogleHomePageTestSearch -> Add -> Sampler -> HTTP Request

  • Lets rename again. Update the name with: GoogleHomePageTestSearchHTTPRequest

  • Update the below parameters

    • Server Name of IP: www.google.com

    • Port Number: None [optional]

    • Protocol (http): HTTP / HTTPS [optional]

    • Method: GET 

    • Path: /search

    • Parameters:

      • Click Add

        • Name: q

        • Value: JMeter

Figure 4: HTTP Sampler creation page 


  • For POST Method with JSON input

    • We can give input, under Body Data give the JSON format input

    • If needed you can add sure to add header details under “HTTP Header Manager” and authorization under “HTTP Authorization Manager”. Both are under GoogleHomePageTestSearch -> Add -> Config Element


Step 3: Listeners

  • Right Click GoogleHomePageTestSearchHTTPRequest -> Add -> Listener -> View Results Tree

  • Rename the name. Update the Name: GoogleHomePageTestSearchHTTPRequestResultTree

  • Click the Run -> Green Button

  • View the results in Sampler result, Response data and Request

  • Different types of charts are available to see the results crisply. And the link is https://www.edureka.co/blog/load-testing-using-jmeter/

Figure 5: Result page after execution of the Sampler


Step 4: Configuration – [optional]

  • As this step is optional, but we can take parameters to the search

  • Right Click GoogleHomePageTestSearchHTTPRequest -> Add -> Config Element -> User Defined

  • Setup the Variables

Figure 6: User defined variables page

  • Using the defined variable, we need to use it by enclosing it in ${<variable>}

Figure 7: Redefine value to use the user defined variable

  • After Run: Check the “q” is substituted with the defined variable and HTTP Request is also holding the “q” value 

Figure 8: Result tree, the user defined variable has been used in the GET request

  • The same format can be used while Data Driven Testing, where in you would want to induce dynamic values to the service. We need to configure the CSV Data Set Config under Config Element.


Step 5: Assertions – [optional]

  • The response assertion control panel lets you pattern strings to be compared against various fields of the request or response

  • Right Click GoogleHomePageTestSearchHTTPRequest -> Add -> Assertions -> Response Assertion

  • Setup the Validations: Positive Validation: Checking whether the Response Code is 200

Figure 9: Define the rules to evaluate response from the Sampler execution

  • Result would be positive, as we have that Response Code is 200

Figure 10: Response is 200, hence the test result is shown passed (green)

  • There are many different combination of assertions, including by adding regex rather hard coded values.


Bonus Step

We all like Bonus!!

Record and Run

  • Let's say we have many rest apis to be tested in single page, we got to create so many Samplers manually, which we will get bored doing. For example in Amazon, there will several api hit to form the Home Page, such as Deals, Products, Best Sellers, User Menu and so many others.

  • Here we have a solution to Record and Run. Shared the step by step example in the below reference link. Link is:

    https://jmeter.apache.org/usermanual/jmeter_proxy_step_by_step.pdf

  • Note: For now Firefox browser supports this feature. Also we need to make sure we have access to update the settings in the Firefox.

Command Line

  • You can run the JMeter from the command line, and can have its output redirected to an html as well. The non GUI mode brings in more flexibility when running heavy loads. But the configuration can be still done using the GUI, as well the results can be analyzed. 

  • Sample Command : $ jmeter -n -t GoogleHomePageTestSearch.jmx -l GoogleHomePageTestSearch.jtl -e -o googletestoutput

    • -n: to run in non-gui mode

    • -t: name of JMX file having the Test Plan

    • -l: Name of JTL(JMeter text logs) file to log results

    • -e: generate report dashboard after load test

    • -o: output folder where to generate the report dashboard after load test. Folder must not exist or be empty

  • Output:

Figure 11: HTML output of the command line execution


Pros of JMeter

  • Open Source: JMeter is an open source software, so no licensing costs

  • Ease to Use: The user can install and use JMeter easily

  • Platform independent: As JMeter is 100% Java based, so it is platform independent and can run on multiple platforms.

  • Customisable: Since JMeter is open source, developers can customize its source code as per their specific requirements. Also there is prescript and postscript execution process where we can run customisable code in Java or Jpython.

  • Data driven testing: The CSV Data Set Config, allows you to read different parameters from text file and convert into parameters which can be used in making dynamic requests.

  • Record and Playback: JMeter provides record and playback options alone with drag and drop feature which makes it easier and faster to create scripts.

  • Supports distributed load testing: JMeter supports distributed load testing features in which we can create master-slave setup for carrying out load test on multiple machines. Link is : https://jmeter.apache.org/usermanual/jmeter_distributed_testing_step_by_step.html

  • Good community support and Documentation: JMeter has many online tutorials(edureka I really like) and helping community support. It also has freely available plugins that helps in different aspects of script creation and analysis.

  • Reporting: Helps to visualise test results. As see before, test results can be displayed in a different format such as chart, table, tree, log file, html and etc. 


Cons of JMeter

  • Passwords are saved as plain text, involves risk when the JMX file is accidentally shared

  • It supports only Java or Java backed languages for custom coding


Other Similar Tools

  • LoadView

  • LoadUI

  • NeoLoad

  • WEBLOAD

  • LoadRunner


Conclusion

  • One of the most used tool for performance and api testing. Definitely can be used to make sure the web applications are meeting the performance benchmarks.

  • The feature list of JMeter is exhaustive, this is just a sample of its usage. 

  • The User Manual will have the detailed description of each its features, link is https://jmeter.apache.org/usermanual/index.html


References

https://www.edureka.co/blog/load-testing-using-jmeter/

https://jmeter.apache.org/usermanual/get-started.html

https://www.guru99.com/jmeter-tutorials.html



Original Blog Posted in OSFY
https://www.opensourceforu.com/2021/08/test-your-software-with-jmeter/
For further research and updates maintaining the blog here.

Scarcity Brings Efficiency: Python RAM Optimization

  In today’s world, with the abundance of RAM available, we rarely think about optimizing our code. But sooner or later, we hit the limits a...