我用以下 views.py 創(chuàng)建了一個(gè) django apiimport datetimeimport osimport tracebackfrom logging.handlers import TimedRotatingFileHandlerfrom logging import Formatterfrom django.http import HttpResponseimport logging# from . import models as mimport pandas as pdimport jsonimport psycopg2 as pg# logger setupdef resp(status): //returns status codedef index(request): logger.info('request:' + str(request.GET)) obj = DAA() if request.method == "GET": // get values from url request if (condition): try: connection = pg.connect(dbname="dbname", user="user", password="password") cursor = connection.cursor() response = obj.level1(arguments) response = obj.level2(arguments) try: // check response except Exception as e: # add exception to log except Exception as e: # add exception to log if response : json_data = { "responseCode": 200, "version": "1.0.0", "results": [ // response ] } json_dump = json.dumps(json_data) return HttpResponse(json_dump, content_type='application/json') elif not response : json_dump = resp(400)使用上面的代碼,我面臨以下問題:在 jmeter 上為 100 多個(gè)用戶測試應(yīng)用程序時(shí),我收到錯誤“已經(jīng)有太多客戶端”,似乎是 postgres 數(shù)據(jù)庫的問題,如 conf 文件 [max_connections = 100] 但增加連接沒有似乎對我有用,所以請?zhí)岢銎渌ㄗh。即使為少于 100 個(gè)用戶運(yùn)行該應(yīng)用程序,我也收到此錯誤“RuntimeError:無法啟動新線程”,因此請建議如何解決此問題?注意:-請忽略編程錯誤,因?yàn)槲抑环窒砹宋业拇a的虛擬結(jié)構(gòu)。
添加回答
舉報(bào)
0/150
提交
取消