WengQiang's Blog

where there is a will, there is a way!

select() vs poll() vs epoll()

  1. select() int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);

  2. poll()

    1
    2
    3
    4
    5
    6
    7
    8
    int poll (struct pollfd *fds, unsigned int nfds, int timeout);

    struct pollfd {
    int fd;
    short events;
    short revents;
    };

  3. epoll() epoll_create(), epoll_ctl(), epoll_wait()

  • select() have three bitmask-based set of fds(fd-set), poll() only have signle array of fds(pollfd structure)
  • select() will reconstruct the fds, so should build each set before each call; poll() has seperate events and returned events, so it don't need.

  • select() and poll() manage everything in user mode and send sets each time to wait on, to add another fd we need to add it to the set and call select()/poll() again(); however epoll() use epoll_create to create context in the kernel mode, using epoll_ctl to update the context.

阅读全文 »

hyperledger fabric

  1. ordering service: broadcast and establish concensus
  2. identity and membership
  3. scalable dissemination(optional): An optional peer-to-peer gossip service disseminates the blocks output by ordering service to all peers
  4. smart-contract execution
  5. ledger maintenance

limitation of Order-Execute architecture

  1. sequential execution
  2. no deterministic code
  3. confidentiality of execution

fabric Execute-Order-Validation architecture

  1. node type
  • client: submit transaction proposals and broadcast them
  • peer: execute transaction proposals and validate them and maintain blockchain ledger which is append-only not all peers will execute the transaciton proposals, which called endorsing peers execute them.
  • ordering service node

  1. introduction in general, on common processor machine, Integer multiplication is many times faster than division. So dividing a numerator n by a divisor d is mathematically equivalent to multiplication by the inverse of the divisor n / d = n * (1/d)

  2. faster remainder algorithm for detail, see paperFaster Remainder by Direct Computation Applications to Compilers and Software Libraries

the faster remainder algorithm implemented in c is following(unsigned and signed):

阅读全文 »

basic principle

  • SOLID >> S: single resposibility
    O: open-closed: open for extension, closed for modification
    simple shoud not go back to code/modify somthing haveing writtern adn tested L: liskov substitution
    if interface is ok to type A, it should also is ok to its inherited type B I: interface segregation
    D: dependency inversion
    high level module should not depend on low level; absraction should not depend on detail

factory method pattern

  1. Delegation of object creation to factory method
  2. Extensibility by permitting arbitrary many factory methods
  3. Code reuse through runtime polymorphism
  4. Decouple initialization of factories from creating connections
阅读全文 »
0%