HNHacker News
TopNewBestAskShowJobs

iambvk

179 karma · joined August 11, 2009

bvk dot other at gmail dot com
submissionscomments
iambvk··on Futures for C++11 at Facebook
Am I the only one who thinks ".then(...)" code is also unreadable? Composability with ".then(...)" looks like a workaround for C++ limitations.

Why can't we have this instead:

  fooAsync(input) {
    //...
    USING_B_THREAD_POOL
    //...
    USING_A_THREAD_POOL
    //...
    USING_B_THREAD_POOL
    //...
  }
What are the disadvantages?
iambvk··on Lessons learned from implementing Paxos (2012)
Here is my understanding. Please correct me if I am wrong.

LATENCY

multi-paxos and raft are equal. It takes 4 hops for a consensus.

fast-paxos gives two-hop consensus when there is no race, which is the optimal.

generalized-paxos gives two-hop consensus for non-conflicting, commutative operations.

genuine-generalized-consensus gives two-hop consensus for non-conflicting, commutative operations and, i think, three-hop consensus for the rest, which is the optimal.

BANDWIDTH

All paxos variants (except classic-paxos of course) allow multiple consensus operations in parallel. Not sure about raft.

STORAGE

cheap-paxos (without reconfiguration) only needs two replicas to support one-node failure; in general, K+1 replicas for K failures.

iambvk··on Coordination Avoidance in Database Systems [pdf]
distributed -> database
iambvk··on The Rust standard library no longer has any scheduling baked into it
Thanks for sharing your experience.

I went through the callback-hell problem myself and came to the conclusion that swapcontext is the only way to go. I am starting to begin a large personal project that will be entirely based on swapcontext model (but using boost::coroutine), so I would like to know more from your experience before I invest into possibly the wrong model. Since you haven't explained your solution in-detail, I have a question:

Did you use multiple N:M schedulers (each owning an isolated group of os-threads) or your entire process uses a single N:M threading library that owns all os-threads of the process?

Here is what I am doing:

My project does lot of disk and network IO. So, IMO, being able to keep CPU, Disk and Network busy is my design goal. Having a single N:M scheduler that handles all threads makes it very difficult to understand/analyze/manage the system performance, so I made the choice of having multiple N:M schedulers (that communicate through message passing), each deals with separate resources of the system. For example, os-threads of a N:M cpu-scheduler will only do compute work and when a disk (or network) io is necessary, the greenlet/task/whatever will be queued into the disk-io-scheduler (or network-io-scheduler). When the os-threads of disk-io-scheduler (or network-io-scheduler) finish the io, they queue the greenlet/task back into the cpu-scheduler.

This IMO keeps managing/analyzing/tuning the system performance and complexity little easy. For example,

> All of a sudden you're forced to write a userspace scheduler and guess what it's really hard to write a scheduler that's going to do a better job that Linux's schedules that has man years of efforts put into it. Now you want your schedule to man N green threads to M physical threads so you have to worry about synchronization. Synchronization brings performance problems so you start now you're down a new lockless rabbit hole. Building a correct highly concurrent scheduler is no easy task.

Agreed, writing a good scheduler that deals with mixed workloads is very challenging. In my model, I am hoping that a poor scheduler wouldn't be an issue because, os-threads in the cpu-scheduler are only competing for cpu-bound tasks; similarly os-threads of io-scheduler are only competing for io-bound tasks. The real scheduling between io and cpu operations is still left to the kernel (because kernel decides to pick which scheduler's os-thread to run.) From kernel point of view there are threads that only do IO work or threads that only do CPU work. I am not yet sure if kernel schedulers are optimized for such workload or not.

> A lot of 3rd party code doesn't work great with userspace threads. You end up with very subtle bugs in you code that are hard to track down. In many cases this is due to assumptions about TLS (but this isn't the only reasons). In order to make it work you now can't have work stealing between your native threads and then you end up with performance problems and starvation problems.

My design-solution to this is to segregate 3rd party code into a fixed set of threads that do not ever participate in N:M threading library. Would that solve the above issues?

