Better HN
topnewbestaskshowjobs
Log inSign up

codedokode

9,867 karma · joined Aug 20, 2015 (11y ago) · 5,528 submissions

PHP developer from Russia.
Submissions

comment 3mo ago · link · parent

Yes but an average man would lose to most of women in term of looks, style, clothes choice, skin care, makeup, hair, etc. If employers cared only about looks then they would prefer to hire women. Of course, it is possible that only women get judged by looks and men are not.

comment 3mo ago · link · parent

> Now not being obese is becoming increasingly rare.

For men, I assume?

comment 3mo ago · link · parent

Because many drugs have side-effects, and they are different for different people. So if a drug helps one person, it might harm another.

comment 3mo ago · link · parent

Indeed, men on average look worse than women.

comment 3mo ago · link · parent

If looks are important for employment how then men find a job? Men are mostly unattractive even compared to not a perfect woman. In terms of looks and style, average man loses to an average woman. Or employers require only women to be attractive?

comment 3mo ago · link · parent

> what stops a big tech with enough money for using a model to generate millions of trivial patent

It requires a yearly payment and can get quite expensive [1]. There are application, examination, issuing and publishing fees for each patent. In contrast, publishing ideas online is free.

[1] https://www.uspto.gov/learning-and-resources/fees-and-paymen...

comment 3mo ago · link · parent

I think you do not need to register a patent, you can just publish the idea with a verifiable date, that could be considered as a "prior art". I would suggest to make a free website where anyone can publish any ideas although I do not understand how one can prove the publish date. And then the community could publish everything that might be potentially invented in near future to prevent others from getting a patent.

For example, I would publish the idea of a "self-driving car" that can drive without or with minimal human supervision using a computer. I believe this is pretty novel and can be called an invention.

Also I hope this patent is valid only in US and cannot be enforced in China.

comment 3mo ago · link · parent

I became curious how fast fdatasync (a better version of fsync) is, and asked LLM to generate a microbenchmark for me. The benchamrk accepts records size, number of records, opens a file, and appends records one by one, making fdatasync after each one. On my SSD, the throughput is 120 fsyncs/second, or ~0.5 MB/s. So if I had Redis to flush the log after each operation, it wouldn't be able to serve those thousands of connections. That's why Redis is either used without AOF, or they flush the data once per second. And that's why SQL databases might look "slow".

Of course one could optimize this - for example, while fsync is being executed, we could accept the queries from other clients and execute them, and once previous flush finishes, flush multiple transactions at once. However, I am not sure if Redis can do this due to being single-thread.

And obviously maybe there are problems with drivers, or with my consumer-level SSD and maybe "professional" SSDs can do more flushes per second.

Writing the code took less than a minute. I often do microbenchmarks now because it is so easy.

comment 3mo ago · link · parent

No, using transactions won't change anything here.

> do not use throwaway placeholder rows to imitate a single item

The point of using multiple rows for one product is to distribute the locks.

comment 3mo ago · link · parent

On a large scale "rare" events happen every day. That is why people use locks and transactions or other measures.

In case with shopify, they want to decide whether the user may place order or not, at the moment when the user clicks "Pay" or some other button. If the user cannot place an order, they are shown the error, if they can, the items are reserved and the user is redirected to the payment page. So payment is processed only after successful reservation, and reservation is made only if the user wants to pay. The similar system works for buying train tickets online in my country, for example.

In you case, when user A clicks a button, following happens (as I understand):

1 the server increments the counter

2 the server calculates available amount as (amount_in_stock - amount reserved by carts with time < counter)

3 if the amount is large enough, the server updates the "time" field for user's cart thus reserving the item

Imagine that at step 2 the user A sees that there is one item left. However before user A does step 3, another user B might reserve the item (complete all 3 steps), and proceed to the payment. Then user A then completes step 3 and proceeds to the payment too. Now we end up with both user A and B paying for the last remaining item which doesn't solve the stated problem. Shopify's solution doesn't have such issues.

This is a classical TOCTTOU situation. There were exploits against Linux kernel based on similar issues.

comment 3mo ago · link · parent

I now thought that "updating a row" might be more expensive than simply deleting because UPDATE is implemented as "mark row deleted" + "insert new version of a row" in a table which support multiple versions of a row (MVCC). So maybe using DELETE is actually faster - it just marks a row as "deleted in transaction X". Unless I forgot something.

comment 3mo ago · link · parent

The fsync policy equivalent to SQL database would be "fsync on each change before reporting successful update to the app". Redis (as many NoSQL databases) also doesn't have SQL and is a pain to view the data, you need to write extra tools when investigating the problems.

RDB snapshots can cause multiple page faults due to use of fork() and CoW.

> It's easier to scale

The company in question manages online stores and they could easily scale by allocating a separate database for each store (sharding).

> But I think using Redis is much more elegant.

I cannot agree because I think using a single database for all the data is more elegant, than multiple different databases and there are less problems to deal with. I dislike microservice-style architecture strongly and believe it is mostly good for wasting company's money.

> 'Use only MySQL as a solution to the distributed transaction consistency problem between two different storage systems, Redis and MySQL!'

I read it as "do not create unnecessary work by using a single database".

comment 3mo ago · link · parent

I mentioned that Redis can write changelog (called AOF in the docs [1]). However, if you tell it to do fsync on every update (like SQL databases do), it stops being that fast and spends time waiting for the filesystem.

Furthermore, the RDB snapshot mechanism (when Redis forks and forked process writes the snapshot) can double memory consumption and cause thousands of page faults in Redis process if there are many writes happening.

