[GHC] #13554: Allow the user to provide a C function that is called on each thread the RTS creates before running any Haskell code

#13554: Allow the user to provide a C function that is called on each thread the RTS creates before running any Haskell code -------------------------------------+------------------------------------- Reporter: dobenour | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: 8.4.1 Component: Runtime | Version: 8.0.1 System | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Currently, it is very difficult to use the MySQL/MariaDB client library with Haskell. One must use bound threads, which comes at a performance penalty. The reason is that the underlying library requires a certain initialization function to be called on each OS thread before any other functions are called. Similarly, it is difficult to optimally use libcurl with GHC. The best- performing way to use libcurl is to have one multi handle per thread and to use `curl_multi_socket_action` to respond to events. This is currently not possible from Haskell, at least not easily. (There are other issues with using libcurl from Haskell; most notably libcurl’s event support makes heavy use of callbacks, which are slow, to tell the application which file descriptors to wait for. But that is a separate issue.) Setting milestone to 8.4.1 because I don’t think that this is difficult. This is a feature requ -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13554 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13554: Allow the user to provide a C function that is called on each thread the RTS creates before running any Haskell code -------------------------------------+------------------------------------- Reporter: dobenour | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by bgamari: @@ -19,1 +19,1 @@ - This is a feature requ + This is a feature request. New description: Currently, it is very difficult to use the MySQL/MariaDB client library with Haskell. One must use bound threads, which comes at a performance penalty. The reason is that the underlying library requires a certain initialization function to be called on each OS thread before any other functions are called. Similarly, it is difficult to optimally use libcurl with GHC. The best- performing way to use libcurl is to have one multi handle per thread and to use `curl_multi_socket_action` to respond to events. This is currently not possible from Haskell, at least not easily. (There are other issues with using libcurl from Haskell; most notably libcurl’s event support makes heavy use of callbacks, which are slow, to tell the application which file descriptors to wait for. But that is a separate issue.) Setting milestone to 8.4.1 because I don’t think that this is difficult. This is a feature request. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13554#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13554: Allow the user to provide a C function that is called on each thread the RTS creates before running any Haskell code -------------------------------------+------------------------------------- Reporter: dobenour | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): There is a bit of a tricky interface question here. It seems to me like allowing only one callback is insufficient. Afterall, what when you want to use both MySQL and libcurl? It seems that you really need the ability to register multiple callbacks for this to be robust. However, there is also the question of what the precise semantics of this callback are. Should it get called on threads which are pre-existing at time of callback registration? Does the callback get called in the context of each thread, or merely with its, e.g., `pid`? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13554#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13554: Allow the user to provide a C function that is called on each thread the RTS creates before running any Haskell code -------------------------------------+------------------------------------- Reporter: dobenour | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Also, it seems that MySQL requires that you call `mysql_thread_end` on thread termination. We would probably also need a callback for this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13554#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13554: Allow the user to provide a C function that is called on each thread the RTS creates before running any Haskell code -------------------------------------+------------------------------------- Reporter: dobenour | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): It shouldn't be hard for someone to implement this idea after these questions are answered. I believe that all of the relevant RTS bits can be found in `rts/Task.c`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13554#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13554: Allow the user to provide a C function that is called on each thread the RTS creates before running any Haskell code -------------------------------------+------------------------------------- Reporter: dobenour | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by fendor): Hi, As an API proposal: {{{ data ThreadCallbackHandle data ThreadCallbacks = ThreadCallbacks { threadCreationCb :: IO () , threadDestructionCb :: IO () } -- function calls would be blocking until -- the callbacks have been executed on all threads. registerCallbacks :: ThreadCallbacks -> IO ThreadCallbackHandle unregisterCallbacks :: ThreadCallbackHandle -> IO () }}} In this proposal, one can submit callbacks that are executed on thread creation or thread termination. These callbacks are also executed on every thread that is currently being executed, since it seems impossible to guarantee that no code execution migrates to threads that have not executed the callback functions. When registering new callbacks, the function should block, until it is guaranteed that every thread has executed the new callback function. Several calls to this function should save existing callbacks and execute all callback functions that have been supplied upon thread creation and termination. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13554#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13554: Allow the user to provide a C function that is called on each thread the RTS creates before running any Haskell code -------------------------------------+------------------------------------- Reporter: dobenour | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): dobenour, does this help your use-case(s)? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13554#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13554: Allow the user to provide a C function that is called on each thread the RTS creates before running any Haskell code -------------------------------------+------------------------------------- Reporter: dobenour | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: Runtime System | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dobenour): Yes it does, though note that “thread” means OS thread and not Haskell thread. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13554#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC