#Vapor Memory Graph/Analyze

1 messages · Page 1 of 1 (latest)

hazy crescent
#

When my vapor project starts running, used memory capacity continues to increase every second.

How can I analyze what is taking up memory and leak situations ?

tawny linden
#

@hazy crescent I personally try to debug these issues through Xcode instruments, because they're far better and more friendly than other tools you can use. But on Linux you can use a variety of tools as well. I don't recall which, but I've used some tools from the C++ developer tools I had installed in the past

#

If you can reproduce it on macOS, Xcode instruments on macOS will help a lot

hazy crescent
#

I tried this but it didn't work. I got an error like this; Required kernel recording resources are in use by another document. @tawny linden

tawny linden
#

Hrm, that's odd. I assume you don't have two instruments running right?

hazy crescent
#

i think no, there is one instruments window…

#

some times the error like ; Failed to gain authorization

tropic turret
#

Those tools don't work with SPM projects, you need to create a regular macOS project (IIRC even a command line tool is enough), add some glue code to start your vapor app, then you can use the memory debugger and instruments alike when running this app.

tawny linden
#

Right, codesigning

#

I guess I haven't needed instruments much in a long time

tropic turret
#

Also, on Linux, use jemalloc. The template Dockerfile was very recently updated to pull it in

hazy crescent
#

As far as I understand, I will create a macOS application and run my vapor application through this application. Afterwards I will be able to analyze the memory. Is it true ?

tawny linden
hazy crescent
#

I think I found the cause of the error. A class connects to a socket on another server every second and tries to capture data. When it captures this data, it closes the connection. The next second it opens a connection again. The reason for this is that the data I want to receive only comes to me when a new connection is established.

I don't know why, but the websocket on the other server does not immediately respond to the close request. It takes 5-6 seconds to close. Somehow, zombie data is created in the memory.

How can I be sure that when I connect to a server with a Vapor websocket, the connection is closed and there is no zombie data in the memory? Is there a way to close the connection safely and reliably? @tropic turret

tawny linden
#

@hazy crescent the obligatory first response is; please do keep the socket open. The way it's wielded now it might as well be a regular HTTP request.

Secondly; is the data really zombie data? Because I find it hard to believe that. I think you're looking for a retain cycle instead

#

So a memory leak

hazy crescent
#

Yes, actually it can be retain cycle, u are right. But i didnt understand, why i should keep the socket open. I want close socket to connect again.

tawny linden
#

Well, you're doing it every second. What advantage does the socket give you then

#

At that point it's a de-optimised HTTP request

hazy crescent
#

The websocket I am connected to provides information about stock price changes in stock markets. It gives all market data when the first connection is established. The. it sends me message when a stock price updated. I need instant information of all markket data every second. Because im processing all stocks and prices to technical analysis. I have to use this webSocket. I searched for a long time and this webSocket is absolutely for me…

#

Just i think, i need to close socket secure and clear..

#

Do you have any other variant or API suggestion in case of using the close() method?

tropic turret
#

It gives all market data when the first connection is established.

I need instant information of all markket data every second.

I'm not sure this implies that you have to DoS attack the other side every second... you could just keep the initial state in memory and update as you're getting the update messages, no?

#

(unless of course these update messages are delayed and you're not immediately getting the new values, and you're really getting updates faster by hard polling...)

hazy crescent
#

I pay for the webSocket I connect to. I discussed this situation with the providers. I stated that I needed all the data. They stated that they could not do this due to cost, but that I could establish a second connection and receive data. @tropic turret