> The final nail in the coffin for me was disk IO. The fact is that non network IO is generally blocking and no OS has great non-blocking disk IO interfaces (windows is best but it's still not great). First, it's pretty low level, eg. difficult to use. You have to do IO on block boundaries. Second, it bypasses the page cache (at least on Linux) which in most cases kills performance right there. And in many cases this non-blocking interface will end up blocking (even on windows) if the filesystem needs to do certain things under the covers (like extend the file or load metadata). Also, the way these operations are implement require a lot lot of syscalls thus context switches which further negate any perceived performance benefits. The bottom line is that regular blocking IO (better yet mmaped IO) outperforms what most people are capable of achieving using the non-blocking disk IO facilities.

Yes, lot of disk/file-system operations do not have non-blocking equivalents. This is one of the main reasons for having a separate disk-io-scheduler (with its own thread-pool) in my design. In my model any blocking-only operation is made asynchronous by queuing the operation into a dedicated io thread pool and let it inform me when the operation is completed. This gives me flexibility in tuning the IO parallelism specific to my needs. For example, SSD can handle more concurrent operations than a HDD, so I can create an ssd-io-scheduler with more number of threads than a hdd-io-scheduler.

It would be great if you could share your thoughts on my analysis. Thanks.

iambvk··on Ask HN: How do I legally run a startup in US while on an F1 or H1B visa?
IANAL, you can start a startup on H1B if you can prove that you are not sponsoring yourself. The way few people I know did is, by having a board of directors with the power to fire you (maybe through majority vote). You need to list a member of board-of-directors as your manager.
iambvk··on Senate hearing on Bitcoin [video]
You are assuming deposits and loans both are done in terms of bitcoins.

In theory, we can design a banking system that accepts deposits in bitcoins and gives out loans in the fiat currency.

iambvk··on Coroutines in one page of C
Didn't see your comment til now. So, here is the difference I see:

Full-blown coroutines give us a way to write fully asynchronous code without using callbacks. For example, I could define ASYNC macro as follows:

#define ASYNC(blocking_function_call) \ do { \ auto io_pool = GetIOThreadPool(); \ auto cpu_pool = GetCurrentThreadPool(); \ \ Detach_The_Thread_and_Enqueue_Coroutine_For_IO(io_pool); \ \ blocking_function_call; \ \ Detach_The_Thread_and_Enqueue_Coroutine_For_CPU(cpu_pool); \ } while (0)

Now, I can make any blocking operation asyncrhonous. For example, open() or readdir() functions do not have asynchronous interfaces, but I can make them asynchronous by simply wrap it with ASYNC(...) macro.

It works as follows: When we need to do a blocking operation, we suspend the coroutine and we enqueue it into a thread-pool that is designated to do blocking calls; the cpu thread is now free, so it can start executing other cpu-bound coroutines. When io thread has finished the job, it will enqueue the coroutine back to the CPU thread pool.

What we have now is a fully asynchronous system where cpu threads can be kept busy with only cpu-bound work and io threads can be kept with io-bound work. This gives us full control over the concurrency. We could be confident that CPU threads are always available for compute work.

We cannot do this with python "yield".

iambvk··on Coroutines in one page of C
Also, it is more powerful. You can return/resume from arbitrary function depths.
iambvk··on Coroutines in one page of C
Glad you mentioned this; to me, this is a very important requirement.

I don't see lot of people understand the difference between YIELD and full-blown coroutines.

IMO YEILD is not very useful; it doesn't compose well with non-yield function. OTOH full-blown coroutines are super awesome.

Too bad C++11 still doesn't give full-blown coroutines.

iambvk··on Rundown of the newest features in C++11 [pdf]
I agree!

I found no libraries that give std::bind functionality in C and GCC extensions also doesn't offer any solutions.

iambvk··on tmux 1.8 Released
I bind C-z as the escape character (in screen). It seems to serve me well :)
iambvk··on Adria Richards: ‘I’m staying safe’
Author mentions that her action was probably an over-reaction -- which is where I stopped reading the article.
iambvk··on Tips for C libraries on GNU/Linux
I find autotools thousand times easier than CMake. Autotools just work. I can always ask it to get the hell out of my way!

