Hacker Newsnew | past | comments | ask | show | jobs | submit | dxxvi's commentslogin

> It's exceedingly rare to see any sort of global mutable state I know a bit of Rust, so you don't need to explain in details. How to use a local cache or db connection pool in Rust (both of them, IMO, are the right use case of global mutable state)?

You wrap it in a mutex and then it is allowed.

Global state is allowed. It just has to be thread safe.


Why does that have to be global? You can still pass it around. If you don't want to clobber registers, you can still put it in a struct. I don't imagine you are trying to avoid the overhead of dereferencing a pointer.

I think a better example might be logging. How is this typically solved in Rust? Do you have to pass a Logger reference to every function that potentially wants to log something? (In C++ you would typically have functions/macros that operate on a global logger instance.)

In Rust you typically use the "log" crate, which also has a global logger instance [0]. There is also "tracing" which uses thread local storage.

As another comment said, global state is allowed. It just has to be proven thread-safe via Rust's Send and Sync traits, and 'static lifetime. I've used things like LazyLock and ArcSwap to achieve this in the past.

[0] https://docs.rs/log/latest/log/fn.set_logger.html


I wonder what the advantage of passing it around is when it makes the argument list longer. The only advantage that I can see is that it emphasizes that this function does something with cache.

I wonder why nowhere talked about who Jia Tan was. In my understanding, a few people already talked to that person. Now, does Jia Tan really vanish?


I agree. Screen sharing in Teams used to work in Firefox but not in the current version (144). It works in Chrome though.


There's at least 1 thing that Zig is better than Rust is that Zig compiler for Windows can be downloaded, unzipped then used without admin right. Rust needs msvc, which cannot be installed without admin right. It is said that Rust on Windows can use cygwin but I cannot make it work even with AI help.


cygwin is a POSIX-emulating library intended for porting POSIX-only programs to Windows. That is: when compiling for cygwin, you'd use the cygwin POSIX APIs instead of the Windows APIs. So anything compiled with cygwin won't be a normal Windows program.

There's no reason to use cygwin with Rust, since Rust has native Windows support. The only reason to use x86_64-pc-cygwin is if you would need your program to use a C library that is not available for Windows, but is available for cygwin.

If you don't want to/can't use the MSVC linker, the usual alternative is Rust's `x86_64-pc-windows-gnu` toolchain.


Have you tried the GNU toolchain? IIRC rustup provides the option to use it instead of the MSVC toolchain during the initial installation.


You should check out cargo-zigbuild which makes use of zig for cross compiling rust projects. https://github.com/rust-cross/cargo-zigbuild


Is it true that a message from a queue will disappear after it is consumed successfully? If yes, at this moment, how do you make kafka topics work as queues?


It "disappears" in the sense that the Consumer-Group that read/committed that message (event) will never see it again. It doesn't "disappear" in the sense that a new Consumer-Group can be started in a way that will get that message, or you can reset your Consumer-Group's offset to re-consume it.


Think about this for a second. Kafka offsets are a thing, consumer groups are a thing. It's trivial to ensure that only one message is delivered to only one consumer if that's what you want. Consumer groups track their offset and then commit the offset, the message stays in Kafka but it won't be read again.

This IMO is better behaviour than RabbitMQ since you can always re-read messages once they have been processed, whereas generally with MQ systems the message is then marked for deletion and asynchronously deleted.


> It's trivial to ensure that only one message is delivered to only one consumer

Exactly-once delivery is one of the hardest distributed systems problems. If you’ve “trivially” solved it, please show us your solution.


> It's trivial to ensure that only one message is delivered to only one consumer if that's what you want. Consumer groups track their offset and then commit the offset, the message stays in Kafka but it won't be read again. This IMO is better behaviour than RabbitMQ

The trivial solution is to use Kafka. They're clearly saying that Kafka makes it trivial, not that it's trivial to solve from scratch.


What the parent poster described isn’t what makes Kafka’s “exactly once” semantics work. It’s the use of an idempotency token associated with each publication, which effectively turns “at-least-once” semantics into effectively “exactly once” via deduplication.


