forked from opensearch-project/opensearch-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added advanced index actions API guide & sample.
Signed-off-by: Djcarrillo6 <[email protected]> Updated CHANGELOG Signed-off-by: Djcarrillo6 <[email protected]> Updated CHANGELOG & link to sample. Signed-off-by: Djcarrillo6 <[email protected]> updated changelog (opensearch-project#522) Signed-off-by: saimedhi <[email protected]> Bump version to 2.3.2 (opensearch-project#524) Signed-off-by: saimedhi <[email protected]> Fix: typos. (opensearch-project#526) * Fix: typo. Signed-off-by: dblock <[email protected]> * Fix: typo. Signed-off-by: dblock <[email protected]> * Fixed its. Signed-off-by: dblock <[email protected]> * Added Visual Code settings to .gitignore. Signed-off-by: dblock <[email protected]> * Added loop type for async client. Signed-off-by: dblock <[email protected]> --------- Signed-off-by: dblock <[email protected]> Modified generator to generate api deprecation warnings (opensearch-project#527) Signed-off-by: saimedhi <[email protected]> Generate cat client from API specs (opensearch-project#529) Signed-off-by: saimedhi <[email protected]> Generate cluster client from API specs (opensearch-project#530) Signed-off-by: saimedhi <[email protected]> Added new guide & sample module for using index templates. (opensearch-project#531) Added index_template guide and sample Signed-off-by: Djcarrillo6 <[email protected]> Removed EOL Python3.5 & bumped urllib3 version to patch security vulnerability (opensearch-project#533) Updated CHANGELOG with pull # Updated CHANGELOG with pull # Updated CHANGELOG removed section. Updated CHANGELOG removed section again Signed-off-by: Djcarrillo6 <[email protected]> Align pool_maxsize for different connection pool implementations. (opensearch-project#535) * Align pool_maxsize for different connection pool implementations. Signed-off-by: dblock <[email protected]> * Document connection classes and settings. Signed-off-by: dblock <[email protected]> * Undo change in async for backwards compatibility. Signed-off-by: dblock <[email protected]> * Fix: typo. Signed-off-by: dblock <[email protected]> --------- Signed-off-by: dblock <[email protected]> Add micro benchmarks. (opensearch-project#537) * Align pool_maxsize for different connection pool implementations. Signed-off-by: dblock <[email protected]> * Added benchmarks. Signed-off-by: dblock <[email protected]> * Multi-threaded vs. async benchmarks. Signed-off-by: dblock <[email protected]> * Set pool size to the number of threads. Signed-off-by: dblock <[email protected]> * Added sync/async benchmark. Signed-off-by: dblock <[email protected]> * Report client-side latency. Signed-off-by: dblock <[email protected]> * Various updates to benchmarks, demonstrating threading improves throughput. Signed-off-by: dblock <[email protected]> * Bench info. Signed-off-by: dblock <[email protected]> * Fixup format. Signed-off-by: dblock <[email protected]> * Undo async maxsize. Signed-off-by: dblock <[email protected]> * Moved benchmarks folder. Signed-off-by: dblock <[email protected]> * Updated documentation and project description. Signed-off-by: dblock <[email protected]> --------- Signed-off-by: dblock <[email protected]>
- Loading branch information
1 parent
80b9681
commit 5edf6c0
Showing
52 changed files
with
3,683 additions
and
911 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
- [Benchmarks](#benchmarks) | ||
- [Start OpenSearch](#start-opensearch) | ||
- [Install Prerequisites](#install-prerequisites) | ||
- [Run Benchmarks](#run-benchmarks) | ||
|
||
## Benchmarks | ||
|
||
Python client benchmarks using [richbench](https://github.com/tonybaloney/rich-bench). | ||
|
||
### Start OpenSearch | ||
|
||
``` | ||
docker run -p 9200:9200 -e "discovery.type=single-node" opensearchproject/opensearch:latest | ||
``` | ||
|
||
### Install Prerequisites | ||
|
||
Install [poetry](https://python-poetry.org/docs/), then install package dependencies. | ||
|
||
``` | ||
poetry install | ||
``` | ||
|
||
Benchmarks use the code in this repository by specifying the dependency as `opensearch-py = { path = "..", develop=true, extras=["async"] }` in [pyproject.toml](pyproject.toml). | ||
|
||
### Run Benchmarks | ||
|
||
Run all benchmarks available as follows. | ||
|
||
``` | ||
poetry run richbench . --repeat 1 --times 1 | ||
``` | ||
|
||
Outputs results from all the runs. | ||
|
||
``` | ||
Benchmarks, repeat=1, number=1 | ||
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓ | ||
┃ Benchmark ┃ Min ┃ Max ┃ Mean ┃ Min (+) ┃ Max (+) ┃ Mean (+) ┃ | ||
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩ | ||
│ 1 client vs. more clients (async) │ 1.640 │ 1.640 │ 1.640 │ 1.102 (1.5x) │ 1.102 (1.5x) │ 1.102 (1.5x) │ | ||
│ 1 thread vs. 32 threads (sync) │ 5.526 │ 5.526 │ 5.526 │ 1.626 (3.4x) │ 1.626 (3.4x) │ 1.626 (3.4x) │ | ||
│ 1 thread vs. 32 threads (sync) │ 4.639 │ 4.639 │ 4.639 │ 3.363 (1.4x) │ 3.363 (1.4x) │ 3.363 (1.4x) │ | ||
│ sync vs. async (8) │ 3.198 │ 3.198 │ 3.198 │ 0.966 (3.3x) │ 0.966 (3.3x) │ 0.966 (3.3x) │ | ||
└───────────────────────────────────┴─────────┴─────────┴─────────┴─────────────────┴─────────────────┴─────────────────┘ | ||
``` | ||
|
||
Run a specific benchmark, e.g. [bench_sync.py](bench_sync.py) by specifying `--benchmark [name]`. | ||
|
||
``` | ||
poetry run richbench . --repeat 1 --times 1 --benchmark sync | ||
``` | ||
|
||
Outputs results from one benchmark. | ||
|
||
``` | ||
Benchmarks, repeat=1, number=1 | ||
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓ | ||
┃ Benchmark ┃ Min ┃ Max ┃ Mean ┃ Min (+) ┃ Max (+) ┃ Mean (+) ┃ | ||
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩ | ||
│ 1 thread vs. 32 threads (sync) │ 6.804 │ 6.804 │ 6.804 │ 3.409 (2.0x) │ 3.409 (2.0x) │ 3.409 (2.0x) │ | ||
└────────────────────────────────┴─────────┴─────────┴─────────┴─────────────────┴─────────────────┴─────────────────┘ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#!/usr/bin/env python | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# The OpenSearch Contributors require contributions made to | ||
# this file be licensed under the Apache-2.0 license or a | ||
# compatible open source license. | ||
|
||
import asyncio | ||
import uuid | ||
|
||
from opensearchpy import AsyncHttpConnection, AsyncOpenSearch | ||
|
||
host = "localhost" | ||
port = 9200 | ||
auth = ("admin", "admin") | ||
index_name = "test-index-async" | ||
item_count = 100 | ||
|
||
|
||
async def index_records(client, item_count): | ||
await asyncio.gather( | ||
*[ | ||
client.index( | ||
index=index_name, | ||
body={ | ||
"title": f"Moneyball", | ||
"director": "Bennett Miller", | ||
"year": "2011", | ||
}, | ||
id=uuid.uuid4(), | ||
) | ||
for j in range(item_count) | ||
] | ||
) | ||
|
||
|
||
async def test_async(client_count=1, item_count=1): | ||
clients = [] | ||
for i in range(client_count): | ||
clients.append( | ||
AsyncOpenSearch( | ||
hosts=[{"host": host, "port": port}], | ||
http_auth=auth, | ||
use_ssl=True, | ||
verify_certs=False, | ||
ssl_show_warn=False, | ||
connection_class=AsyncHttpConnection, | ||
pool_maxsize=client_count, | ||
) | ||
) | ||
|
||
if await clients[0].indices.exists(index_name): | ||
await clients[0].indices.delete(index_name) | ||
|
||
await clients[0].indices.create(index_name) | ||
|
||
await asyncio.gather( | ||
*[index_records(clients[i], item_count) for i in range(client_count)] | ||
) | ||
|
||
await clients[0].indices.refresh(index=index_name) | ||
print(await clients[0].count(index=index_name)) | ||
|
||
await clients[0].indices.delete(index_name) | ||
|
||
await asyncio.gather(*[client.close() for client in clients]) | ||
|
||
|
||
def test(item_count=1, client_count=1): | ||
loop = asyncio.new_event_loop() | ||
asyncio.set_event_loop(loop) | ||
loop.run_until_complete(test_async(item_count, client_count)) | ||
loop.close() | ||
|
||
|
||
def test_1(): | ||
test(1, 32 * item_count) | ||
|
||
|
||
def test_2(): | ||
test(2, 16 * item_count) | ||
|
||
|
||
def test_4(): | ||
test(4, 8 * item_count) | ||
|
||
|
||
def test_8(): | ||
test(8, 4 * item_count) | ||
|
||
|
||
def test_16(): | ||
test(16, 2 * item_count) | ||
|
||
|
||
def test_32(): | ||
test(32, item_count) | ||
|
||
|
||
__benchmarks__ = [(test_1, test_8, "1 client vs. more clients (async)")] |
Oops, something went wrong.