Skip to content

Commit 83e3d32

Browse files
committed
Updates README and set benchmark results
1 parent 2cb0a74 commit 83e3d32

File tree

4 files changed

+61
-17
lines changed

4 files changed

+61
-17
lines changed

README.md

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,90 @@
1-
# AxiosQueue.js
1+
## Why to use axios-queue-js?
22

3-
## Description
3+
The `axios-queue-js` is a lightweight wrapper of `axios` that enables you to make requests using a queue. In simple words, it improves significantly the performance of your requests, once no request is made unless there's an open slot for it. This lib works for both web and node environments and can be easily placed in codebases that already use `axios` to handle requests, even if they are using a custom client.
44

5-
AxiosQueue.js is a wrapper of axios which enables you to enqueue axios requests and run them in a pipeline.
5+
## Performance of axios with axios-queue-js
66

7-
## Instalation
7+
> All the following results were colleted by doing requests to a localhost server and all the scripts used the default configs for axios-queue-js.
88
9-
`npm install axios-queue-js` for npm users and `yarn add axios-queue-js` for yarn users.
9+
The following chart represents the performance of a node script trying to do 1k sequential requests using nothing but `axios`.
10+
11+
After almost 2min of execution, `axios` triggered an error that terminated the script, that was able to do and finish only 209 requests.
12+
13+
![axios chart](/benchmark-results/axios.png "axios chart")
14+
15+
Now you can see the results of the same test after using `axios` along with `axios-queue-js` in the script.
16+
17+
It's worth mentioning that all the 1k requests were successfully made in only 6 seconds. That is about **5x more requests being made in only 5% of the time**.
18+
19+
![axios-queue-js results](/benchmark-results/axios-queue-js.png "axios-queue-js results")
20+
21+
For the next chart we repreated the previous testing, but this time with **100k requests**.
22+
23+
As you can see below, `axios-queue-js` was able to make `axios` handle about **478x more requests in only 3x more time than axios did alone**.
24+
25+
![axios-queue-js results](/benchmark-results/axios-queue-js-100k.png "axios-queue-js results after 100k requests")
1026

1127
## Usage
1228

29+
You can install `axios-queue-js` by running a `npm install axios-queue-js` or `yarn add axios-queue-js` in your project. After that you can use it as follows.
30+
1331
```typescript
32+
// By using module imports
1433
import axios from 'axios-queue-js';
1534

1635
axios.get('https://endpoint.test.net').then((response) => {
17-
console.log('Hey look, I am getting a response using AxiosQueue.js :D');
36+
console.log('Hey look, I am getting a response using axios-queue-js :D');
1837
});
1938

2039
axios.post('https://endpoint.test.net', {}).then((response) => {
21-
console.log('Hey look, I am posting something and getting a response using AxiosQueue.js :D');
40+
console.log('Hey look, I am posting something and getting a response using axios-queue-js :D');
41+
});
42+
```
43+
44+
```typescript
45+
// By using commonjs
46+
const { default: axios } = require('axios-queue-js');
47+
48+
axios.get('https://endpoint.test.net').then((response) => {
49+
console.log('Hey look, I am getting a response using axios-queue-js :D');
50+
});
51+
52+
axios.post('https://endpoint.test.net', {}).then((response) => {
53+
console.log('Hey look, I am posting something and getting a response using axios-queue-js :D');
2254
});
2355
```
2456

2557
## Customizing
2658

27-
If you want to customize the queue length, you can create your own AxiosQueue.js and use it as a client, just like below.
59+
If you want to customize the queue length or even use an external axios client to handle the requests, you can create your own `AxiosQueueManager` instance and use it as you will. Eg.:
2860

2961
```typescript
62+
// By using module imports
63+
import axios from 'axios';
3064
import { AxiosQueueManager } from 'axios-queue-js';
3165

32-
const client = new AxiosQueueManager({ queueSize: 10 });
66+
const axiosQueueClient = new AxiosQueueManager({ queueSize: 10, client: axios.create() });
3367

34-
client.get('https://endpoint.test.net').then((response) => {
35-
console.log('Hey look, I am getting a response using AxiosQueue.js :D');
68+
axiosQueueClient.get('https://endpoint.test.net').then((response) => {
69+
console.log('Hey look, I am getting a response using axios-queue-js :D');
3670
});
3771
```
3872

39-
## Configuration
73+
```typescript
74+
// By using commonjs
75+
const axios = require('axios')
76+
const { AxiosQueueManager } = require('axios-queue-js');
77+
78+
const axiosQueueClient = new AxiosQueueManager({ queueSize: 10, client: axios.create() });
79+
80+
axiosQueueClient.get('https://endpoint.test.net').then((response) => {
81+
console.log('Hey look, I am getting a response using axios-queue-js :D');
82+
});
83+
```
4084

41-
As showed previously, you can create and configure your own AxiosQueueManager instance, which can receives an object with the following configs.
85+
Following is a table with all the possible properties that you can set when creating your own `AxiosQueueManager` instance.
4286

43-
| Key | Optional | Default Value | Type | Description |
44-
| --------- | -------- | ------------- | ------------- | --------------------------------------------------------- |
45-
| queueSize | True | 10 | Number | Represents the queue's maximum size |
46-
| client | True | axios.default | AxiosInstance | Can be set to use a custom axios instance in the requests |
87+
| Key | Optional | Default Value | Type | Description |
88+
| --------- | -------- | ------------- | ------------- | ----------------------------------------------------------------------------- |
89+
| queueSize | True | 10 | Number | Represents the queue's maximum size |
90+
| client | True | axios.default | AxiosInstance | Custom axios instance that will be used under the hood to handle the requests |
38 KB
Loading
23.1 KB
Loading

benchmark-results/axios.png

20.3 KB
Loading

0 commit comments

Comments
 (0)