Server cpu always at 100% in testphase

Hi,

I have a Dapp on testnet where i just transfer tokens between different addresses and chains. I am the only user for this Dapp but my server https://poteo5fegttn.moralishost.com:2053/server always reaches 100% cpu and answers with „POST https://poteo5fegttn.moralishost.com:2053/server/functions/getNativeBalance net::ERR_INSUFFICIENT_RESOURCES“.
After a while when the cpu is back to normal 10% it get the error Error: XMLHttpRequest failed: “Unable to connect to the Parse API”

Access to XMLHttpRequest at ‘https://poteo5fegttn.moralishost.com:2053/server/functions/getTokenBalances’ from origin ‘http://localhost:3000’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

RESTController.js:304 POST https://poteo5fegttn.moralishost.com:2053/server/functions/getTokenBalances net::ERR_FAILED 403

Does anybody have an idea what did I wrong?

Thanks for your help.

Henning

How do you do that transfer of tokens between addresses and chains? Maybe that part uses considerable cpu.

For the weekly challenge I was thinking to use Moralis to deploy my own token bridge. So I have 3 Bridge contracts on Ropsten, BSC and Polygon testnet. I send ERC20 or native to this Bridge SC. This emits an event. Moralis listens to this event and after it is confirmed I sign a tx on the other chain of the bridge to mint the new token. The bridging process works fine although the server seems to come to its limit. The frontend side then crashes but this doesn’t effect the bridging tx. The tx goes through. At the moment i sign the tx with cloud function but i also tried it on the frontend. But I got the same result.

it looks like you are doing enough processing that could cause 100% usage of the processor for the free server instance.
how do you do this part: Moralis listens to this event and after it is confirmed?

It is an afterSave function in my cloud file.

Moralis.Cloud.afterSave("TransferOnEth", async (request) => {
    if(request.object.get("confirmed")) {
      if (request.object.get("step") === "burn") {
         await doBridging(
          request.object.get("fromTokenAddress"),
          request.object.get("toTokenAddress"),
          request.object.get("owner"),
          request.object.get("fromChain"),
          request.object.get("toChain"),
          request.object.get("amount"),
          request.object.get("nonce"));
      }
    }
});

and in the doBridging function I just connect to web3 with Moralis.web3ByChain() and then sign the tx to the bridge SC with the private key that is on the server

you shouldn’t process too many transactions of this type now, right?

Yes it is only me. And I tried to send 2 tx right after each other. but that seems to be already too many. when i sign the tx for ropsten sometimes only on ongoing tx i enough to bring the cpu to 100%

What I don’t understand is when subscribe my frontend to a live query of the TransferOnEth class and then on update if fire the tx from my frontend I also see the 100% from time to time

I think that signing a transaction with the initialization of web3 uses considerable processing power on the small server associated with a free account. You could put some logging with timing for various stages of your code to see what part takes a lot of time to execute.

Thank you cryptokid for your strong support. i really appreciate it. i was able to figure out the high performance consuming task at now i do it outside the cloud function. Seems to work for a demo.

1 Like