Distributed Computing in Javascript

    The other day I discovered Life with Playstation, but the essence is not in it, but in the background process of Folding @ home . Distributed computing project for computer simulation of coagulation of protein molecules. While we read the news, watch the weather, our PS3 makes calculations for Folding @ home.

    And then an idea came to me, why not make calculations in the browser while the user is working on our site, because loading the processor when viewing the site is minimal.

    For a long time I could not think of what it is possible to calculate in a distributed manner in order to materialize the idea ... Rendering a 3D scene is not justified for the test and is expensive according to the transmitted data. I recalled a simple laboratory work from the student years on KMPF - visualization of the potential of a field with several charges. Extremely simple, can be distributed.


    Calculation example


    We have 5 positive and 5 negative charges randomly scattered in the cube 5.12 by 5.12 by 5.12 meters. It is necessary to calculate the field potential in each centimeter of the cube. It's simple - for each centimeter we go over all the charges and summarize the potential for this centimeter.

    We have 512 layers of 512x512 cells. It took me 6 seconds to calculate one layer. The whole field will take about an hour.

    Size of received data

    Suppose we need such accuracy of calculations that as a result of each centimeter there will be 4 bytes of data, then the entire cube will occupy 512 MB.

    300th layer render

    image

    How can it work


    The client downloads a script containing the calculation module (model) and the I / O module, which in turn requests the state of the model and the task from the server.
    State of the model: the coordinates of all points and charges, the amount of space to calculate. Task: interval for calculation, for example, from 512 to 1024 cells (one row of a layer).
    The client calculates 512 cells and sends this data to the server (2Kb of data). In response, he receives a new task for the calculation. And so on.

    For control, there must be a server issuing tasks for clients and receiving calculation results. The server has a job queue for computing. Each task has a timeout, after which it returns to the queue. The server saves data in storage (file).
    There will be 262144 tasks in 512 cells in total - 262144 2Kb data blocks.

    image

    Also popular now: