Async - api

Buenas.
Tengo un codigo asincronico que lo que hace es enviar json por API, la idea de hacerlo asincronico es enviar gran cantidad, hoy en dia eh realizado millones de pruebas enviar 1000 reg, 10.000 reg 500.000reg y hasta 1.000.000 de reg pero lo tiempo son malisimos 2000 reg en un minuto por ejemplo.
Adjunto el codigo a ver si alguien me puede orientar o ayudar por si algo que hice esta mal y me perjudica la performance.
Muchas Gracias!

import os
import aiohttp
import asyncio
import json
import readCfg
import utils
import re

conf = readCfg.Config()
url_post_ppeople = “”
pk_table = “”
type_api_response = “”

Funcion del armado de los Json que son enviados a la funcion de POST

def create_Json_Post(path_in_json, list_json, url, pk, type_api):

global url_post_ppeople
global pk_table
global type_api_response
global pk_insis
type_api_response = type_api
url_post_ppeople  = url
pk_insis = pk
pk_table = utils.to_insis_format(pk)

for fichero in list_json:
    jsonName = fichero.lower()        
    jNameRes = jsonName.rsplit(".", 1)[0]
    with open(os.path.join(path_in_json, jsonName), 'rb') as f:
        todos = json.load(f)
        registros = len(todos)
    # Funcion Asincronica de envio POST
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main(todos, jNameRes))

Funcion Asincronica que envia json mediante Api POST

async def get_tasks(session, url_post_ppeople, todo, headers):
results = []
results_dict = {}
try:
async with session.post(url_post_ppeople, json=todo, auth=aiohttp.BasicAuth(‘biwares.api’, ‘biwares.api’), headers=headers, ssl=False) as resp:
# Armado de la respuesta de Error que envia la API
status = resp.status
if status != 200:
try:
response_dict = json.loads(await resp.text())
except ValueError:
message = str(‘null’)
else:
message = response_dict[‘message’]

            msg = re.sub(r"[^a-zA-Z0-9]"," ",message)
            results = '{"'+ pk_table + '":null,"error_codigo": "'+ msg + '"}'
            # results = '{"'+ pk_table + '":null,"error_codigo":'+str(status)+ '}'
            #results = '{"manId":null,"error_codigo":'+str(status)+',"mensaje":"'+str(message)+'"}'   
  
        else:
            results = await resp.text()
            if type_api_response == 1:
                res = json.loads(results)

                #TODO para salvar credit card, si cambia la estructura del response q nos ayude dios
                for i in res['parameters']['parameter']:
                    if i['name'] == pk_insis.upper():
                        res_dormat = str(i['content']).replace('[','').replace(']','')
                        results = '{"'+ pk_table  + '":' + res_dormat + '}'
                        break



        return results
except aiohttp.ClientConnectorError as e:
    print('Connection Error', str(e))
    print('==>No hay conexión con el servidor ' + url_post_ppeople)
    exit()

async def main(todos, jNameRes):
sock_connect = int(conf.sock_connect)
timeout = aiohttp.ClientTimeout(sock_connect=sock_connect, total=None, sock_read=None)

async with aiohttp.ClientSession(timeout=timeout) as session:
    tasks = []
    headers = {'Accept': 'application/json','Content-Type': 'application/json', 'ignoreLoginService': 'true'}
    #TODO para test se usa 'operational-mode': 'SIM'
    # headers = {'Accept': 'application/json','Content-Type': 'application/json', 'ignoreLoginService': 'true', 'operational-mode': 'SIM'}
    
    for todo in todos:
        url = url_post_ppeople
        tasks.append(asyncio.ensure_future(get_tasks(session, url, todo, headers)))

    responses = await asyncio.gather(*tasks)
    data = {}
    data['item'] = []
    for results in responses:
        data['item'].append(results)

    # Armado del Json de respuesta
    with open(os.path.join(conf.json_folder_response, jNameRes.title()+'R'+'.json'), 'w', encoding="utf-8") as j:
        dict_str0 = str(data['item'])
        j.write(dict_str0)

    with open(os.path.join(conf.json_folder_response, jNameRes.title()+'R'+'.json'), 'rt', encoding="utf-8") as j:
        x = j.read()

    with open(os.path.join(conf.json_folder_response, jNameRes.title()+'R'+'.json'), 'wt', encoding="utf-8") as j:
        x = x.replace(":null", ":\"\"")
        x = x.replace("'", "")
        x = x.replace("},", "},\n")
        x = x.replace("\\", "")
        j.write(x)
    j.close()

   
    await session.close()