Skip to content

Commit

Permalink
added benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyaven committed Dec 27, 2023
1 parent 0c0047d commit 342fdbe
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 52 deletions.
104 changes: 53 additions & 51 deletions notebooks/aws/aws.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"metadata": {},
"outputs": [],
"source": [
"region = 'us-east-1'"
"regions = \"'ap-southeast-2', 'us-east-1'\"\n",
"region = 'ap-southeast-2'"
]
},
{
Expand All @@ -29,7 +30,7 @@
"split_part(instanceState, '\\n', 3) as instanceState, \n",
"count(*) as num_instances\n",
"FROM aws.ec2.instances \n",
"WHERE region = '$region' \n",
"WHERE region IN ($regions)\n",
"GROUP BY split_part(instanceState, '\\n', 3)"
]
},
Expand All @@ -49,9 +50,9 @@
"outputs": [],
"source": [
"%%stackql\n",
"SELECT instanceType, COUNT(*) as num_instances \n",
"SELECT region, instanceType, COUNT(*) as num_instances\n",
"FROM aws.ec2.instances\n",
"WHERE region = '$region'\n",
"WHERE region IN ($regions)\n",
"GROUP BY instanceType"
]
},
Expand Down Expand Up @@ -95,10 +96,8 @@
"metadata": {},
"outputs": [],
"source": [
"# get multiple regions asynchronously\n",
"from pystackql import StackQL\n",
"stackql = StackQL(download_dir='/srv/stackql', output='pandas')\n",
"stackql.executeStmt(\"REGISTRY PULL aws\")"
"%%stackql\n",
"select PolicyName, Arn from aws.iam.policies where region = '$region'"
]
},
{
Expand All @@ -107,25 +106,27 @@
"metadata": {},
"outputs": [],
"source": [
"# get multiple regions asynchronously\n",
"import nest_asyncio, json\n",
"nest_asyncio.apply()\n",
"import pandas as pd\n",
"\n",
"regions = [\"ap-southeast-2\", \"us-east-1\"]\n",
"\n",
"queries = [\n",
" f\"\"\"\n",
" SELECT '{region}' as region, instanceType, COUNT(*) as num_instances\n",
" FROM aws.ec2.instances\n",
" WHERE region = '{region}'\n",
" GROUP BY instanceType\n",
" \"\"\"\n",
" for region in regions\n",
"]\n",
"\n",
"instances_df = await stackql.executeQueriesAsync(queries)\n",
"instances_df"
"%%stackql\n",
"SELECT region, function_name\n",
"FROM aws.lambda.functions\n",
"WHERE region IN (\n",
"'us-east-1',\n",
"'us-east-2',\n",
"'us-west-1',\n",
"'us-west-2',\n",
"'ap-south-1',\n",
"'ap-northeast-3',\n",
"'ap-northeast-2',\n",
"'ap-southeast-1',\n",
"'ap-southeast-2',\n",
"'ap-northeast-1',\n",
"'ca-central-1',\n",
"'eu-central-1',\n",
"'eu-west-1',\n",
"'eu-west-2',\n",
"'eu-west-3',\n",
"'eu-north-1',\n",
"'sa-east-1')"
]
},
{
Expand All @@ -134,8 +135,18 @@
"metadata": {},
"outputs": [],
"source": [
"%%stackql\n",
"select PolicyName, Arn from aws.iam.policies where region = '$region'"
"functions_list = _.to_dict(orient='records')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pystackql import StackQL\n",
"stackql = StackQL(download_dir='/srv/stackql', app_root='/jupyter/.stackql', output='pandas')\n",
"stackql.executeStmt(\"REGISTRY PULL aws\")"
]
},
{
Expand All @@ -144,28 +155,11 @@
"metadata": {},
"outputs": [],
"source": [
"import nest_asyncio, json\n",
"# get all functions across all regions asynchronously using pystackql\n",
"import nest_asyncio\n",
"nest_asyncio.apply()\n",
"import pandas as pd\n",
"\n",
"regions= [\"us-east-1\",\"us-east-2\",\"us-west-1\",\"us-west-2\",\"ap-south-1\",\"ap-northeast-3\",\"ap-northeast-2\",\"ap-southeast-1\",\n",
" \"ap-southeast-2\",\"ap-northeast-1\",\"ca-central-1\",\"eu-central-1\",\"eu-west-1\",\"eu-west-2\",\"eu-west-3\",\"eu-north-1\",\n",
" \"sa-east-1\"]\n",
"\n",
"get_fns = [\n",
" f\"\"\"\n",
" SELECT *\n",
" FROM aws.lambda.functions\n",
" WHERE region = '{region}'\n",
" \"\"\"\n",
" for region in regions\n",
"]\n",
"\n",
"functions_df = await stackql.executeQueriesAsync(get_fns)\n",
"functions_list = functions_df.to_dict(orient='records')\n",
"\n",
"get_fns_details = [\n",
" f\"\"\"\n",
" f'''\n",
" SELECT \n",
" function_name,\n",
" region,\n",
Expand All @@ -177,13 +171,21 @@
" FROM aws.lambda.function\n",
" WHERE region = '{function['region']}'\n",
" AND data__Identifier = '{function['function_name']}'\n",
" \"\"\"\n",
" '''\n",
" for function in functions_list\n",
"]\n",
"\n",
"function_details_df = await stackql.executeQueriesAsync(get_fns_details)\n",
"function_details_df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f"
]
}
],
"metadata": {
Expand Down
92 changes: 92 additions & 0 deletions notebooks/aws/benchmarks.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pystackql import StackQL\n",
"stackql = StackQL(download_dir='/srv/stackql', execution_concurrency_limit=-1, app_root='/jupyter/.stackql', output='pandas')\n",
"stackql.executeStmt(\"REGISTRY PULL aws\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"regions = [\n",
"'us-east-1',\n",
"'us-east-2',\n",
"'us-west-1',\n",
"'us-west-2',\n",
"'ap-south-1',\n",
"'ap-northeast-3',\n",
"'ap-northeast-2',\n",
"'ap-southeast-1',\n",
"'ap-southeast-2',\n",
"'ap-northeast-1',\n",
"'ca-central-1',\n",
"'eu-central-1',\n",
"'eu-west-1',\n",
"'eu-west-2',\n",
"'eu-west-3',\n",
"'eu-north-1',\n",
"'sa-east-1'\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# threading test 1 - stackql native golang threading\n",
"\n",
"regions_list = \"','\".join(regions)\n",
"stackql_query = f\"\"\"\n",
"SELECT region, function_name\n",
"FROM aws.lambda.functions\n",
"WHERE region IN ('{regions_list}')\n",
"\"\"\"\n",
"\n",
"import time\n",
"\n",
"start_time = time.time()\n",
"result = stackql.execute(stackql_query)\n",
"end_time = time.time()\n",
"\n",
"print(f\"Time taken (Go threading): {end_time - start_time} seconds\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# threading test 2 - python threading model\n",
"\n",
"queries = [f\"SELECT region, function_name FROM aws.lambda.functions WHERE region = '{region}'\" for region in regions]\n",
"\n",
"import nest_asyncio\n",
"nest_asyncio.apply()\n",
"\n",
"start_time = time.time()\n",
"result = await stackql.executeQueriesAsync(queries)\n",
"end_time = time.time()\n",
"print(f\"Time taken (Python async): {end_time - start_time} seconds\")"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 1 addition & 1 deletion scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
/srv/stackql/stackql --version
echo "starting stackql server..."
nohup /srv/stackql/stackql --http.response.pageLimit=-1 --pgsrv.port=5466 srv &
nohup /srv/stackql/stackql --execution.concurrency.limit=-1 --http.response.pageLimit=-1 --pgsrv.port=5466 srv &
echo "stackql server started"
start-notebook.sh --NotebookApp.token=''

0 comments on commit 342fdbe

Please sign in to comment.