Code Monkey home page Code Monkey logo

Comments (13)

ityuhui avatar ityuhui commented on July 30, 2024

I think the best way is setting a timetout in the parameter of watch function, after timeouts, free up the resource same with non-watch example.

e.g.

    CoreV1API_listNamespacedPod(apiClient, "default",   /*namespace */
                                NULL,   /* pretty */
                                0,  /* allowWatchBookmarks */
                                NULL,   /* continue */
                                NULL,   /* fieldSelector */
                                NULL,   /* labelSelector */
                                0,  /* limit */
                                NULL,   /* resourceVersion */
                                30,  /* timeoutSeconds */     <------------------ Set the timeout
                                1   /* watch */
        );

from c.

clearday4 avatar clearday4 commented on July 30, 2024

I think the best way is setting a timetout in the parameter of watch function, after timeouts, free up the resource same with non-watch example.

e.g.

    CoreV1API_listNamespacedPod(apiClient, "default",   /*namespace */
                                NULL,   /* pretty */
                                0,  /* allowWatchBookmarks */
                                NULL,   /* continue */
                                NULL,   /* fieldSelector */
                                NULL,   /* labelSelector */
                                0,  /* limit */
                                NULL,   /* resourceVersion */
                                30,  /* timeoutSeconds */     <------------------ Set the timeout
                                1   /* watch */
        );

Application want to watch the events util they stop watching.
They want to receive the state of the only changed object.
But if we set the timeout, application should watch again and get the entire status of object again.
what is the difference from get function?

from c.

ityuhui avatar ityuhui commented on July 30, 2024

When timeout is set, watch function will not return even though it receives the state change.

The watch function returns only the timeout is reached.

from c.

clearday4 avatar clearday4 commented on July 30, 2024

It doesn't meet our requirement.
application wants to know immediately if pod is scaled in or out or deleted or modified.

from c.

ityuhui avatar ityuhui commented on July 30, 2024

Suppose setting timeout as 3600 seconds (1 hour),
Watch function can receive events such as pod deletion/modification (your callback function will be called) immediately but Watch function will not stop watching. After 3600 seconds, the watch function will return and stop watching.

from c.

clearday4 avatar clearday4 commented on July 30, 2024

But After 1 hour,
if application call watch function again, K8s API server send the all pod state again,
Therefore, if application wants to know the pod status has changed, compare to previous status and the previous information should be stored to db.

There is no different from GET that we need to store the previous state.

from c.

ityuhui avatar ityuhui commented on July 30, 2024

I think you can set a longer timeout.
Or run watch function forever in a thread. After the program ends, allocated memory will be released.

And I see you have tried pthread_cancel(), then when will you call pthread_cancel() ?

from c.

clearday4 avatar clearday4 commented on July 30, 2024

If I kill the watch thread with pthread_cancel, resource leak occurs.
Since watch thread is blocked on curl_easy_perform, curl handle, curl mime, apiClient and cJSON_Parse are leak

from c.

ityuhui avatar ityuhui commented on July 30, 2024

Could you please run watch function forever in a thread ?
After the program ends, allocated memory will be released.

from c.

clearday4 avatar clearday4 commented on July 30, 2024

right. so application can't stop watching until now.

from c.

brendandburns avatar brendandburns commented on July 30, 2024

Can't you use pthread_cleanup_push to register a cleanup handler for the watch pthread?

https://man7.org/linux/man-pages/man3/pthread_cleanup_push.3.html

from c.

brendandburns avatar brendandburns commented on July 30, 2024

I'm closing this since I think that the issue issue is resolved via the Libcurl progress functions.

from c.

brendandburns avatar brendandburns commented on July 30, 2024

Please use /reopen if there is further assistance needed.

from c.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.