The docs contains corresponding warnings. "Cloud backups" are marketing terms and not ACID guarantees.

As one more disadvantage, Redis has no SQL and you cannot easily view the data.

As for transactions, indeed it seems to have them, but their execution is serialized, i.e. when MySQL can prepare 100 transactions in parallel, Redis will execute them sequentially.

[1] https://redis.io/docs/latest/operate/oss_and_stack/managemen...

comment 3mo ago · link · parent

The item is reserved when the user decides to place an order, but before paying for it. Not when a product is added to the cart because the user can keep it there for a month and end up not buying.

You reserve the product by creating an "active_cart" entry. Your solution has a problem, that when you run the check, it might say the product is available, but before you create an "active_cart" to reserve it from thread A, another thread B reserves it and you end up reserving a product that is not available anymore. You end up with SUM(active_cart.quantity) > inventory.available_units.

That is exactly why the database has locks - to prevent this situation. With locks, thread A decrements inventory.available_units and that row is locked until the end of transaction. Other threads (if they do SELECT FOR UPDATE instead of SELECT) cannot see the old, invalid value until thread A either commits and the value is updated or rollbacks. However, locks cause performance issues and that is why shopify uses the architecture from the article - instead of 100 users fighting for the lock on the same row with available amount, each user locks only rows with units they plan to buy.

Interestingly, MySQL docs has the documentation page with a similar case: https://dev.mysql.com/blog-archive/mysql-8-0-1-using-skip-lo...

comment 3mo ago · link · parent

Redis doesn't have transactions and persistence.

No persistence means the data gets lost if machine shuts down or process crashes. Furthermore, after restart you will need to regenerate the data which can take time. That's why Redis is a cache and not a database. You can fix the persistence issue (Redis can write WAL log, don't remember if it does fsync or not), but then Redis won't be able to handle those thousands of concurrent connections.

Redis (and other NoSQL storages) don't have some magic architecture that gives them advantages over SQL databases. They just cut corners on ACID guarantees and skip fsync. Once you start doing fsync, your transaction throughput will drop to SQL database level.

Redis also doesn't have transactions which means every app error damages the data. You will spend engineer hours investigating and fixing the problems. Transactions save so much time and worries.

comment 3mo ago · link · parent

The problem is that in this case you have to do splits/merges. And while there are products that are sold by 100 units at a time, I think in most cases people by 1-2 items so the hassle might be not worth it.

Also you might not understand the original problem. Imagine if 100 customers want to buy product A. One thread starts a transaction, searches for amount of product A and UPDATE's it and goes searching for other products. The database locks the row until the end of transaction and other 99 treads cannot continue until first transaction commits (they can read but cannot update the rows).

This is why they made a row per item. In this case, transaction 1 hopefully locks only several rows with items of product A. Transaction 2 instead of waiting for lock release skips them (due to SKIP LOCK) and locks several next rows. And so on.

Obviously you do not need to make a row per item - if the available amount is really large (10 000 items), you could have for example 100 rows having 100 items each. In this case each transaction locks the whole row (100 items) even if it wants to reserve just one item. The problem though is that now every row might have different amount of available items and you have to do more work to reserve the amount you want.

comment 3mo ago · link · parent

Could not they shard the inventory table by shop_id? As I understand, the order includes only items from one store, so there is no need to keep all the stores in a single table.

Also, I wonder why they could not have a row status (available/reserved) and UPDATE it instead of deleting the rows.

comment 3mo ago · link · parent

If you have an AI, you could make it analyze crystal photos?

comment 3mo ago · link · parent

This shows that large companies making closed-source CPUs cannot be trusted. No doubt they would add whatever the government asks them to add.

What can be done to mitigate this? One option would be to buy a large FPGA and flash it with an open-source CPU. Another would be to emulate a CPU, working with encrypted data and commands, so that even if the backdoor in a host CPU tries to overwrite memory, it would only crash the emulated OS. One more option would be to run the code in a Virtual Machine like QEMU which translates the code and prevents issuing unknown instructions.

comment 3mo ago · link · parent

Sounds like GDPR?

comment 3mo ago · link · parent

But aren't you also "count-shaming" parent comment for preferring women with specific number of previous partners? Maybe they are not the only one frustrated.

Also, in Muslim countries and regions it is typically expected for a woman to have zero previous partners to get married, or at least having relationship only within a marriage.

comment 3mo ago · link · parent

The article is too long. Judging about beauty standards by using sex dolls as an example is not very smart, first, because they are targeted to a small niche audience with specific tastes, second, they do not look especially attractive in the photos in the article. Also the font is awful and a pain to read.

comment 3mo ago · link · parent

Unless they are very tall or very short, probably no.

comment 3mo ago · link · parent

So for example, a 6 feet tall nerdy-looking geek is better than 5' 6" athlete or celebrity? Doesn't seem logical to me.

comment 3mo ago · link · parent

Weight varies much more than height (there is 3x-4x ratio between extreme values) and is instantly noticeable unlike height, so I think this is a bad comparison.

comment 3mo ago · link · parent

I am curious why is height important? Understandably, income affects the lifestyle and opportunities, but what does height affect? What changes if you are several inch taller or shorter? I cannot understand.

Also, why those who care about height so much do not go for basketball players?

Also, the picture with income graph says "household income", not "personal income".

comment 3mo ago · link · parent

IMEI is like a MAC address. You are identified by the data in the SIM card and not by IMEI.
1
121314
185