Skip to main content

Home/ ProgrammingPages/ Group items tagged memory

Rss Feed Group items tagged

Navneet Kumar

Synchronization and the Java Memory Model - 3 views

    • Navneet Kumar
       
      Assignment to a long, double, float variables are not Atomic.
  • as-if-serial property of these manipulations shields sequential programmers from needing to know if or how they take place. Programmers who never create their own threads are almost never impacted by these issues
  • All changes made in one synchronized method or block are atomic and visible with respect to other synchronized methods and blocks employing the same lock, and processing of synchronized methods or blocks within any given thread is in program-specified order. Even though processing of statements within blocks may be out of order, this cannot matter to other threads employing synchronization.
  • ...6 more annotations...
  • atomicity alone does not guarantee that you will get the value most recently written by any thread. For this reason, atomicity guarantees per se normally have little impact on concurrent program design
  • Thread.start has the same memory effects as a lock release by the thread calling start, followed by a lock acquire by the started thread
  • releasing a lock forces a flush of all writes from working memory employed by the thread, and acquiring a lock forces a (re)load of the values of accessible fields. While lock actions provide exclusion only for the operations performed within a synchronized method or block, these memory effects are defined to cover all fields used by the thread performing the action.
  • If a field is declared as volatile, any value written to it is flushed and made visible by the writer thread before the writer thread performs any further memory operation (i.e., for the purposes at hand it is flushed immediately). Reader threads must reload the values of volatile fields upon each access.
  • you will obtain either its initial value or some value that was written by some thread, but not some jumble of bits resulting from two or more threads both trying to write values at the same time
  • As a thread terminates, all written variables are flushed to main memory.
Navneet Kumar

defmacro - Functional Programming For The Rest of Us - 0 views

  • In a lazy language you have no guarantee that the first line will be executed before the second! This means we can't do IO, can't use native functions in any meaningful way (because they need to be called in order since they depend on side effects), and can't interact with the outside world! If we were to introduce primitives that allow ordered code execution we'd lose the benefits of reasoning about our code mathematically
  • continuations, monads, and uniqueness typing.
  • Alonzo Church developed a formal system called lambda calculus. The system was essentially a programming language for one of these imaginary machines
  • ...18 more annotations...
  • Functions that operate on other functions (accept them as arguments) are called higher order functions.
  • currying is used to reduce the number of arguments
  • only executes code when it's required
  • A lazy compiler thinks of functional code exactly as mathematicians think of an algebra expression - it can cancel things out and completely prevent execution, rearrange pieces of code for higher efficiency, even arrange code in a way that reduces errors, all guaranteeing optimizations won't break the code.
  • John McCarthy (also a Princeton graduate) developed interest in Alonzo Church's work. In 1958 he unveiled a List Processing language (Lisp)
  • Lisp machine - effectively a native hardware implementation of Alonzo's lambda calculus!
  • it was proved that lambda calculus is equivalent to a Turing machine.
  • It turns out that functional programs can keep state, except they don't use variables to do it. They use functions instead. The state is kept in function parameters, on the stack. If you want to keep state for a while and every now and then modify it, you write a recursive function
  • Erlang engineers have been upgrading live systems without stopping them for years.
  • Erlang systems are not scalable and reliable. Java systems are. Erlang systems are simply rock solid
  • Ericsson designed a functional language called Erlang for use in its highly tolerant and scalable telecommunication switches.
  • Continuation Passing Style or CPS
  • A "continuation" is a parameter we may choose to pass to our function that specifies where the function should return.
  • continuations are a generalization of functions.
  • CPS version needs no stack! No function ever "returns" in the traditional sense, it just calls another function with the result instead. We don't need to push function arguments on the stack with every call and then pop them back, we can simply store them in some block of memory and use a jump instruction instead. We'll never need the original arguments - they'll never be used again since no function ever returns!
  • What does the stack contain? Simply the arguments, and a pointer to memory where the function should return. Do you see a light bulb? The stack simply contains continuation information! The pointer to the return instruction in the stack is essentially the same thing as the function to call in CPS programs!
  • A continuation and a pointer to the return instruction in the stack are really the same thing, only a continuation is passed explicitly, so that it doesn't need to be the same place where the function was called from
  • When we get a current continuation and store it somewhere, we end up storing the current state of our program - freezing it in time. This is similar to an OS putting itself into hibernation. A continuation object contains the information necessary to restart the program from the point where the continuation object was acquired.
  •  
    deals from the history of functional languages
    what are functional languages, benefits

