Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
April 11, 2015 vibed - best approach to manage central state (cached records) | ||||
---|---|---|---|---|
| ||||
Hi. Two questions: 1. On startup I load various indexes from file storage into memory in the shared static this segment, and I would like to access these from threads serving web requests. The data can be considered immutable once loaded. What is the best way to make this data accessible? Obviously static doesn't work as the threads have their own storage (I think this is what is happening). __gshared works, but is there a better approach? 2. This works: auto router = new URLRouter; router.get("/pricebars",&renderPricebars); router.get("/names",&renderTickernames); router.registerRestInterface(new MarketDataAPIImplementation); auto settings = new HTTPServerSettings; settings.options=HTTPServerOption.parseQueryString; settings.port = 8080; listenHTTP(settings, router); But if I switch the REST registration and the static route registration ("/pricebars" and "/names") then it segfaults. Reason for mixing regular routes and REST is to be able to serve some data in CSV form. Thanks. |
April 12, 2015 Re: vibed - best approach to manage central state (cached records) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Laeeth Isharc | On 12/04/2015 7:24 a.m., Laeeth Isharc wrote:
> Hi.
>
> Two questions:
>
> 1. On startup I load various indexes from file storage into memory in
> the shared static this segment, and I would like to access these from
> threads serving web requests. The data can be considered immutable once
> loaded.
>
> What is the best way to make this data accessible? Obviously static
> doesn't work as the threads have their own storage (I think this is what
> is happening). __gshared works, but is there a better approach?
>
>
> 2. This works:
> auto router = new URLRouter;
> router.get("/pricebars",&renderPricebars);
> router.get("/names",&renderTickernames);
> router.registerRestInterface(new MarketDataAPIImplementation);
> auto settings = new HTTPServerSettings;
> settings.options=HTTPServerOption.parseQueryString;
> settings.port = 8080;
> listenHTTP(settings, router);
>
> But if I switch the REST registration and the static route registration
> ("/pricebars" and "/names") then it segfaults. Reason for mixing regular
> routes and REST is to be able to serve some data in CSV form.
>
> Thanks.
The caches I use in e.g. web service frameworks use __gshared. As long as they are readonly most of the time, and written in one go. I see no problems threading wise.
|
April 12, 2015 Re: vibed - best approach to manage central state (cached records) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rikki Cattermole | On Sunday, 12 April 2015 at 02:54:27 UTC, Rikki Cattermole wrote:
> On 12/04/2015 7:24 a.m., Laeeth Isharc wrote:
>> Hi.
>>
>> Two questions:
>>
>> 1. On startup I load various indexes from file storage into memory in
>> the shared static this segment, and I would like to access these from
>> threads serving web requests. The data can be considered immutable once
>> loaded.
>>
>> What is the best way to make this data accessible? Obviously static
>> doesn't work as the threads have their own storage (I think this is what
>> is happening). __gshared works, but is there a better approach?
>>
>>
>> 2. This works:
>> auto router = new URLRouter;
>> router.get("/pricebars",&renderPricebars);
>> router.get("/names",&renderTickernames);
>> router.registerRestInterface(new MarketDataAPIImplementation);
>> auto settings = new HTTPServerSettings;
>> settings.options=HTTPServerOption.parseQueryString;
>> settings.port = 8080;
>> listenHTTP(settings, router);
>>
>> But if I switch the REST registration and the static route registration
>> ("/pricebars" and "/names") then it segfaults. Reason for mixing regular
>> routes and REST is to be able to serve some data in CSV form.
>>
>> Thanks.
>
> The caches I use in e.g. web service frameworks use __gshared. As long as they are readonly most of the time, and written in one go. I see no problems threading wise.
Thanks.
Laeeth.
|
April 12, 2015 Re: vibed - best approach to manage central state (cached records) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Laeeth Isharc | On Saturday, 11 April 2015 at 19:24:22 UTC, Laeeth Isharc wrote:
> Hi.
>
> Two questions:
>
> 1. On startup I load various indexes from file storage into memory in the shared static this segment, and I would like to access these from threads serving web requests. The data can be considered immutable once loaded.
>
> What is the best way to make this data accessible? Obviously static doesn't work as the threads have their own storage (I think this is what is happening). __gshared works, but is there a better approach?
You can declare the cache as `immutable` (which is shared across threads) and assign to it using `assumeUnique()`. You just need to make sure the initialization really happens only once, i.e. do it in `main()` or in `shared static this()` as opposed to `static this()`.
|
April 12, 2015 Re: vibed - best approach to manage central state (cached records) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz | On Sunday, 12 April 2015 at 10:04:53 UTC, Marc Schütz wrote:
> On Saturday, 11 April 2015 at 19:24:22 UTC, Laeeth Isharc wrote:
>> Hi.
>>
>> Two questions:
>>
>> 1. On startup I load various indexes from file storage into memory in the shared static this segment, and I would like to access these from threads serving web requests. The data can be considered immutable once loaded.
>>
>> What is the best way to make this data accessible? Obviously static doesn't work as the threads have their own storage (I think this is what is happening). __gshared works, but is there a better approach?
>
> You can declare the cache as `immutable` (which is shared across threads) and assign to it using `assumeUnique()`. You just need to make sure the initialization really happens only once, i.e. do it in `main()` or in `shared static this()` as opposed to `static this()`.
Thanks.
Laeeth
|
Copyright © 1999-2021 by the D Language Foundation