Doing complex dependencies in CMake is a pain where as with Autmake, I can just go back to Make in the same file.

iambvk··on Commercial freedom
I still think there is one middle man that is very tough to get rid of: banks or payment gateways, like visa.

They still are getting their cut!

If bitcoin is going to change that, it is also going to create opportunity!

iambvk··on Adobe's Source Code Pro Font
+1 for Ubuntu Mono. IMO it looks better than Inconsolata.
iambvk··on Apple's tribute to Steve Jobs, one year on.
I think this is the first time Apple posted a non QuickTime video on their site. As a Linux user, it felt different :)
iambvk··on Inconsolata
I used to use Inconsolata ever since I came to know about it.

But, after the monospaced variant of Ubuntu font is released, I switched away from Inconsolata. It is a great font, but Ubuntu Mono is better looking for my taste.

iambvk··on 9 reasons to start using C++11
Linux kernel has lists, etc. that can be used as generic data structures. IMO they are good enough for most purposes.
iambvk··on 9 reasons to start using C++11
> What I would like to see is a (convincing) list of why use C++ (in new projects) at all.

C is my obvious choice, but...

When it comes to deciding between C and C++, C++ beats C in one aspect: templates. For example, quick sort in C++ performs a lot better than C because templates enable lots of compiler optimizations. (Rest of the C++ features are just garbage for my purposes.)

I just hope next C revision adds some form of template support into the language.

iambvk··on Trolls (2008)
Yes, I think reddit is not as bad as many think. Given the huge size of reddit community, I guess, reddit has managed to retain a high quality humor and knowledge (eg: r/askscience). Their fu is one of the best source of innovative comics I ever found.
iambvk··on Google Engineer Builds Facebook Disconnect
I too don't have a facebook account and the worst issue with Facebook connect is, its login box steals keyboard focus and completely annoys my browsing experience.

I hope he releases this as Firefox extension too.

iambvk··on The Truth about $35 Android Tablet from Indian Government
i am an indian, and i agree completely.
iambvk··on Oracle sues Google over use of Java in Android
I wonder how much did google give away till now...
iambvk··on OpenSolaris fork imminent?
Are you suggesting packaging in debian or fedora has some issues? Can you elaborate in one or two lines? Thanks.
iambvk··on New symbol for Indian Rupee
to get = symbol, which stands for equality (among people, religion,etc)
iambvk··on Post from "weev" (AT&T/ipad data hacker) on his arrest and treatment
Lets hope Apple will step-in and to stand by his civil liberties. I heard they took some moves for the same for Chinese workers :P
iambvk··on Google the way it's supposed to be
It would be very nice, if it can be centered vertically too!
iambvk··on Gizmodo and the Prototype iPhone
I did not see anywhere that it was stolen, any pointers?
iambvk··on Gizmodo and the Prototype iPhone
What does DA stand for?

Please explain where spirit and ethics that are broken in your opinion.

AFAIK, Gizmodo's business is that: gather sources, inform interested people what it can. If we forget letter of law, this is how i see it:

(1) No where i see the proof that it was stolen. (2) Gizmodo paid the guy some amount to get pictures, etc. and is actually willing to return it to Apple. I still don't see the problem if it gets returned to Apple. (3) Gizmodo revealed the Apple employee's name to public, which is kinda crossing the line -- but given that a guy recently committed suicide for such a fault, i give Gizmodo a pass.

iambvk··on Gizmodo and the Prototype iPhone
Ethics matter, i agree. Rule of law matters? I am really not sure, it needs to be considered case by case: Things change over time, new laws come in that make old things illegal. Do i have to accept them blindly or not is a personal decision.

Coming to the point, you did not mention what part of Gizmodo story you think is ethically wrong. Ethics matter, rule of law matters, try our best, learn from mistakes, etc. are kinda universal truths, everybody knows. Say something concrete to the point!

← PreviousPage 4 of 5Next →