Navneet Kumar

MySQL Performance Blog ยป MySQL Query Cache - 0 views

  • It does not cache the plan but full result sets
  • so it looks at first letter of the query and if it is โ€œSโ€ it proceeds with query lookup in cache if not - skips it.
  • Might not work with transactions
  • ...15 more annotations...
  • uses non-deterministic functions such as UUID(), RAND(), CONNECTION_ID() etc it will not be cached.
  • If table gets modification all queries derived from this table are invalidated at once
  • if you have high write application such as forums, query cache efficiency might be pretty low due to this.
  • all queries are removed from cache on table modifications - if there are a lot of queries being cached this might reduce update speed a bit
  • Qcache_free_memory and Qcache_lowmem_prunes
  • number of your selects - Com_select and see how many of them are cached. Query Cache efficiency would be Qcache_hits/(Com_select+Qcache_hits).
  • One portion of query cache overhead is of course inserts so you can see how much of inserted queries are used: Qcache_hits/Qcache_inserts Other portion of overhead comes from modification statements which you can calculate by (Com_insert+Com_delete+Com_update+Com_replace)/Qcache_hits
  • want to set query cache
  • means it is much more efficient as query which required processing millions of rows now can be instantly summoned from query cache
  • It also means query has to be exactly the same and deterministic, so hit rate would generally be less
  • full page caching
  • not using query_cache_wlock_invalidate=ON locking table for write would not invalidate query cache so you can get results evenif table is locked and is being prepared to be updated
  • it can serve responses very fast doing no extra conversion or processing.
  • but it is still not as fast as specially designed systems such as memcached or local shared memory.
  • It is not distributed If you have 10 slaves and use query cache on all of them cache content will likely be the same, so you have multiple copies of the same data in cache effectively wasting memory
  •  
    mysql query caching
Navneet Kumar

Table types in MySQL: Part 1 - HEAP tables - 0 views

  •  
    Heap tables : in-memory tables
Navneet Kumar

JavaScript tutorial - 0 views

  • for your own objects, you may wish to provide a special string that may provide more useful information. To do this, simply define the 'toString' method:
  • not have to store individual copies of the methods for each instance of the object, so it may require less memory, but it will require the browser to search the current and parent scopes to find the methods. This may cause a marginal delay
  • Saying 'this.propertyname' as I did above will create a public property. Any script can create an object then use and modify its properties directly. Using 'var' to define a variable in the constructor will create a private property.
  • ...7 more annotations...
  • Private variables can only be accessed from methods that are declared inline, and not externally referenced or created using the prototype construct. Methods of this kind are also known as privileged methods
  • prototype chain.
  • That also means that if the mycircle prototype is changed (properties are added or deleted, etc.), these changes are replicated down the chain, so the mysphere also inherits these changes.
  • mysphere.prototype.constructor = mysphere;
  • I will take all of the methods out of the constructor, and add them later using the prototype. That way, the mycircle prototype methods will always be available without me needing to create a new mycircle. Unfortunately, this also means that public and private properties are very hard (or impossible) to use. It's a trade off - one functionality for another.
  • When running the method, we need to tell JavaScript that even though we are referencing a method for a different prototype, we want to run it as if it were a method of the object we are creating (to make sure that any properties it creates are added to the object we are creating). This could be done using the 'call' method or 'apply' method
  • Note that when assigning the mycircle object to the mysphere prototype, it also overwrites the mysphere prototype constructor property
  •  
    complete Javascript tutorial
Navneet Kumar

When Not to Normalize your SQL Database - SWiK - 0 views

  • With the above design, it takes six SQL Join operations to access and display the information about a single user. This makes rendering the profile page a fairly database intensive operation which is compounded by the fact that profile pages are the most popular pages on social networking sites.
  • Database denormalization is the kind of performance optimization that should be carried out as a last resort after trying things like creating database indexes, using SQL views and implementing application specific in-memory caching. However if you hit massive scale and are dealing with millions of queries a day across hundreds of millions to billions of records or have decided to go with database partitioning/sharding then you will likely end up resorting to denormalization
    • Navneet Kumar
       
      De-Normalization is OK if you are'nt going to update
  • Denormalization means that you you are now likely to deal with data inconsistencies because you are storing redundant copies of data and may not be able to update all copies of a column value simultaneously  when it is changed for a variety of reasons. Having tools in your infrastructure to support fixing up data of this sort then become very important.
  •  
    De-normalizing database to improve speed.
1 - 7 of 7
Showing 20 items per page