简体   繁体   中英

creating N childs that share one ETS table with a supervisor

I have created a supervisor that starts children where each child is creating its own ETS table. Basically, everything looks fine except when I am trying to start more than 50 children, it says too many DB tables, which is a bad design as well. I would like to implement in such a way that the supervisor creates children and that all children use one ETS table. Even if the child wants to write to the ETS table it writes into the global ETS table.

I tried to google but could not find any help.

Thank you!

Why do you say that creating 50 ETS tables is a bad design? It all depends on your requirements. If those 50 processes need to access ETS at the same time then limiting them to just one table may impact performance because only one process can be writing to the table at a time.

Creating a single table or a gen_server that owns the table and is acting as a gateway to writing the data to the table (as proposed by Nathaniel) makes sense only if all those processes need to access the same data.

But in the later case it will be still more efficient if the table id is passed from the supervisor to its children so that the child processes can read/write in parallel rather than relying on the central gen_server to proxy the requests to the table (unless of course performance isn't your requirement).

It depends on what you actually want, but you could have the supervisor create the table and pass the pid/name to the children to use. You'll need to have the table use public permissions if you want to share it between processes.

Or make a server that's in charge of reading and writing the data that you want to store and have the supervisor manage that server along with the rest of the children.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM