Giter VIP home page Giter VIP logo

Comments (9)

 avatar commented on May 30, 2024 1

Everything works perfectly! you're doing great!
I tested for large requests and DDoS attacks - everything is fine!
Now DNDB is a reliable base!

from dndb.

denyncrawford avatar denyncrawford commented on May 30, 2024

@michailVestnik Hi buddy, the problem isn't a DnDB issue. It is actually just because you're not awaiting your async function.

Edit: I must remember that DnDB is not a sync module and you have to wait for each operation until it is done and committed to run the next operation, this is because we are working with a file state that cannot change while another write task is running. So, this happens when you try to perform multiple operations at time.

I did a minimal example with the fix and it works nice:

import { Application } from "https://deno.land/x/[email protected]/mod.ts";
import Datastore from 'https://deno.land/x/[email protected]/mod.ts'

const app = new Application();

const count = new Datastore({
  autoload: true,
  filename: './count.db'
})

console.log("http://localhost:8080/");

const increment =  async (page) => {
  let results = await count.find({ url: page })
  if (results.length) {
    for (let el of results) {
      let { counter } = el;
      return await count.updateOne({url: page}, {$set: {counter: counter+1}})
    }
  } else {
    let doc = {
      url: page, 
      counter: 1
    }
    return await count.insert(doc);
  }
}

app.get('/*', async (c) => {
  let page = c.url.pathname;
  page = page === '/' ? 'index' : page 
  let pageVisit = await increment(page);
  return JSON.stringify(pageVisit, null, 2)
})

app.start({port: 3000})

Also you don't need to loop through all the documents, you can use Datastore.updateOne() :D but I did it in the example to be true to your code, also dndb does not return async iterators they are just arrays and you don't need to use for await.

Does this solve your problem? If it does, I proceed to close, regards 😄 .

from dndb.

denyncrawford avatar denyncrawford commented on May 30, 2024

Ok, I'm testing right now on another pc and it crashes with the same exact error even when I'm waiting for the function. Let me check it out ASAP.

from dndb.

 avatar commented on May 30, 2024

I think that the problem is in writing the backup file db. updated and the reaction of the operating system. If we give the request rate about 1600 per minute-the application crashes

from dndb.

denyncrawford avatar denyncrawford commented on May 30, 2024

Yes, I'm working so far trying to debug this, but I can't find why it fails at that operation rate. I guess the same as you, by now I only know that this is related to the temporary file renaming and the way dndb handles storage. I am working solve the problem ASAP.

from dndb.

denyncrawford avatar denyncrawford commented on May 30, 2024

@michailVestnik Hi, buddy, this is the new update:

Basically the error occurs because when a user makes a request at the same time as another user is doing the same, Deno revokes the rename operation because the file is already open by another call. In fact, I made a run queue manager, but it didn't work due to the way the DnDB storage system is managed, dndb opens and closes the file every time an operation is executed. Probably what I'll have to do is keep the file open when initializing dndb and close it only when renaming. For now I have to do some rewrites, please be patient.

from dndb.

denyncrawford avatar denyncrawford commented on May 30, 2024

@michailVestnik I did some changes and it is working so far:

trim.mp4

Idk if it is only working on my environment so, can you perform a test with the update using the example?

https://raw.githubusercontent.com/denyncrawford/dndb/main/mod.ts

from dndb.

 avatar commented on May 30, 2024

OK. I'll test it now, wait!

from dndb.

denyncrawford avatar denyncrawford commented on May 30, 2024

Thanks @michailVestnik, it's great that this bug has been discovered and resolved. I proceed to close this issue and publish the stable version.

from dndb.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.