We used Flink and S3 compatible backends (for the Flink state) to ensure exactly once processing.

I didn't say Kafka magically solves these problems for you, but it was required for the scalability we needed.


> better behaviour than RabbitMQ since you can always re-read messages once they have been processed

I can imagine, a 1 Billion dollar transaction accidentally gets processed by ten thousand client nodes due to a client app synchronization bug, company rethinks its dumb data dumper server strategy...news at 11.


Is Google guava really needed? I would like it to be taken out.


No, it's not needed. We plan to remove Google Guava from the Fory Java dependency. Our philosophy is that the core should have as few dependencies as possible for maintainability and minimal footprint.


So, you want a place to store many files in a short period of time and when there's a new file, somebody must be notified?

Have you ever thought of using a postgresql db (also on aws) to store those files and use CDC to publish messages about those files to a kafka topic? In your original way, we need 3 aws services: s3, lambda and sqs. With this way, we need 2: postgresql and kafka. I'm not sure how well this method works though :-)


I've dealt with images in a database and it was a disaster, the transfer times are garbage.


Like put the video blobs themselves in postgres data columns? Does putting very large (relative to what you normally put in postgres) files in pg work well? Genuine question, i do not know, I've been considering it too and hesitant about it.


I already checked with AI before putting the comment :-)

