当我进行负载测试时,我收到 dial tcp : socket: Too much open files 错误。通过设置 ulimit 其工作正常,但是在不设置 ulimit 的情况下还有其他解决方案吗?
代码:
package main
import (
"fmt"
"io"
"io/ioutil"
"encoding/json"
"net/http"
)
type Struct_Response struct {
Meta struct {
Requestid string
}
}
var HttpClient = &http.Client{}
func main(){
apiUrl := "http://example.com"
JsonStr :="teststr"
conn_token :="1233333333333"
req, err := http.NewRequest("POST", apiUrl, bytes.NewBuffer(JsonStr))
if err!=nil{
fmt.Println(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("requestid", "1234")
req.Header.Set("Authorization", "Bearer "+conn_token)
req.Header.Set("Connection", "close")
resp, err := HttpClient.Do(req)
req.Close=true
if resp!=nil && resp.StatusCode==200 {
body, _ …Run Code Online (Sandbox Code Playgroud) from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
from rest_framework_simplejwt.views import TokenObtainPairView
from rest_framework_simplejwt.utils import datetime_to_epoch
SUPERUSER_LIFETIME = datetime.timedelta(minutes=1)
class MyTokenObtainPairSerializer(TokenObtainPairSerializer):
@classmethod
def get_token(cls, user):
token = super(MyTokenObtainPairSerializer, cls).get_token(user)
token['name'] = user.username
token['user_id'] = user.id
if user.is_superuser:
#token.set_exp(from_time=starttime,lifetime=SUPERUSER_LIFETIME)
token.payload['exp'] = datetime_to_epoch(token.current_time + SUPERUSER_LIFETIME)
return token
class MyTokenObtainPairView(TokenObtainPairView):
serializer_class = MyTokenObtainPairSerializer
Run Code Online (Sandbox Code Playgroud)
我已经尝试过此代码(以下链接:我们如何在django中的jwt令牌中为不同的用户分配不同的到期时间)。这段代码更新了刷新令牌的到期时间,但是我想使用simplejwt模块在django中更新访问令牌的到期时间。任何建议,请。