[Haskell-cafe] Re: Threads with high CPU usage
Günther Schmidt
redcom at fedoms.com
Mon Dec 22 09:40:56 EST 2008
Hi,
I am not yet 100% certain that the unsafe calls are indeed the cause of
the problem, eventhough I strongly suspect there are.
I can tell you more once I have managed to rewrite all "unsafe" calls into
"safe" once, reinstall HDBC.Sqlite3 and then run my app again to see the
effects. My first attempt doing so was not successful, I'm not certain
whether I missed an "unsafe" call or the app is using an old version of
HDBC.Sqlite3 or whatever.
I understand that Takusen does not use "unsafe" calls and would like to
try it with that one then, but haven't find enough docs yet on how to use
Takusen.
Günther
Am 22.12.2008, 15:15 Uhr, schrieb John Goerzen <jgoerzen at complete.org>:
> Duncan Coutts wrote:
>> On Mon, 2008-12-22 at 10:30 +0000, Malcolm Wallace wrote:
>>
>>> The terminology seems counter-intuitive, but in other other words, a
>>> "safe" call is slower but more flexible, an "unsafe" call is fast and
>>> dangerous. Therefore it is always OK to convert an "unsafe"
>>> declaration
>>> into a "safe" one, but never OK to convert from "safe" to "unsafe"
>>> without looking at what the foreign side actually does.
>>
>> And in general we would not even bother with considering using "unsafe"
>> for calls that are already expensive. It's only worth considering when
>> the length of the call is always very short.
>>
>> For example in a database library it might make sense to use 'unsafe' on
>> the data-access functions that extract data from a local query result
>> but we should always use 'safe' on any DB function that might want to
>> talk to the network (eg to get more query results).
>
> It's difficult to anticipate the needs here. For instance, some people
> may be using a few very-long-running queries measured in minutes, such
> as the original poster. Other people, such as web app developers, may
> be issuing literally millions of queries, right after another, where the
> difference matters.
>
> I had initially used "unsafe" because of the documented performance
> benefit, plus I certainly am not expecting Sqlite to call back into the
> Haskell runtime.
>
> It seems to me strange that using "unsafe" instead of "safe" would have
> negative implications for threading. After all, as Malcolm said above,
> "it is always OK to convert an unsafe declaration into a safe one". So
> could the compiler be made to be smart enough to do so when it is
> advantageous for threading purposes?
>
> What's the best way to make this suitable for both people with many
> queries and those with long-running queries?
>
> I should also add that I suspect the C calls that are bothering the
> original poster here are the standard ones for reading results, and
> could be called many, many times on even a single query.
>
> -- John
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list