1GB with the bytea data type (https://www.postgresql.org/docs/current/datatype-binary.html) and 4TB with the BLOB data type (https://wiki.postgresql.org/wiki/BinaryFilesInDB).


Have you done this? I can google or AI for the max size that postgres will allow, sure. I have googled in the past for whether this actually works well, and have gotten answers leaning towards most advice against it in real world scenarios.

So if you have experience with this and it did work well, I'm curious to hear about it! That's why i asked about if it worked well, not about the maximum size postgres allowed in various data types.

If you have no experience with it, but are just posting advice based on what AI tells you about max sizes of data allowed by pg that I can get from the same source too, then okay, fair enough, and certainly no need to give me any more of that!


> I've been considering it too and hesitant about it

Why hesitant? Just ask AI. It'll tell you how to do it and then you can experiment it yourself.


Do you know that there's a concurrent Scala library named ZIO (https://zio.dev)? :-)


Does it make the electricity price go down or up? It seems to me that the electricity price never goes down.


Perception isn't objective, and inflation still exists.

However, price gouging by monopolies also exist. See Enron and their intentionally caused rolling brown-outs.


My hacker news modified with violentmonkey: https://vercel-html-example.vercel.app/hn-violentmonkeys.png

The + - buttons on the top panel change the font size of every thing except the font size of the panel.

Things are arranged to minimize the page scrolling.

The news title and number of comments are darker and a little bit bigger than other elements for an easy reading.


Do you mind sharing the script?


    // ==UserScript==
    // @name        ycombinator
    // @namespace   Violentmonkey Scripts
    // @match       https://news.ycombinator.com/*
    // @grant       GM_addStyle
    // @version     1.0
    // @author      -
    // @description 10/5/2022, 6:35:39 PM
    // ==/UserScript==

    GM_addStyle(`
      .pagetop { color: #fff }
      body .title { font: 19px/1.5 sans-serif }
      body a, body a:link { color: #222 }
      body .comhead { font-size: 16px; font-style: italic }
      body .title .rank { color: #aaa; font-size: 14px }
      body .subtext { font-size: 16px; padding: 4px 0 6px 19px }
      .c00, .c00 a:link { color: #444 } body .comment { font: 16px/1.45 sans-serif; max-width: none }
      body span.pagetop a, body span.pagetop a:visited { color: #fff }
      body tr.athing:not(.comtr):nth-child(even) { background: linear-gradient(#f4f4f4, #eee, #f4f4f4) }
      body tr.athing > td { padding: 5px 10px 5px 1px }
      body tr.athing > td.votelinks { padding-right: 5px }
      td.zoom { font-weight: 700; color: #fff; width: 32px }
      td.zoom > span { cursor: pointer; font-size: 1.5rem }
      div.toptext { font-size: 17px; color: #333 }
      span.number-of-comments { font-size: 18px; color: #666 }
    `);

    const t = document.getElementById('hnmain');
    if (t != null) {
      t.removeAttribute('bgcolor');
      t.removeAttribute('width');
      t.parentNode.removeChild(t);
      document.body.prepend(t);
    }

    const spanPagetop = document.querySelector('td span.pagetop');
    if (spanPagetop) {
      const tr = spanPagetop.parentElement.parentElement;
      tr.insertAdjacentHTML('afterbegin', `
        <td class="zoom"><span onclick="zoomIn(); return false">+</span></td>
        <td class="zoom"><span onclick="zoomOut(); return false">-</span></td>
      `);
    }

    setTimeout(function() {
      while (true) {
        const td = document.querySelector('tr:not([id]) > td.subtext');
        if (td == null) {
          break;
        }

        const tr = td.parentElement;
        const previousTr = tr.previousElementSibling;
        if (previousTr != null) {
          tr.parentElement.removeChild(tr);
          previousTr.append(td);
        } else {
          break;
        }
      }

      while (true) {
        const tr = document.querySelector('tr.spacer');
        if (tr == null) {
          break;
        }
        tr.parentElement.removeChild(tr);
      }

      document.querySelectorAll('td.title[valign="top"]').forEach(td => td.setAttribute('valign', 'middle'));

      document.querySelectorAll('table > tbody > tr:has(> td + td + td + td) + tr + tr > td[colspan="2"]:first-child + td:last-child').forEach(td => {
        td.setAttribute('colspan', '2');
      });

      document.querySelectorAll('a[href^="item?id="]').forEach(a => {
        const arr = a.innerHTML.split('&nbsp;');
        if (arr.length == 2) {
          a.innerHTML = `<span class="number-of-comments">${arr[0]}</span> ${arr[1]}`;
        }
      });
    }, 419);

    const myScript = document.createElement('script');
    myScript.innerHTML = `
      const FONT_SIZE_THRESHOLD = 26.9;
      function zoomIn() {
        const bodyTitle = document.querySelector('body .title');
        if (bodyTitle) {
          const newFontSize = parseFloat(getComputedStyle(bodyTitle).getPropertyValue('font-size').replace('px', '')) + 1;
          document.querySelectorAll('body .title').forEach(t => {
            t.style.fontSize = newFontSize + 'px';
            if (newFontSize > FONT_SIZE_THRESHOLD) t.style.fontWeight = 300;
          });
        }
        const bodyComment = document.querySelector('body .comment');
        if (bodyComment) {
          const newFontSize = parseFloat(getComputedStyle(bodyComment).getPropertyValue('font-size').replace('px', '')) + 1;
          document.querySelectorAll('body .comment').forEach(t => {
            t.style.fontSize = newFontSize + 'px';
            if (newFontSize > FONT_SIZE_THRESHOLD) t.style.fontWeight = 300;
          });
        }
      }

      function zoomOut() {
        const bodyTitle = document.querySelector('body .title');
        if (bodyTitle) {
          const newFontSize = parseFloat(getComputedStyle(bodyTitle).getPropertyValue('font-size').replace('px', '')) - 1;
          if (newFontSize > 12) document.querySelectorAll('body .title').forEach(t => {
            t.style.fontSize = newFontSize + 'px';
            if (newFontSize < FONT_SIZE_THRESHOLD) t.style.fontWeight = 400;
          });
        }
        const bodyComment = document.querySelector('body .comment');
        if (bodyComment) {
          const newFontSize = parseFloat(getComputedStyle(bodyComment).getPropertyValue('font-size').replace('px', '')) - 1;
          if (newFontSize > 12) document.querySelectorAll('body .comment').forEach(t => {
            t.style.fontSize = newFontSize + 'px';
            if (newFontSize < FONT_SIZE_THRESHOLD) t.style.fontWeight = 400;
          });
        }
      }
    `;
    document.head.appendChild(myScript);


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: