jeudi 4 janvier 2018

Django server slow either because of requests module or socket module

My website gives deatails about different servers. I have used requests to check which server ILO IP is not working through http and which is not.

After using requests.. the page loads super slow! I'm also using socket to translate DNS name to IPS.

My server checks ILO Ips of many servers and if the server is broken it shows the IP as a text and if not it shows a link(THE IP) to the ILO.

Do you know how to make the server load much faster? Thanks.. P.S Timeout 0.04 helped a bit.. but not fast enough..

index.html-

Liquid error: Unknown operator is

            <td width="100%"><center></center></td>
            Liquid error: Unknown operator is
            <td style='white-space: nowrap'>

models.py -

from django.db import models
# Create your models here.
import requests
import socket
class serverlist(models.Model):
    ServerName = models.CharField(max_length = 30,blank=True)
    Owner = models.CharField(max_length = 50,blank=True)
    Project = models.CharField(max_length = 30,blank=True)
    Description = models.CharField(max_length = 255,blank=True)
    IP = models.CharField(max_length = 30,blank=True)
    ILO = models.CharField(max_length = 30,blank=True)
    Rack = models.CharField(max_length = 30,blank=True)
    Status = models.CharField(max_length = 30,blank=True)
    def checkUrlAvailable(self):
        ip_check = 'http://' + self.ServerName + ".ilo.lab.radcom.co.il"
        resp = requests.head(ip_check,timeout=0.04,allow_redirects=False)
        if resp.status_code == 303:
            return True
        else:
            return False
    def convertIPtoDNS(self):
        socket.setdefaulttimeout(1)
        dns_name= self.ServerName + ".ilo.lab.radcom.co.il"
        ip = socket.gethostbyname(dns_name)
        return ip




Aucun commentaire:

Enregistrer un commentaire