J
J
jenya77712018-04-01 12:12:53
Node.js
jenya7771, 2018-04-01 12:12:53

Is resource consumption very high when using socket?

Hello, I started using the tips, and after a while the load on the server is very large, the RAM is 1200, and the processor is loaded to the maximum. Konda did not use the tips, the indicators were like this, the processor was at zero, and the RAM was 95.

This is how the connection happens

const socket = io(config.api.socketHost, {
  autoConnect: true,
  reconnection: true,
  timeout: 35000,
  reconnectionDelay: 600,
  reconnectionDelayMax: 3500,
  query: {
    auth: config.api.socketKey
  }
})
.open();

const timeoutResponse = 45 * 1000
let conect = false
const key = config.api.socketKey

try {

  socket
  .on('connect', () => {

    logger.info('Connect to socket API')
    conect = true
  })
  .on('disconnect', () => {

    logger.error('Disconnect to socket API')
    conect = false
  })
  .on('connect_error', (error) => {

    logger.error('Error connect to socket API', error)
  })
  .on('connect_timeout', (error) => {

    logger.error('Сonnect to socket API timeout', error)
  })
  .on('reconnecting', (attempt) => {

    logger.warn('Error reconnecting to socket API', null, {
      attempt: attempt
    })
  })
  .on('reconnect_failed', (reconnectionAttempts) => {

    logger.warn('Failed connect to socket API', null, {
      reconnectionAttempts: reconnectionAttempts
    })
  })
  .on('reconnect_error', (error) => {

    logger.error('Error reconect to socket API', error)
  })
} catch (error) {

  logger.error('Error conect socket API', error)
}


And all functions of this kind
exports.list = () => {

  return new Promise((resolve, reject) => {

    try {

      if (conect) {

        const hash = crypto.randomBytes(30).toString('hex')
        
        socket
        .emit('list', JSON.stringify({
          auth: key,
          hash: hash
        }))
        .on('list', (data) => {

          data = JSON.parse(data) 

          if (data.hash === hash) {

            resolve(data.list)
          }
        });
      } else {

        reject(new Error('Disconnect to socket API'))
      }
    } catch (error) {

      reject(error)
    }	
  })
}

I am a customer, what could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Nagorny, 2018-04-01
@esvils

Here is a similar question

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question