digitalmars.D.learn - vibed - best approach to manage central state (cached records)
- Laeeth Isharc (24/24) Apr 11 2015 Hi.
- Rikki Cattermole (4/26) Apr 11 2015 The caches I use in e.g. web service frameworks use __gshared. As long
- Laeeth Isharc (3/45) Apr 11 2015 Thanks.
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (6/16) Apr 12 2015 You can declare the cache as `immutable` (which is shared across
- Laeeth Isharc (3/22) Apr 12 2015 Thanks.
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.
Apr 11 2015
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.
Apr 11 2015
On Sunday, 12 April 2015 at 02:54:27 UTC, Rikki Cattermole wrote:On 12/04/2015 7:24 a.m., Laeeth Isharc wrote:Thanks. Laeeth.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.
Apr 11 2015
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()`.
Apr 12 2015
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:Thanks. LaeethHi. 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()`.
Apr 12 2015