Azure Database for PostgreSQLでApache AGEを試してみる(続き)
- Azure Database for PostgreSQLでApache AGEを試してみる
- 少し書き直してみた(6.4倍ぐらい速くなった)
- Azure Database for PostgreSQL + Apache AGEのインデックス
上記エントリーをまとめて、書き直したコードが以下。
#!/usr/bin/env python3.11
# -*- coding: utf-8 -*-
# builtin modules
import argparse
import json
import os
import resource
import sys
import threading
import time
# third party modules
while True:
try:
import pandas as pd
break
except:
os.system(f"{sys.executable} -m pip install pandas")
while True:
try:
import psycopg as pg
from psycopg.rows import dict_row, namedtuple_row
break
except:
os.system(f"{sys.executable} -m pip install psycopg")
while True:
try:
import psycopg_pool
break
except:
os.system(f"{sys.executable} -m pip install psycopg-pool")
while True:
try:
from pyvis.network import Network
break
except ModuleNotFoundError:
os.system(f"{sys.executable} -m pip install pyvis")
# Constants
AG_GRAPH_NAME = "actorfilms"
# Global Variables
connection_string = """
host=your_server.postgres.database.azure.com
port=5432
dbname=postgres
user=your_account
password=admin_password
options='-c search_path=ag_catalog,"$user",public'
"""
# See, https://docs.python.org/ja/3/library/resource.html
resource.setrlimit(resource.RLIMIT_NOFILE, (8192, 9223372036854775807))
# See, https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/concepts-limits
# If number of connections exceeds 8192, you will get the error.
pg_pool = psycopg_pool.ConnectionPool(connection_string, max_size = 1703, min_size = 128)
# exit with redden message
def exit_with_error(msg) -> None:
sys.exit("