Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot is getting slow or hags out #594

Open
peweb opened this issue Jan 21, 2023 · 12 comments · May be fixed by #620
Open

Bot is getting slow or hags out #594

peweb opened this issue Jan 21, 2023 · 12 comments · May be fixed by #620
Labels
bug Something isn't working

Comments

@peweb
Copy link

peweb commented Jan 21, 2023

Version

v0.0.96 (209d2e0)

Description

Bot is running on a VPS with very low load. If i dont touch it for several days I cant login to the frontend or if I login it is slow.
If I reboot the server everything works fine.

How can I troubleshoot and fix this?

I have
0 * * * * /usr/bin/docker restart binance-bot tradingview

@peweb peweb added the bug Something isn't working label Jan 21, 2023
@habibalkhabbaz
Copy link
Contributor

Hello @peweb

Yes it's valid issue. It is happening continuously after migrating to the custom queue implementation.
I will look into this when I have time or maybe @uhliksk can help us on this too.

@uhliksk
Copy link
Contributor

uhliksk commented Jan 22, 2023

Hello @habibalkhabbaz, @peweb

Do you have any logs? I don't have this issue. Maybe unstable internet connection can cause this? I'll try to do some tests.

@uhliksk
Copy link
Contributor

uhliksk commented Jan 23, 2023

I probably found the cause of this issue. Cronjob is not deterministic as it can interrupt the job if it's running for more than 20 seconds which will cause the job will not indicate it's finished. I'll rework the code to finish the job properly if running for more than 20 seconds.

// Make sure the job running within 20 seconds.
// If longer than 20 seconds, something went wrong.
await fulfillWithTimeLimit(
moduleLogger,
20000,
executeJob(moduleLogger),
null
);

@shhhmel
Copy link

shhhmel commented Jan 28, 2023

Same problem.
docker restart binance-bot tradingview and cronjob doesn't help.
UI still loading infinitely.

@shhhmel
Copy link

shhhmel commented Jan 29, 2023

Possible solution:

Instead of using setTimeout to interrupt the job if it's running for more than 20 seconds, you could use the async-timeout library to handle the timeout.

const fulfillWithTimeLimit = async (logger, timeLimit, task, failureValue) => {
  let timeout;
  try {
    timeout = asyncTimeout.set(timeLimit, task);
    return await timeout;
  } catch (err) {
    logger.error(
      { tag: 'job-timeout' },
      `Failed to run the job within ${timeLimit}ms.`
    );
    return failureValue;
  } finally {
    asyncTimeout.clear(timeout);
  }
};

This way, if the task takes longer than 20 seconds to complete, it will throw a TimeoutError which will be caught by the catch block. The job will then proceed with the failureValue.

@peweb
Copy link
Author

peweb commented Apr 5, 2023

@chrisleekr Can you please check this and release it if this is fixed?
Thanks!

@chrisleekr
Copy link
Owner

@peweb, The proposed code by @shhhmel is doing the same task as what the current code does.

@uhliksk
Copy link
Contributor

uhliksk commented Apr 6, 2023

@chrisleekr I'm sorry I forgot to push the PR for this. I little bit busy last few weeks so I'll push what I tried to do, but I didn't have a time to finish it yet.

@uhliksk uhliksk linked a pull request Apr 6, 2023 that will close this issue
@chrisleekr chrisleekr linked a pull request May 3, 2023 that will close this issue
@dasbts
Copy link

dasbts commented May 8, 2023

If this works, then you are a beast, because I get this issue every day (sometimes multiple times a day) even with cronjob to restart the bot every 6h. Either it freezes with the cache locks, or it just stops working, alternatively random symbols websockets stop working.

I am currently trying this out and will update how it looks in the next days. However, I had to change in the queue.js as I got:
setTimeout(...).then is not a function and since it is just a timeout, I changed it
From:

        setTimeout(r, 20000).then(
          logger.error({ symbol }, `Queue ${symbol} job timeout`)
        )

Into:

      new Promise((resolve) => {
        setTimeout(() => {
          resolve();
        }, 20000);
      }).then(() => {
        logger.error({ symbol }, `Queue ${symbol} job timeout`);
      })

I ran it for only like 30 minutes and got error "javascript heap out of memory docker mark-sweep reduce last resort gc in old space" even tho I have a lot of RAM available and also ZSwap which compresses my RAM. However, it was apparently as easy to fix on Linux as writing in terminal:
export NODE_OPTIONS=--max_old_space_size=4096
On windows, save it as an environment variable.

EDIT: Sadly didn't resolve the random "action" timer stopping (thus meaning the ws stopped/restarted) for random symbol at random time.

@dasbts
Copy link

dasbts commented May 10, 2023

Applied the code in your commit @uhliksk, but today I noticed it is still doing this. It is very slow and having issues releasing the locks (which I have retries for to not totally break the bot when it cannot release redlock), so when changing pages for the symbols it even went back to the initial page for some seconds, before going to the page I chose.

Many of my symbols also stopped the tickers at random times 2-3 hours ago.

Nice try tho!

@uhliksk
Copy link
Contributor

uhliksk commented May 11, 2023

@dasbts Thank you for testing. I'm not able to finish the thing because of some health issue. I'll be glad for any suggestions until I'll be able to get back to work again.

@dasbts
Copy link

dasbts commented Jun 9, 2023

@uhliksk I had to revert the change sadly, for some reason when I was selling a trade, it thought the last buy price was 0 even tho it was recorded all this time, so the profit was reported as way more than it was worth. Also had a trade trigger at the sell, then for some reason it deleted the trade and everything related to it, but didn't sell. Of course only had to remove the sell history and add back the last buy price, but sadly missed a profitable sell opportunity.

Not 100% sure if this was actually related, but I started some other strange errors too. Haven't really had any problems like this after I reverted and after implementing the #629 changes (which I just need to know how you want PR's made as some repos seem to have develop branches etc.

However, my changes included removing the WS tickers subscription for all BTC equivalents (if trading for example DOGE/USDT), as used for dust transactions, as otherwise, everytime I would restart a socket, it would also add i.e. DOGE/BTC to my GUI cards, even tho it's not monitored in the config. After doing this I also got a big performance boost in that it previously hanged up and was slow in general. So for me that's a clue something is suspect with the BTC dust part in tickers.js.

Repository owner deleted a comment Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants