Hello everyone. I'm Satish. I work at Flipkart in the ads tech team. Today I'm here to talk about our experience in using functional programming constructs to build an ad serving engine. So here is a rough agenda for today. Like for those of you who are wondering why Flipkart and ads, I'll just give a brief background. So Flipkart displays advertisements on the app homepage and the desktop homepage. And we also display ads on different category pages on the app and desktop. We also show product listing pages along with search results. And after that we'll briefly talk about some problems with imperative programming and how functional programming addresses some of these concerns. I'll give a high level overview of ads serving both from a domain perspective and from an architectural perspective. After that we'll just go through different problems in advertising and discuss functional solutions for these problems and see how Java 8 solution compares with Haskell solutions for these problems. Along the way we'll also talk about some abstractions and some concepts of monoids, functors, monoids and how they apply in real world functional programming. We'll just rinse and repeat and apply the same procedure on different problems in ads domain and continue like that. So before we get started let me just explain what I mean by real world here. In the real world most of us are working in imperative languages like Java or Ruby or JavaScript. And this is what real world Java looks like. When Java gets lambdas you expect to see code with fluent APIs that looks like this. But in reality you're actually looking at code with nested loops and conditions thrown in random places making it very hard to reason about the code. We spend most of our time thinking about the how part of the code instead of the what part of the code. Actually the code is not visible I can change it. Can you just confirm if the code is visible? So dynamic programming world is no different either. With Ruby's metaprogramming you expect to see code that reads like English sentences like this. But most of the time your writing test which should have been checked by the compiler or your writing put statements for doing debugging or you're just wondering where that magic method indexed by ISB and came from. Again in JavaScript there are these hundred different frameworks and you expect Angular or React to solve all of your problems. But in reality you're spending most of your time writing console.log statements instead of writing actual code. Unless you're lucky enough to work only with Aka in Java or Elm in JavaScript, this is state of most non-functional languages out there. Let's see how functional programming addresses some of these concerns. One day a friend tells you about the magical world of statically typed functional languages like Haskell. He's so excited about its features like referential transparency and lazy evaluation. You are equally excited and you start reading Haskell books to find out for yourself. One day you stumble upon this code for quick sort.  So that's the promise of statically typed functional languages. In a parallel universe a different friend tells you about the magical world of dynamically typed functional languages like Lisp. He or she is so excited about its features like homo-econicity. It seems promising and you want to find out for yourself and you start reading books on Lisp. And you stumble upon this code for infinite Fibonacci series. You cannot imagine any way in which you can express an infinite computation like this in your favorite language.  But in reality we often end up with other arguments but not using a functional language at work or in your projects. So these arguments are often along the lines of Scala or Clojure is hard to maintain or Haskell or Lisp is not on JVM and they're also in the form of time. In spite of all this learning functional programming is still worth it because like Alan Perlis says here it changes the way you think. And even if you're working in a non-functional language using functional style still has a lot of benefits. So in spite by all this we've tried to build an ad serving stack at Flipkart using functional style in a non-pure functional language like Java 8. I'll just talk about our experience in trying to do that. So the ad serving system that we're going to talk about deals with three different clients. It serves ads for apps, desktop and exchange. And in each of these clients it serves ads in multiple formats. The ad which you're seeing here is a brand story ad on the app and a carousel ad on the app. Similarly in the desktop you're seeing a carousel ad and a widget ad. Exchange here refers to showing ads on a third party publisher. And this is how a typical ad serving stack looks like. So advertisers configure campaigns and there are ad requests coming from app desktop and exchange. Ad server handles these requests and forwards it to ad selector. Ad selector is a component which selects relevant ads, ranks them and returns an ad. In some stacks the ad server and ad selector is a single component. In some stacks it could be like separate components. The ad gets rendered on the app and the app fires an event to the tracker. Tracker records these events and that's how most ad platforms make money. For the rest of this talk we are going to zoom in on the ad selector component here which is where we mostly adopted functional style. So the process for selecting an ad typically involves these steps. So relevance selects the relevant campaigns and banners for a specific ad request. Attribution performs an A-B test to find out how effective an ad is compared to users who have not seen the ad. Ranking basically scores the banners, ranks it and sends the top rank ad. The duplication is here to serve unique ads if there are multiple ad requests coming in the same request. And finally there is selection which returns the top rank ad. I'll be using these conventions throughout the talk. I'll just do something to fix the Haskell code which is not visible here. So the conventions will be anytime a functional concept is used or introduced in the slides for the first time, you'll be seeing this yellow sticky. Any Haskell code example that I talk about will be in this theme and any Java code example that I show will be in this theme. I'll just fix the code in a minute and get back. Okay, let's just look at the data model for ad serving before we start jumping into code and concepts. The primary entities that we're talking about here are advertisers who have many campaigns and campaigns which have many banners. Campaign has these properties of pricing type and price. To give you a very high level example, the industry standard term for this is CPM which stands for cost per mile or the price that advertisers are willing to pay for thousand impressions. And the banner has these two different properties which are CTR and score. CTR here stands for click through ratio. It's basically the ratio of number of clicks that you get to the number of impressions that you serve. And slots are often group slots here stands for ad slots. And these slots can optionally be grouped in group together. For example, if it's a carousel ad, all the ads, ad slots in that carousel belong to the same group. And a user here has certain properties based on which he or she can be targeted for the specific advertisement. So what I've tried here is to represent the data model using Haskell's type constructors and data constructors. I'm using Haskell here for conciseness and to show how it compares with Java code. So as you can see here, there is a type alias for price and there is an enumeration for pricing type. I've defined data types for advertiser, campaign and banner with all the relationships. I've defined data types here for slot and slot group. And the user here is either an unknown user or a user whose ID we know. And this is a corresponding Java code for the same data model with libraries like Lombok and Java. Even Java code comes pretty close to this in terms of conciseness. You just have to define the properties and just like Haskell showing, just like in Haskell if you implement EQ and show, you just have to do that declaratively here as well. Now let's talk about the different problems in ad selection flow. The first step in ad selection is relevance. And this layer basically selects relevant campaigns. And in this example, let's say you have a Gillette ad, a Loreal ad, Ole ad and an ads advertisement. This layer helps you in showing the right ad to the right audience. The user targeting which I'm showing here is just one of the many, many features of relevance. And we'll just talk about some certain, some example filters for relevance. So one of the filters is to check if the campaign itself is active or not. The other is to check if the campaign is targeted at a specific slot or not. The other is to check if the campaign is targeted at the user's gender or not. In reality, there are a lot more attributes, but for demonstration, we'll just stick to these three. So the first step in implementing this is to define the type signature of it. The analogous thing to do in Java world is to define that, define the interface definition for this functionality. So the type signature for relevance, relevant campaigns here takes a context as input and returns a list of campaigns per slot in a map as output. You can think of context here as some kind of abstraction for user and the request data. With this type signature in place, the, with this type signature in place, the filter, the filters that we want to implement for relevance can all be represented as lambdas like this. So checking if a campaign is active or not is straightforward. You just check the campaign status. Checking if a campaign is targeted at a specific slot or not is like comparing the slot of the request with the slot of the campaign. And gender targeting here happens to have like two different cases. A campaign is either targeted at a specific gender or it's, or it's not. So the maybe type in Haskell or the optional type in Java is perfect to represent both of these cases. The lambdas which I showed for relevance filters can be represented in Java using these predicates which just translate one to one. The next step in finding relevant campaigns is to somehow combine all these filters and then apply it on an input list of campaigns. One way to do this is to just chain all these filters and then apply them together. The campaign.getall method which I'm showing here is just for demonstration and in a real world that is terribly inefficient if you're just doing it on all your campaigns. Another solution instead of chaining these filters is to call an AND method on a filter and then combine these filters. This is not same as function composition because in function composition you have two functions with different type signatures. In this case all of these lambdas or functions have the same type signature and return a boolean. So this AND method helps you combine one filter with another filter to make them work together. So with this kind of abstraction in place adding a new targeting feature is now as simple as adding another predicate to the list. So let's say you want to implement location targeting for campaigns. You just implement a lambda for location targeting and then just chain it here. I'm just simplifying a lot of things here saying it's all AND but in the real world it could be a combination of AND and ORs. So the next step in ad selection is to select relevant banners for the campaigns that you've already filtered out. So to give you a very small example for this like let's say you have an ad request and you have a small size banner, a medium size banner and a large size banner. So this layer basically helps you in showing the right banner for the right request. And the matching the filtering criteria here could be in two ways. One is you either match the template or you either match the dimension. So template here is a concept that is often used in advertising in apps where a banner either fits a template or it doesn't fit a template. In the example which I showed earlier, brand story has a different template and carousel ads have a different template. So just like before the type signature for relevant banners here is a function which takes a list of campaigns per slot as input and returns a list of banners per slot as output. Again the filters for relevant banners can be expressed as lambdas. For template here is a lambda which checks if the banners template matches the request template. For dimension is a filter here which checks that the banners dimensions match the request dimensions. Let's say we want to combine these filters using an OR function. We can just combine these predicates using an OR. So far what we've been doing is to take functions that return booleans and then combine them using either an AND or an OR. So let's just see if there is a better way to combine functions that return booleans. These are some operations that you can do on a list or numbers or booleans. What is a common pattern here? Like I'll just give you a short time to go through this. So the common pattern here is the first common pattern here is identity. Like if you add an empty list to any list you get back the same list. If you add a zero to a number you get back the same number. If you add a true with a boolean value you get back the same boolean value. The next common pattern here is associativity. The order in which you combine these operations does not matter. So it turns out monoid is an abstraction of this common pattern. Let's see how monoid helps us in combining functions that return booleans better. The basic idea behind a monoid is this. Monoid is a type class and if your class implements a monoid type class and if you define what is identity and if you define how to append two things you get concatenation for free. So it turns out some classes can have more than one monoid. For example numbers have two monoids because the identity for sum is zero and the identity for product is one. Similarly booleans have two monoids all and any. That's because the identity for an AND operation is true and the identity for an OR operation is false. With this abstraction in place now we have a way to combine multiple functions that return booleans. Like let's say you had implemented the code for relevant campaigns and relevant banners in Haskell. Your original solution would have been to apply all the filters and then fold it using an AND value or an OR value or an OR function. So with this abstraction in place you have a list of filters which return either an AND or an NE and then you just concatenate them to combine all these functions that return booleans. The next problem that I'm going to talk about in the world of ad serving is ranking. Like let's say there are multiple banners in a slot. Ranking helps you in scoring these banners and then once you have scored these banners it helps you sort the banners and return the best banner for that specific request. Scoring here can be based on multiple criteria like price of the banner or the CTR of the banner or the conversion rate of the banner. I'll just show it with a small example here. Like let's say there is an ad request coming for r slash programming subreddit. There are three competing banners here from Try Closure, Try Erlang and Try Haskell. These banners are scored based on some criteria and Try Erlang gets a score of 0.85 here. Try Haskell gets a score of 0.75 and Try Closure gets a score of 0.65. After scoring, Try Erlang gets to show its banner on r slash programming. This is basically how ranking works in the ad world. So let's just repeat the process that we've been doing for relevant campaigns and relevant banners and define the type signature for ranking. The type signature for ranking here takes a list of banners as input and returns a list of banner scores as output per slot. The banner score object that I've shown here in the output is not just a score or a decimal value. It is a composite object containing both the banner and its score. One thing if you notice is that there is a common pattern here between relevant banners and ranking banners. The pattern is that both of these methods take a map as input and return a map as output. And if you see the type signature, the key remains the same in both the input and the output. The only thing that changes is the value. So this is very easy to abstract with a higher order function that takes another function as input. So this is a function that is commonly available in most libraries. Like if you have a map data structure in Ruby, there are libraries which give you a function like map values which transforms only the values. But it turns out in Java, map itself does not have a map function. So this is very easy to implement on your own with a higher order function like this, which takes a transformer function from key A, sorry, value A to value B as input. So with this abstraction in place, all of your implementations for relevance and ranking simplifies to calling map values with a function that does the transformation. Now coming back to scoring, you can score banners using some combination of all these different scoring criteria. Like let's say we choose price and CTR in scoring a banner. One simple formula that we could use is to assign 50% of the weight to price and 50% of the weight to CTR. In real world, this might change a lot. It can even be a product of price and CTR with some exponential coefficients. So one simple way to accomplish this is to take all the prices, take all the CTRs, zip them, and then apply a function which computes the score. The only problem with zip here is that it wouldn't work if there are more than two attributes, but you can still write other zip, zip three or zip four kind of functions which work with more than two attributes. The map values here is an example of a higher order function which takes another function as input. The scored function here is a first class function. It's only a coincidence that this function is being returned as the output of another method. You might as well assign it to a variable which is actually what a first class function is. We had a real use case where we had to rotate banners if the scores are equal. So to give you an example, let's say programming subreddit gets an ad request and there are three competing banners and all of them have an equal score. You have to rotate banners like this for every request. One simple way to accomplish this is to write a comparator function like this. This is like writing a function which compares people by their last names and if the last names are equal, you compare them by their first names. Compare can again be represented as a lambda. It turns out the monoidal properties that we looked at also apply to the ordering object in Haskell. The ordering object in Haskell is very similar to the output of compare. Like Java's compare returns minus one, zero and plus one and Haskell's compare returns less than equal to or greater than. So the way this ordering works is whenever you try to append to ordering together, if the first comparison returns a less than or greater than, it is going to directly return. Whereas if the first comparison returns an equal to, it is going to apply the second comparison. So with this, comparing two equals scores, sorry, comparing two equally scored banners simplifies to this.  So this will help you in easily rotating banners if the scores are equal. We will still talk about another problem in ranking. So one of the criteria which is used in ranking is CTR. CTR as I mentioned earlier is the click-through rate. It's a ratio of clicks to number of impressions. And most often this CTR is predicted using a machine learning model. I'll just skip the details of the offline model for this part and talk only about the online model. So this CTR prediction model is a logistic regression model. It takes a list of features as input. These features are often properties of supply, demand and user. An example of supply here is the slot ID. An example of demand here is the campaign ID. An example of user features here could be the gender or location of the user. The output is a predicted CTR, which is a probability from 0 to 1. This is the formula for calculating predicted CTR. It's very similar to the linear regression formulas that we know about. So the p-tas here corresponds to the model coefficients. The x's here corresponds to the Boolean values of the features. The p-CTR or the predicted CTR here is computed using a sigmoid function on this to return a value from 0 to 1. I'll just walk you through an example of a model evaluation and see how we can apply function programming in this. So let's say there is a request coming for a slot 123 for a campaign 123 and let's say we know that the user's gender is male and we don't know nothing about the user's category affinity. So one way to apply this p-CTR function is to take the model coefficients for slot 123, campaign 123, gender male and since we know nothing about the user's category affinity we pick the default category feature and once you apply all these coefficients you come up with a p-CTR whose value is 0.7%. Even though I've showed only like three of four features here in reality there could be a lot more features going on behind the scenes in computing a p-CTR. So I'll just walk you through the implementation of one of these features and then the same thing can be extrapolated to all the features. So there are two kinds of features here. One is a single valued feature and the other is a multi valued feature. Gender is an example of a single valued feature. And category affinity is an example of a multi valued feature. In case of gender we either know the user's gender or we don't. So this can be represented using a maybe type and we can pattern match on the gender and if it's nothing we generate the gender colon default feature and if it's a value which is wrapped in just we generate the gender colon male or gender colon female feature. So the way to combine this for CTR prediction is to generate all of these features for all the attributes look up all the coefficients and then reduce the value to a p-CTR. What you see here is Haskell code for this comparison and what you see below is the Java code. This can be done by calling a map method on Java's optional and Java does not have, Java 8 at least does not have pattern matching by default. This is the same implementation for a multi valued feature where you could change the container to a list instead of a maybe structure. So to understand how the map here on optional works in Java we'll just take a short detour to understand how functors work. So I'm going to borrow the explanation of functors from this blog post right here which has a very good explanation of functors applicatives and monads. So let's say you have a function called plus three. Plus three is similar to plus one or increment function. You can apply it on value two and get a value of five. So that's normal function application. But let's say I'm going to use the box analogy here for most of my explanations. Let's say the value of two is wrapped in some kind of box. The box here could be a maybe structure or a list structure. If you try to apply plus three on two in a box it is not going to work. So functors basically apply a function to a value in a box. So if you take the function plus three and apply it to two in a box using an F map, F map is going to magically get the value two from the box apply the function and return the value five again in a box. I'll briefly explain how this works for the gender feature that we just discussed. Like let's say you have two kinds of user, two kinds of requests. In one of the requests you know nothing about the user here. In the other request you have a user and you also know the gender of the user. For simplicity I'm just keeping the user as a maybe here and gender as a normal string. So if you try to generate the gender, gender feature using this it won't work because gender is a function that takes a normal user and returns his or her gender. Whereas what we have here is a maybe object. One way to make it work is to apply F map on it. So F map is going to help you apply the gender function on a maybe user. So that is exactly what we have tried here when we did a map function on the gender. This is going to work for both kinds of requests with or without a user and generate the corresponding model features. Another interesting problem in ad selection is explore or exploit problem. So the canonical name for this kind of problem is called a multi-arm bounded problem. Like imagine you're a gambler in Las Vegas and you have n arms and there are n slot missions. Each arm here corresponds to the number of options that you have available every time you decide to play. And each slot mission here comes with a reward and the reward is a probability distribution of how much money you can expect to make.  One is you can choose to always exploit by choosing the slot mission with the highest reward or you can choose to explore to learn more about the other slot missions. The explore, exploit, dilemma or tradeoff here is how often you choose to explore versus going for the machine with the highest reward. It turns out this has a direct analogy in the world of ad serving. The arms here corresponds to the number of banners that you have available and the reward here is the number of clicks or score that you expect to make.  The implementation of explore will probably consist of something like this. It'll have a function which decides when to explore or not and whenever it explores it goes with a different kind of scoring logic and whenever it is exploiting it goes with the actual scoring logic. One simple solution to explore is to order the banners randomly and this can be done by writing a function like this which computes random scores and uses those random scores instead of the actual scores. The other problem in advertising which I'll talk about is deduplication. So deduplication serves unique ads if there are multiple ad slots. Like in the carousel ads which we saw earlier you could end up delivering duplicate banners or you could end up showing duplicate advertisers or duplicate campaigns. An example of deduplication is something like this. In this specific example we are showing two Marvel movie ads and one DC Comics ad. According to dedu, this is wrong because you're showing two banners for the same advertiser. dedu actually fixes this by showing one Marvel ad, one DC Comics ad and one Hellboy ad. One way to implement dedu, the type signature for dedu takes a list of banners scores as input and returns an optional banner as output. It's optional here because at the end of dedu you can even make, end up making the whole slot empty. So it's representing either whether a banner is present or not. Dedu itself can be implemented in a lot of ways but first we need to check if dedupe is required or not. One simple way to do that is to check all your slots count the number of unique advertisers and match it with the number of unique banners. A simple way to do that is to collect all your banners across all your slots and then group them by their advertiser using something like a group by method and match the advertiser count with the banner count. The data structure that you end up with here is a grouping of banners by their advertiser and that can be used for actually implementing your dedupe logic. One of the other problems in dedu is that you want multiple options. In some cases you're okay with duplicate ads. Like in the case of exchange you're okay with duplicate ads and you don't want dedupe. In some cases you want dedupe by advertiser which is the Marvel vs DC example which I showed earlier. And in some other cases you're okay with showing duplicate ads for the advertiser as long as they belong to different campaigns like different Marvel movies. One way to represent all of these complexities is to have a function of banner and then wrap it in a container. Like if you don't want dedupe you can just set the dedupe criteria as nothing. If you want dedupe by advertiser or by campaign you create a function of banner and then put it in a container. This criteria will be used at some point in your dedupe logic. And one way to apply function which is wrapped in a container is applicative. This is, again I'm going to use the box analogy here. The way in which this differs from a functor is that in case of functor you only have the value in a box. In case of applicative you have both the function in a box and a value in a box. In this example here you have plus three in a box and two in a box. Applicatives extract the value from both of these boxes, apply the function and return the value five in a box. And one of the things which I skipped earlier is attribution. So attribution here is like an A, B test to find out how effective an ad is. So to give you an example like let's say there is a halo ad and there is a group of people in A who have not seen the ad and they are one person likely to buy the game. And there is a group of people in B who have seen the ad and who are 1.5% likely to buy the game. So attribution here helps you in doing that A, B test and in measuring how effective the ad is after the end of the campaign. The type signature for attribution looks something like this. It takes a list of banners as input per slot and returns a list of filtered banners as output for the same slot. Let's just say for example that you have an A, B service in place and it is quite expensive to call the A, B service once every banner and you want to do it together for all of your banners. One simple way to do this is to take all the banners from all the slots, flat map it and then pass the list of banners to the A, B service. What flat map is doing here is to convert a list of list of banners into a list of banners so that you can directly call the A, B service only once. Let's take another short detour. What we've done right now is to apply flat map to convert a list of list of something to a list of something. In the case of CTR model feature we talked about the case of handling if gender is present or not by doing a map on optional. There is also another case where the user itself may be present or not. Like to give you a small example if there is an ad request coming from app or desktop we may not know the user in all the cases. It might even be a new user. So we have to handle the case of user itself being present or not. So this is done in Java by doing a flat map on optional. So is there any similarity between the flat map that we do on optional and the flat map that we do on streams here? So what if we try to use a map instead of flat map here? The problem is if you try to replace that flat map with a map it won't even type check. Let's just see why. So this is the same code in Haskell. So what you're seeing here is a request. The user object is a maybe user. The gender object is also a maybe gender. User is a function that takes a request and returns a maybe user. Gender is a function that takes a user and returns a maybe user. Let's say you want to find out the gender of a maybe user. If you use fmap on it it is going to return a maybe maybe gender. Whereas if you use this magic function right here it is going to return the gender wrapped only once. It turns out monad is an abstraction of this common pattern. I'll again use the box analogy here. Like let's say monads help you apply a function that returns a value in a box to a value in a box. So let's just say you have a function here which is a half function. This function takes a number as input and returns half of the value as output. In this example it works only for even numbers. It doesn't work for odd numbers. For even numbers it returns a just 10. For odd numbers it returns nothing. Let's say you want to apply this function to a value 20 in a box. Let's just see what what all happens if we use different different function application operators. You cannot apply the value 20 in a box directly to this function. That won't type check. Whereas if you apply fmap on this function you're going to get the value 10 wrapped in the box twice. The box here is just a container like maybe or just whereas if you use the monad bind operator on this it is going to extract the value 20 from the box apply it on the function and return the value 10 wrapped only once. Let's just see how this applies to the same gender feature generator function that we're using here. So we have a maybe user which is the value that that you get by calling context.getUser. And you have a function here which takes a normal user and returns a maybe gender. If you you can't directly apply it again because maybe user and user won't type check. If you use fmap on it fmap is going to extract this user apply it on this function and it's going to return a maybe maybe gender which is exactly the case that we saw here. Whereas if you use the monad bind operator on this it is going to extract the user apply it and return maybe gender wrapped only once. Finally we need to tie all these steps that we have together to create a workflow. So in reality there could be multiple workflows like you could choose to have a different workflow for app and a different workflow for desktop and all that. It turns out a workflow is nothing but function composition. The function composition operator takes a function from B to C as input and another function from A to B as input and returns a function from A to C as output. This is a list of functions that we have so far. I've simplified it to remove the map and the slot but bringing it back is still the same thing. So we have a function called relevant campaigns which takes a context and returns a list of campaigns. We have a function called relevant banners which takes a list of campaigns and returns a list of banners and so on. All of these functions can be composed together nicely to create an app selection workflow which is not a lot different from the workflow box that you're seeing above. That's all I have. Questions? What I've shown is just using Haskell for prototyping and then trying to understand whatever we've done in Java 8 using Haskell's terms. We only use Scala and Closure in production. And by the way this is all in Java 8 this is not in Haskell in production because of No, in reality it was not prototyped in Haskell and Java. We've done analogous work in Java. Like we were far more productive in terms of adding more features. Like once we have the foundation in place it was pretty easy to add features. Like if you have if you're representing all your features as lambdas or if you're representing all your model features as these optional types in lambdas it was very easy to add successive features on top of that. Like basically we were trying to use whatever we knew from Scala or Haskell and trying to apply the same thing within the constraints of Java 8. Is there an advantage to move for moving to Java 8 when you get most of these things with Lomborg and IntelliJ and other things right? So Java 8 has a lot of other features which are which make it more functional than Java 7. Like the options of streams lambdas and optional types are native in Java 8 whereas they're not native in Java 7. So Java 8 still gives you a lot of benefits in trying to use functional style compared to Java 7. It's still possible to achieve all this in Java 7 by writing your own implementation of optional or Goa's implementation of optional and things like that. But Java 8 still gives you a lot of native benefits. Yeah. Which one are you talking about? Okay. The data model, sorry. So this is not possible in Java. You have to represent this as a this is kind of like an enumeration. So the way to represent this in Java is to create a maybe user and when that is nothing you treat it as an unknown user or if it's a just user you treat it as a as an actual user. So did you explore say functional Java or Java slang or one of those functional libraries that give you some of these type classes say monoid so they have they have sort of implemented those type classes. We've used only a library called Proton Pack. So that gives us features for doing zip and pattern matching. Proton Pack. Thanks everyone.


We learned there's a big learning curve to the space, so I talked to the department and they created a position for me for overseeing all the online projects, all the future MOOC projects for the Department of Biology. So that's what I do now, but it also entails working on projects for the residential courses with the MIT students and we create digital learning materials for them to help improve their experience on campus. And sometimes for all our MOOC material, we do use it on campus, but we also have some of the materials first created for the residential experience that then end up going out to the public through MOOCs. So I work with two postdocs that are full-time and then some grad students and undergrads help out from time to time. The unique thing about our models that we are domain experts and subject experts, but we also try to be the expert in technology, the expert in digital learning, and the expert in the learning sciences.


Hello friends, I am Rohit Kumar R. Vakhtarikar working as an assistant professor in computer science and engineering department at Walsh Institute of Technology, Swalapur. Today we are going to learn about the multiprocessor scheduling, learning outcomes. At the end of this session students will understand how multiple processor scheduling is used for load balancing to reduce the load of CPU. Now let's see the basics of multiprocessor scheduling. The name it will determine everything. It's a multiple processor scheduling, means in our single CPU we'll have the multiple processors for the execution purpose. Now when it comes for the multiple processors means we'll have the n number of processes for the execution purpose. So now when n number of processes will come for the execution on a single processor at that time that processor will get a heavy load and while executing all this process the throughput of that processor will be very poor. So now to improve this thing the load balancing concept has been introduced. To perform this load balancing we need to use the multiple processor scheduling here. It means here we'll have the multiple processors with multiple processes. So now here this concept is more complex than the single processor system. In multiprocessor system all the systems are nothing but the homogenous system. Homogenous system means all systems have the same configurations. Then we can easily move the process from the one system to the another system. So now while performing this movement or moving this process from one processor to the another process all these processes must be in the ready queue. So let's see the different approaches for the multiple processor scheduling. There are the two approaches. The first one is asymmetric multiprocessing. Second one is symmetric multiprocessing. In asymmetric multiprocessing we'll have the two types of system. One is a master system and another one is a slave system. The master system is nothing but the system who is going to decide everything. Like scheduling and IO processing things and other processes will just execute the user code. So now this concept is nothing but the asymmetric multiprocessing. This is a simple and it will reduce the need of data sharing. Because each system has its own data and is going to execute its own code. So now here let's see the example. Now in this diagram we'll have the process P1, process P2, P3 and P4. We'll have the four process. In that way we'll have one master process who is going to manage this slave process. Means while executing the different processes first this master process will schedule all this processor's task and then only the process is going to be executed. So let's see the next. Symmetric multiprocessing. In symmetric multiprocessing all processes may be in a common ready queue or each process may have its own private queue for ready processes. The scheduling process proceeds further by having the scheduler for each processor examine the ready queue and select the process to execute. Means in this symmetric process each processor has its own memory and its own queue for the execution of task. So now while executing the scheduler will take the charge for the scheduling of different process. Let's see its diagram here. Here we'll have CPU1, CPU2, CPU3 and CPU4. Now here all the CPUs are connected through one bus. Now here we'll have the different process P1, P2 and P3, P4 process. So now while executing this different process they can share their data to each other. So that is nothing but the symmetric multiprocessing. In asymmetric multiprocessing CPU are not going to share anything but in symmetric multiprocessing the memory is going to be shared between the different process. Now let's see the processor affinity. The system tries to avoid the migration of process from one processor to the other process and tries to keep a process running on the same processor. So that is nothing but the processor affinity. Means when many processes come for the execution of one system and that process is not able to execute the further task. So at that time that process needs to migrate its process from its processor to the another process. The process which is idle. So now here the processor affinity means avoiding the migration and try to keep a process running on the same processor that is nothing but the processor affinity. So there are the two types of processor affinity. First one is the soft affinity and second one is the hard affinity. The soft affinity when an operating system has a policy of attempting to keep a process running on the same processor but not guaranteeing it will to do. So this situation is nothing but the soft affinity. Means system is not going to allow further migration and still he is saying like there is no guarantee that the process will execute completely. So that is nothing but the soft affinity. Now hard affinity. Some system such as Linux also provides some system calls that supports hard affinity which allows a process to migrate between the different processors. So that is nothing but the hard affinity. So let us see the load balancing means what? Load balancing is the phenomena which keeps the workload equally distributed across the different processors in a symmetric multiprocessing system. Load balancing is necessary only on the system where each processor has its own private queue of processor which are eligible to execute. So these statements will define the criteria of symmetric multiprocessing. So now for the load balancing there are the two approaches. The first is the push migration and second one is the pull migration. Let us see the push migration first. In push migration, a task routinely checks the load on each processor and if it finds in an imbalance then it evenly distributes the load on each process by moving the process from the overloaded process to the ideal or less busy process. So that is nothing but the push migration means here it allows for the migration of the process from one processor to the another process and another way the pull migration means if this pull migration occurs when an ideal processor pulls a wetting task from a busy processor for its execution means that processor is going to take the other processors process for the execution purpose. So that is nothing but the pull migration. Now let us see this question how workload is equally distributed across all processors in an SMP system. So dear friends pause this video and write your answer. So let us see the answer. By using load balancing concept we can perform these things. In load balancing work is equally divided into the processors by using push migration and pull migration. Now here let us see the some basic introduction of multi-core processors. In multi-core processors multiple processors core are placed on the same physical chip means on a single physical chip will have the more than one multiple processors. So now each core has a register set to maintain its architecture state and thus appears to operating system as a separate physical processors. And now the next one is memory stall when processor access memory then it spends a significant amount of time waiting for the data to become the available. This situation is called the memory stall. Basically it occurs because of the cache miss means when any process is looking for the data then that kernel will first upon look into the cache and if the cache miss happens then that process needs to access that data from the main then secondary memory. So at that time here that process needs to wait. So that time or that situation we can call it as a memory stall. So multi-core processors. So basically to solve this problem recent hardware design implemented multi-threaded processor core in which two or more hardware threads are assigned to each core therefore if one thread stall while waiting for the memory core can switch to the another thread. So this thread will use for to avoid these memory stalls. Now let us see the references the operating system concepts by Galvin then system programming and operating system by Dumdery. Thank you.


What is going on guys welcome back to the channel and I appreciate you being here today I bring you the location of the no dance locations to and those battle stars for your battle pass You say challenge you should see in your suggested challenges until it's completed These challenges are for season 3 week 2 But by the way guys before we go any further because I'm beginning to post that fortnight content And you guys seemingly seem to enjoy it I will be giving away two thousand 800 v-books to win simply drop a like on this video and leave a comment down below Winner will be picked from the comment section of any of my fortnight videos over this next week And then contacted via youtube dm also big thanks to my life crisis for helping me find these locations So let's go unscreen now you can see the map of all the locations we have found so far if there are more Let me know down below in that comment section, but I leave there only 13 in total now although Only 13 here you only have to dance in front of five of these to get those battle stars So you can pick whichever five you want but unscreen now I will show you the location of all 13 spots we've found so far and because you don't pick where you actually spawn in It's probably best to pick the five closest to you We'll work around a map anticlockwise and starting with the first one which is just left of anarchy acres So if you're spawning a north side map this one is easy to get that's if no one else goes here The second one is located at junk junction a place. I rarely see many people go This one should be easy for you to find and do The next one is located just left of Pleasant Park on this hill So either land on top of this hill or build your way up like I had to The next one is just above snubby shores relatively easy to find Next up we have one in greasy Grove This place can get a little populated so be careful while dancing here The next one is more central of the map at tilted towers again This one can also get populated pretty quickly actually took me three attempts at recording this so be careful The next one is at flush factory locating at the bottom of the map The next one is located literally just above fatal fields this place as you will see always has people going here So be as stealthy as possible The next one is located again central of the map just by salty springs not the easiest one to locate So this should help you the next one is located near moisty Maya This one simple to get considering the bus sometimes can end its journey right in this area The next one is in retail row slap bang center of it So get this one as quick as possible and get out because this place does get populated The next one is located between retail row lonely Lodge and tomorrow town So as you can imagine this place can get hectic for sure And the last one is located just west of wailing woods another real easy one to locate for sure and Guys that is it all 13 known locations for the no dance spots to earn them five easy Battlestars if this video did help you out leaving like really does help me out if you're new around here And this is what you want to see be sure to subscribe and hopefully people I will see you on that next one


Hello everybody, welcome back to nerdy draws, which also happens to be my second time recording because I forgot to plug in my power source That really sucks. So today we are drawing Alice from the game Alice Madness Returns Which if you guys don't know is my absolute favorite game of all time. I have not, oh, I didn't mean to do that I haven't played Alice American McGee's Alice yet, but I really really want to I just haven't found my game because it's been lost ever since I got I've been interested in the art book So I really need to find that so that I can actually get then get all the downloadable games because I can actually play on my Xbox one now. I also started Recording some game footage, so I might be doing that soon. I will I'm trying to Finish my own life is strange game and then play life is strange before the storm for this actual channel So look forward to that. That's an actual dead set plan So you guys don't have to worry about me not doing that But as soon as before the storm comes out and I have enough money to pay for it I will play that because it's an exciting game, but enough about other franchises Let's talk about this one because it is amazing So I got the art book a few days ago I'm actually gonna make a vlog on this so if anything sounds a little bit redundant It's because I didn't really anticipate what I was making or putting into the vlog So, you know, we'll just leave that up to chance So this book I gotta tell you guys even if you're not a fan of this game or of Alice Manusher turns if you love dark art or just in general Creativity this is absolutely the book for you and that absolutely sounds like I'm advertising for it But I'm serious when I mean that Some of it is really messed up But it you have to appreciate the amount of creativity that went into this game, you know when you're playing the game you You can definitely tell that they put effort into it like the coding itself leaves a little to be desired But the creativity you can tell because of like the detail that goes into certain worlds and enemies and stuff Of course, there are things that I do think that they could have done differently like maybe have less They didn't that's something I noticed is that they didn't have big boss fights Like I know they had colossal ruin Which by the way, if you guys don't know is the absolute bane of my existence I would highly recommend you looking it up because it sucks.  It terrifies me so And also the ending I won't give any spoilers But the ending I kind of wish was done differently I kind of wish she was a little more violent honestly than it was But you know, there's there's obviously things that I feel could have been changed that other people would appreciate Because this game was good and this game had a lot of goodness to it So I'm actually looking through the art book right now There were a lot of levels that they wanted to put in the game but couldn't because of like technical details So they had they had let's see a water level and the level where you could like walk Underside that no upside down where you could walk upside down which is pretty cool But they ended up not going with it, but um so Getting into the actual game itself first of all in my opinion it was really really fun to play I know a lot of people would disagree with that but I just found it super interesting and I'm a simple person who plays games that are easy for me And so this definitely was according to my liking now. They do have on the game They have this game they have this game mode called nightmare mode, which I've never played But according to my boyfriend, it's like playing dark souls, which I'm not ready for I don't think I'm gonna play nightmare mode I think I'm just gonna stay in my nice little cavity of a Happy fun simple easy playing But this game was ever since getting the art book It's actually really inspired me like it inspired me to change up my art styles a little bit. So if you follow me on my my um My art instagram I posted a couple art styles that I had actually tried out because of this game And I didn't really like a lot of them, especially the realism one that one is really ugly But I ended up coming with this one at the end.  So that's why I decided to digitize it and The eyes were a little bit too big And I actually fixed this but I don't fix it in the speed pane because I sent it to my boyfriend and my boyfriend I asked him like what could I do better because it looks weird He was like well, maybe the eyes and I was like, yeah, dude true So I fixed the eyes a little bit, but you'll see it in the end drawing just not in the speed pane itself But this it was super inspiring especially because they're talking about In in the book they're talking about their process of how they like began with their creativity And it was really inspiring because they were like, oh we had art everywhere and I was like man, that would be great Man, if I could just draw so much that I had that much art that would be fantastic So as you can see I've got super hyped up for this art book. I got super hyped while reading it I got super hyped for the game itself. So I actually Really want to play that soon, which hopefully I will if I could play this for you guys. I would but I have Already played the game and usually the thing with uh playthroughs is that it's the element of surprise They usually people want to see you playing the game when you don't really know what's going on And I can't really provide that for people considering I've played this game three times And I'm super close to 100 percent That's just me bragging because I'm having a good time, but I can definitely say that this art book doesn't hold back on the boob Definitely not at all, but it's it's a great book and I would highly recommend anybody get it So like just look at previews online with some of the art that's in here. It's fantastic if You want inspiration. This is your place to go Also, the dresses in here were really really cool. The dresses in the game itself There is one dress that I find super Useless like let me see if I can find it in the book just so I can like reference the name of it I guess it doesn't have the name, but it's like the card dress or something I know I know what it looks like. I just can't remember exactly what it's called. It's like like card card something or other But it was it's kind of useless because you can get like up to 16 health in that game Actually, I think you can even do more depending on how many times you play it But you can get a lot of health and it reduces your health to like maximum four Which really sucks, especially when you're playing hard level bosses So that seems really useless the one I thought was actually really useful was I think it was the Ugh the steam dress because It drops more teeth when you kill an enemy And if you guys don't know teeth is the system that they use like point system that you can spend That you can spend on like upgrading your weapons and stuff That's also something I kind of wish they continued doing is making weapons Because I have a lot of teeth in that game since I played it three times And there is I got like 13,000 teeth and I have no weapons to upgrade or spend them on because I I upgraded all my weapons and I kind of wish I had more of that Like me me and my brother were kind of just going over ideas like If we could we would add this stuff because this game this game is so cool Imagine if you could like add what you wanted to it and just make it super perfect Like I I gotta give it to game coders, man. They they are good. They know lots and I've taken a coding class before I have actually taken Uh two years No, sorry one year of cc plus one year of html and css and one year of java. First of all I'd just like to say java sucks java can um Well, I have words for it that I won't say But I hate java html and css is honestly my favorite just because it's so easy and c++ is a little bit better But it was also really difficult for me I I know people would say differently, but If I could if I could code man, this this would be fun because I even brought up the idea because of this book of Like starting a game company with one of my friends because we all really like to draw and one of my friends is actually a really good coder So if she's watching this, hey, just a shout out You know who you are because I literally told you you were probably the only one I told about this idea So if you're listening to this then uh, yeah, you know who you are. Thank you very much for being so good at things But they had this this Book definitely tells a lot about some of the elements that are in the game That I kind of wish that they had done Like certain certain levels and all that But I appreciate the game for what it is. It is of course my absolute favorite game And while I have a lot of criticisms for it, I couldn't imagine Not having Alice the way it was it I got it. I think when I was way younger. I was like it was like in 2012 and My aunt had it and she didn't want to play it anymore. So she ended up just giving it to me And oh boy did I have a field day with this game. It was difficult. So I I finished it within A few months because that's how I play games usually But I finished it and it's one of the only one of the very few wrong games that I finished So we are coming to the end of this speed paint guys. I hope you guys enjoyed me Having a fandom talk slash drawing if you guys want me to draw something leave it down in the comment section below Hope you guys enjoyed bye guys


For an even easier and better experience, we've made a few changes to your favorite property portal. You can now quickly flip between different areas of the site, from sales to rentals listings, on-show properties, as well as farm listings and commercial listings. Sorting criteria has been made even easier. You have options to sort for most recent advertised properties, as well as price lowest or priced highest. Our filter options have moved to the right-hand side of the page, making it easier for you to search for relevant features. At the click of a button, you can quickly and easily identify home options, such as security features and amenities. Find out more about the area by scrolling down to our featured neighborhood section. And read up on area news in the property news section. The new bank sales page displays five ways to search for properties. Search all bank properties. You can search by location. You can search by bank. You can search by price range, as well as house type. Our new farms page displays sorting options as well. You can sort for most recent, priced lowest, priced highest, as well as lands are smallest to largest. Want to receive email alerts but don't have the time to fill out lots of info? With private property, it's as simple as adding your email address.


Hello, Pennsylvania. Tomorrow we're going to host a live streamed Facebook town hall where I will answer your questions about my 2017-2018 budget. I have been touring the state talking about my new way forward for Pennsylvania and I want to give all of you on Facebook a chance to participate. So send me your questions by leaving a comment on this post and tune in tomorrow to hear my answers live. Thanks.


Hey guys, how you doing? This is your boy rich and we are 42 days 11 hours 38 minutes and 15 seconds away From history in Canada and the market is responding. Look at all the green Unbelievable and of course your boy rich. We're on top of all of it put KB EV on full alert Make sure huge which I told you guys last night is on full alert HU GE FSDDF and T God TGOD up 21% Green thumb GTII up 20% Chiron life sciences KHRN up 17% Everything's on fire, but today I have some breaking news. Here it is Tetra bio pharma ink up 13% and look at this move up From 50 cents all the way to a dollar 25 in a month, but why you ask rich? Why is it so high? Look at this all the indicator strong by strong by strong by strong by strong by and strong by Let's read the news Tetra bio pharma announces record date for dividend in kind of North Bud farms shares Tetra bio pharma ink Tetra or the corporation on the TSX OTC QB under TB PMF a global leader in cannabinoid based drug development and Discovery announced today that its board of directors has declared a dividend in kind the dividend of 15 million five Fifteen million five hundred thousand common shares each a North Bud share of North Bud farms ink North Bud owned by Tetra pro-rata to the holders of record of outstanding common shares each a Tetra share of Tetra the shareholders of record as of September 7th 2018 the dividend record date the dividend will be payable on September 12th 2018 that tetra shares purchased on the TSX venture exchange the exchange or on or after September 6th 2018 will not be eligible to receive the dividend You must buy it by tomorrow The corporation would like to remind all holders of tetra options or warrants who intend to exercise their securities and Participate in the dividend that they should proceed to do so well in advance of The ex-dividend date in order to ensure that they are eligible to receive the dividend The North Bud shares were acquired by the corporation in connection with a previously announced sale by the corporation by Grow pros MMP ink details of which are contained in the corporation's previous press release issued on December 21st 2017 The dividend will be paid and satisfied in full by the corporation transferring the North Bud shares to the shareholders of record on the record date on a pro-rata Basis subject to certain adjustments to account for the corporations with holding obligations Under applicable tax laws as described below no fractional North Bud shares Cash or any other form of payment will be payable under the dividend Any fractional interest in North Bud shares under the dividend will be rounded down to the nearest whole number of shares Based upon the number of tetra shares Currently outstanding and without taking into account the exercise of any options or warrants Currently outstanding or the effect of rounding for fractional interests Approximately 0.1012 North Bud shares will be paid under the dividend for every one Tetra share held by a shareholder of record on the record date There you go. There's the breaking news and where you hear first right here from your boy rich Absolutely free. It's true. And of course Tetra bio pharma is up 13% on this news. What do you think? Do you think it's a big winner? If you do smash the like button share this video? Let it go viral imagine if you buy it. I buy it. We all buy it. We all win Which TV live is strictly for education entertainment purposes? We are not licensed advisors always do your due diligence always do your research before you invest in anything that we talk about here on rich TV live If you're not winning and you're not watching This is your boy rich and I'm oh 42 days 11 hours 32 minutes and 55 seconds away from history I'm up. We'll see you soon


I hear from lots of people every day who are concerned about how their diet is affecting their health. They need answers based on facts, in other words, from the peer-reviewed medical literature, and that is what I'm here for. Welcome to the Nutrition Facts Podcast. I'm your host, Dr. Michael Greger. Today we have the second in a two-part series where I offer some highlights from my latest book, How Not to Age, taped in front of a live audience. We pick up our story with tips on how to keep our vital organs in good working order.  Let me just share a few quick pearls. For example, did you know that 85% of bone-related fracture risk has nothing to do with bone mineral density? That's just been drilled into our heads by big farm and a billion dollar bone density screening industry. Fractures are primarily due to falling, not osteoporosis. So it's the age-related muscle loss and impaired balance that may be breaking most of our bones, which is good news because there's something we can do about it. Seven randomized controlled trials, strength and balance training cut fracture rates nearly in half, and that's just during the trial. In the five years after this one-year study ended, those who had previously been randomized to the combined strength and balance group suffered 74% fewer fractures. That's far more effective than osteoporosis drugs like Phosomax that can cause fractures, atypical femoral fractures and as many as 1 in 300 uses. They're called atypical because they occur not after a fall or trauma, but just during routine activities like walking, twisting at the hip, or just standing still. Thanks to the drug, your femur, your thigh bone, the biggest bone in your body just cracks in half. Too cruel an irony from a drug that's supposed to protect your bones. After bones, I talk about preserving your bowel function in chapter number two. Randomized constipated diabetics to either cookies containing a tablespoon, a day of ground flax seeds, or flax-free placebo cookies for 12 weeks, and not only does the flax improve constipation symptoms, but resulted in 8-pound weight loss over placebo, 25-point lower blood sugars, an astounding drop in hemoglobin A1c, and 17-point lower LDL cholesterol, all for about 10 cents a day of ground flax seeds. For a head-to-head test between flax seeds and psyllium, sold as metamucil, a third cookie group was added, about 10 grams of psyllium, and the flax seed beat out the psyllium for constipation relief, weight, blood sugars, and cholesterol, and is about four times cheaper. Flax seeds were also directly compared to the prescription laxative lactulose, and worked better as well. Bladder function. Prevalence of overactive bladder syndrome increases with age, reaching about one in three. No wonder bladder-relaxing drugs are a multi-billion dollar industry, yet may only reduce bathroom breaks by about half a pee a day compared to placebo. But a quarter teaspoon a day of dried cranberry powder worked nearly four times better, about two fewer daily trip to the bathroom over placebo, and that's without any of the drug side effects, dry mouth constipation sedation-impaired cognition, rapid heartbeat, urinary retention, and the urinary and the visual disturbance that lead almost two-thirds to stop taking the drugs, whereas cranberries are just tangy. Urinary incontinence is a common problem among older adults, particularly women, thanks to childbirth. Systemic menopausal hormone therapy like premarin actually makes it worse, but local vaginal estrogen may help. What works five times better than estrogen cream, though, kegel exercises, pelvic floor exercises, as I detail in the section jacked in the box. For men, urinary issues are more an enlarged prostate problem, having to get up multiple times a night, wee hours of the night. Cranberries to the rescue there again, even just a eighth of a teaspoon a day of powdered cranberries can significantly improve prostate symptoms. You can buy cranberry powder in bulk at a cost of less than a penny per day. What about sol-palmetto, the most common herbal supplement used for prostate symptoms, based on dozens of randomized controlled trials involving nearly 5,000 men? No clinical benefits, but pumpkin seeds work. More than a thousand men with prostate symptoms were randomized to either about a tablespoon a day of plain pumpkin seed kernels, a proprietary pumpkin seed extract or placebo. The study was funded by the drug company that made the supplement, but the supplement totally flopped while the pumpkin seeds themselves worked. Pumpkin seed oil was pitted against the leading drug for hair loss in women. A little less than a quarter teaspoon applied to the scalp once a day versus a dose of the drug, and they both worked, but the drug worked better. But rosemary oil, however, may be more closely matched. 100 balding men were randomized to twice a day minoxidil like Rogaine versus a rosemary lotion. It took six months, but significant comparable improvements in hair counts in both groups with no significant difference between the two. The rosemary lotion appeared to work as well as the drug. If you want to give it a DIY try, you can pre-mix about 10 drops of rosemary essential oil to each fluid ounce of your favorite lotion and rub a quarter teaspoon on your scalp twice a day. Cost-wise, that much rosemary oil would come out to be about a penny per week. Let's move on from hair highlights to hormones. I touched upon how menopausal hormone therapy can increase the risk of urinary incontinence, but that's not all. If 1,000 post-menopausal women, women take the standard hormone regimen for 10 years, you'd not only expect 876 extra cases of urinary incontinence that they would not have gotten otherwise, but nine more cases of invasive breast cancer. Eight more cases of heart disease, probably 22 more cases of dementia, 21 more cases of gallbladder disease, nine more strokes, and 21 more blood clots, though not a single partridge nor pear tree. However, hormone therapy is highly effective in decreasing menopausal hot flashes. Is there any way to keep cool without the clots in cancer? In the U.S., menopausal hot flashes are considered inevitable, but there isn't even a word for hot flash in Japanese, and this may be due to their greater consumption of soy foods, but you don't really know until you put it to the test. Harvard Center of Excellence in Women's Health funded a randomized crossover trial of a half a cup of unsalted soy nuts a day and achieved about a 40 to 45 percent reduction in hot flashes within two weeks compared to the control group. Given that a plant-based diet may also be effective for managing menopausal symptoms, researchers decided to combine the two of plant-based diet plus whole soybeans. In fact, two randomized control trials found that plant-based nutrition with a daily half cup of cooked whole soybeans can reduce the number of serious hot flashes by 84 to 88 percent within 12 weeks. Overall, most randomized to the plant-based bean group ended up free of moderate to severe hot flashes compared to about 95 percent sill suffering in the control group. Lots of other things can help whole fennel seeds powdered into capsules to pit them against placebo in a double-blind trial significantly improve menopausal symptoms at a dose of about a teaspoon a day. Fenugreek may also help at a dose of one and a half teaspoons a day, though not as much as hormones but without the side effects. Though fenugreek can make your pee smell like maple syrup, sounds like a bonus. The nice thing about studying spices is you can entire servings can be stuffed into a pill to pit them against placebo. A quarter teaspoon of black cumin powder a day led to significant improvements in memory and other tests of cognition within nine weeks compared to placebo. Black sesame seeds less than a teaspoon a day of ground black sesame seeds stuffed into capsules against placebo drove down systolic blood pressures by about eight points within a month. If sustained that alone could decrease the risk of stroke by about a quarter. What else can we powder? Strawberries, osteoarthritis patients were randomized to two ounces of freeze dried strawberry powder versus a fake strawberry flavored and colored placebo powder and compared to placebo the real strawberries significantly decreased constant pain intermittent pain and total knee pain and improved disability and overall quality of life. Osteoarthritis is the most frequent cause of physical disability among older adults yet how do we treat it? Acetaminophen Tylenol is considered the first line pain killer but guess what it doesn't work. I mean it works just not much better than a sugar pill but at least it's not going to make things worse. Like other things we doctors have cooked up like steroid injections which actively worsen joint deterioration and offer no greater pain relief than placebos or arthroscopic surgery which may end up tripling our risk of ending up having to get a total knee replacement. I mean so you know even if the strawberry study is some total fluke what's the worst that can happen? Tastier smoothies? And listen to the quarter of a teaspoon of ground ginger a day can beat out placebo for joint pain. Researchers conclude ginger therefore is recommended as a safe drug for these patients but by drug they just mean a couple pinches of the ground ginger you can buy at any store. There was even a study on topical ginger at least when applied to the scrotum paper thin slices of ginger applied over the inflamed testicles and the researchers were on the ball healing nearly three times faster than the control room. There have been more than a hundred randomized controlled trials on ginger shown to help with nausea and vomiting and everything from COVID to PMS, heavy periods, painful periods, migraine headaches, multiple sclerosis, and the list goes on. Bottom line mounting evidence suggests ginger can promote healthy aging.  Literally a hundred marines were randomized to a clove a day or a placebo and those on garlic had significantly fewer tick bites though sadly garlic does not appear to help against other blood suckers. So far I've touched on preserving your bones, bowels, bladder, hair, hormones, and joints but preserving your mind is the largest chapter in the book because dementia is one of the most pressing public health problems and most feared condition of later life. There's a common misconception that we have no control over whether we develop dementia but the good news is that although Alzheimer's may be incurable at least it is preventable. There's an emerging consensus that what's good for our hearts is also good for our heads. Clog with cholesterol, closing off arteries, clamping down blood flow.  Too much cholesterol in our blood is unanimously recognized to be a risk factor for the development of Alzheimer's disease. Those with a total cholesterol of 225 or more may have nearly 25 times the odds of ending up with amyloid plaques that plaques in their brain 10 to 15 years later. Cholesterol explains how the Alzheimer's gene apoE4 ravages the brain. After all, apoE is the primary cholesterol carrier inside the brain. LDL cholesterol in those with low kind of bad gene variants of apoE averages 40 points higher but switch people to a diet lower in animal fat and that cholesterol difference can be effectively smoothed out so diet can trump genetics. This may explain the so-called Nigerian paradox where they have among the highest rates of the Alzheimer's gene but some of the lowest rates of Alzheimer's disease. How is that possible? Genes load the gun but lifestyle pulls the trigger. The paradox may be explained by their low cholesterol levels probably because of their diet's low in animal fat. Human beings may have evolved to maintain an LDL cholesterol level of around 25 but the average in the western world is approximately 120. No wonder heart disease is the leading cause of death in high income countries and dementia is killer number two. That helps to explain why the so-called Alzheimer's gene is the single most important gene when it comes to longevity too which is good news because even if we've been dealt some bad genetic cards we still may be able to reshuffle the deck with diet. So in terms of dietary guidelines for the prevention of Alzheimer's we should center our diets around vegetables, legumes, fruits and whole grains. In other words the dietary pillar of lifestyle, medicine, whole food, plant-based nutrition or even simpler plants plants and more plants any plants in particular. Note that the director of Loma Linda's Alzheimer's prevention program single up berries and greens eating strawberries and spinach can mitigate age-related cognitive decline in rats but what about in people? When the cognition of hundreds of twins was followed over a decade consuming the berry pigments in less than a quarter cup of blueberries a day or about a cup of strawberries was associated with slowed cognitive aging by about four years and nearly all the randomized controlled trials on blueberries and cognitive performance found improvements in at least one brain domain perhaps because blueberry consumption can improve blood flow to certain critical regions of the brain. Now the one study that flopped mixed the berries with milk and we know that the addition of milk can prevent the artery protective effects of tea and prevents the bump in antioxidants that you'd normally get eating dark chocolate and impairs the absorption of the autophagy activating compounds in coffee. What about mixing berries and cream? The antioxidant activity of blueberries is not just impaired by milk researchers found that the total antioxidant capacity of our bloodstream measured in two different ways shoots up within an hour of eating a cup and a half of blueberries with water and remains elevated five hours later with milk and maybe we'd expect like less of a bump but in fact they ended up worse than when they started after eating a whole bowl of blueberries they ended up with less antioxidant capacity in their body because they ate the blueberries with milk. One reason greens may be referred to as an anti Alzheimer's plant is because dark green leafy vegetables can also improve blood flow in the brain and interventional trials randomized older adults to the greens pigments found in a cup of days worth of cooked kale and see significant improvements in complex attention cognitive flexibility and those randomized even just half a cup of kale's worth of the cruciferous compound sulforaphane got significant improvements in processing speed and working memory. Here's the rate of cognitive decline in elderly men and women eating a serving a day of green leafies compared to those only eating greens about once every 10 days. Are you sitting down? The rates of decline among those who consumed one to two servings of greens a day was equivalent to being 11 years younger so now are you sitting down to a big salad? Greens come up in chapter after chapter what's the recommendation for preventing age related macular degeneration are leading cause of blindness or even treating it in its earliest stages consume a diet high in green leafy vegetables. We're talking two to three servings a day so at least greens at every lunch and supper with bonus points for sneaking them into breakfast and like a green smoothie in fact blending greens can triple the bioavailability of a key vision protecting nutrients. The main reason greens make it into my anti-aging eight though is because of the nitrates and the serving two of cooked greens can slow our metabolic rate for the same reason that a little shot of beet juice can help freedivers hold their breath longer because it improves the efficiency of our mitochondria little power plants and ourselves allowing us to effectively extract more energy from each breath. Another dietary intervention that is a similar effect on slowing metabolism is calorie restriction right the candle that burns half as bright burns twice as long but instead of starving all the time you can just eat a big salad. What else can greens do? The Harvard nurses health study the consumption of leafy greens appeared to protect against the development of frailty and when put to the test in a randomized double-blind placebo controlled trial the equivalent of two-thirds of a cup of spinach led to a significant boost in muscle strength muscle quality and muscle mass in older men and women. A single cup of cooked greens worth of vegetable nitrates significantly boosted maximal power and velocity in quads so much it was functionally equivalent to acutely reversing the effects of several decades of aging a single cup of cooked greens. Of course when most people think about maintaining muscle mass into old age they don't think spinach they think protein but if you put together all the randomized controlled trials of adding extra protein to the diets of older men and women you find no evidence that adding protein increases muscle mass restraint. Okay yeah but what if you have sarcopenia excessive age related muscle loss right surely then protein helps right no no significant effect on physical performance or muscle strength what does work exercise when it comes to age related muscle mass it's use it or lose it maybe exercise plus protein no protein supplementation does not significantly augment the effects of strength training in older adults in fact one of my anti-aging eight is protein restriction why do longevity experts like valter longo recommend people cut down on protein to live long here's what luigi fontana wrote in his book he's the director of another leading longevity research center excess protein may not mass your muscles but it will accelerate aging how do you boost the pro longevity hormone fgf-21 dietary protein restriction how do you suppress the age accelerating enzyme igf-1 you do it through dietary protein restriction how do you suppress the so-called motor of aging m-tor dietary protein restriction in fact protein restriction was the only intervention i could find that could slow down all 11 of the aging pathways which is good news because it's easier to cut back on protein than to cut back on everything walk around starving all the time and it may even be easier than that most or all of the life extending benefits of protein restriction maybe due to just restricting particular amino acids like methionine in that case you could even keep your protein intake the same but just swap sources from animal proteins like meat to plant-based sources like beans so in humans methionine restriction can be achieved using a predominantly plant-based diet which makes methionine restriction feasible as a life extension strategy of course drug companies look at this same data and think what pharmaceuticals can we develop to mimic these dietary interventions anything else that can maintain muscle mass other than greens and machines how about cocoa beans older men and women are randomized to a single tablespoon of regular cocoa powder a day experience the significant improvement in muscle strains muscle mass and all four measures of physical performance and no the study was not funded by hershey's unfortunately the tastiest cocoa did not work as well the control groups here were just given the same amount of highly dutched cocoa alkalized cocoa where some of the bitter compounds removed during the dutching process are the very flavonoids responsible for the benefits but natural cocoa is so good it can improve walking performance in those with peripheral artery disease not only by improving blood flow but as muscle biopsies showed by improving mitochondrial activity this is consistent with improved mitochondrial structure as well in biopsies taken from people's quads though this study was actually funded by hershey's what else can cocoa do increase the circulation within our skin boosting at 70% within two hours after less than a tablespoon do that every day and within three months you end up with significantly improved skin thickness density and hydration but no change in wrinkles however keep it up for six months and you do see an improvement in wrinkles a significant decrease in wrinkle depth along with an improvement in skin elasticity within 12 weeks all by making your life a little more chocolatey by just adding some natural cocoa powder to your daily diet i uh put it in my oatmeal with uh you know some canned water packed tart cherries for a chocolate covered cherry sensation what else can we do for our skin well there certainly are other antioxidant anti-inflammatory glycotexin free foods so when patients inquire about a diet that might contribute to younger looking skin right evidence supports a recommendation to follow a whole food plant-based diet but the most important thing to prevent skin aging is avoid the sun exposure to sunlight may account for 90% of visible skin aging that's why dermatologists agree there's nothing more important to slow the signs of aging than to protect your skin from the sun the gold standard is considered to be the use of sunscreens in the daytime and so-called retinoids at night they're talking about a prescription only form of topical vitamin a also known as all-trans retinoic acid or tritinoin sold as retin A that has been widely proven to improve skin performance the only skin appearance the only problem is that it may kill you topical tritinoin therapy and all-cause mortality randomized control trial had to be stopped early because significantly more people were dying in the retinoic acid group compared to the placebo cream group when applied topically one day percent is absorbed into the bloodstream could it be killing people well while the debate continues as to whether the increase in deaths was just some statistical fluke or real biological effect tritinoin continues to be banned in europe for cosmetic purposes so what can we use topical niacinamide also known as nicotinamide is described as one of the best studied anti-aging skin cream ingredients which is not saying much but it has been shown to reduce yellowing wrinkling blotchiness and dark spots in aging facial skin for example significantly reducing crow's feet wrinkles around the eyes this was a split face study in which 64 percent of the niacinamide side eye wrinkles had moderate or market improvement compared to zero percent of the placebo side eyes topical vitamin c also similar improvements over placebo and wrinkles salinus and skin tone or firmness unfortunately vitamin c is unstable in creams turning an unsightly brown when it oxidizes limiting its shelf life so instead what the skin industry does skin care industry they use the stable vitamin c esters or derivatives but there's no evidence that these compounds have comparable effects likely because they're poorly absorbed oh excuse me and only minimally convert to the active form but the good news is you can make your own the 10 solution using that study retails for ridiculous 127 an ounce but you can make a diy solution more than 2 000 times cheaper by simply buying a scorpic acid in bulk and mixing three grams into 30 grams of water at a cost of about a nickel per ounce drip a few drops into the palm of your hand and use your fingertips to apply it over your face neck upper chest just don't get it in your eyes and look you can do the same thing with niacinamide which can be even more ridiculously priced but you can buy it in bulk as well at a 5000 discount all right i can go on and on certainly the book does but let me close out by going back to the basics from the anti-aging journal rejuvenation research finally a regimen to extend human life expectancy was it some exotic new stem cell treatment or gene therapy no it was a reference to this Harvard analysis more than 100 000 men and women were followed for decades and even just basic lifestyle behaviors appeared to translate to 12 to 14 extra years um for the average 50 year old even at age 50 we may be able to add an extra dozen years to our lifespan even at age 70 there could still be 10 extra years on the table and if you clean up your life before 50 nearly 18 years maybe up for grabs based on the simple common sense behaviors that's the kind of life extension extrapolating from uh some of these lab animal experiments but after decades of research and hundreds of millions of dollars later efforts to translate these results into humans have largely been in vain yet here we are with human data suggesting dramatic life extension is available to all of us right here right now the the the the trillion dollar pill that anti-aging biotech has been promising us is here it just effectively has to be administered in the produce aisle and the gym and turning back the clock not with a drug or a delorean but just by eating and living more healthfully a mid-life shift between the ages of 45 and 64 to even the barest of minimums the barest of minimums so what are we talking about at least five servings of fruits and vegetables day walking even just 20 minutes a day maintaining healthy weight and not smoking can result in substantial reduction in mortality even in the immediate future right we're talking a 40 lower risk of dying in the subsequent four years the researchers conclude that making the necessary changes to adhere to a healthy lifestyle is extremely worthwhile and middle age is certainly not too late to act you hold the power we would love it if you could share with us your stories about reinventing your health through evidence based nutrition go to nutrition facts dot org slash testimonials we may be able to share it on social media to help inspire others if you see any graphs charts graphics images or studies mentioned here please go to the nutrition facts podcast landing page there you'll find all the detailed information you need plus links to all the sources we cite for each of these topics my latest book how not to age is out now premiering at number two on the new york times best solos list check it out of your local public library of course all the proceeds of the sales of all my books goes directly to charity nutrition facts dot org is a non-profit science based public service where you can sign up for free daily updates on the latest nutrition research with bite size videos and articles everything on the website is free there no ads no corporate sponsorships no kickbacks strictly non-commercial i'm not selling anything i just put up as a public service as a labor of love as a tribute to my grandmother whose own life was saved with evidence-based nutrition


1. Garbage. My dog monster is the best in the world. Fact. Dad says he's probably half dog, half mole, because he's so good at digging tunnels, mainly underneath our garden fence. He's really round, so it's a miracle he doesn't get stuck. I watched him do it once. He sat on the flower bed and stared at the wooden panels, as if he was trying to work out how to tackle them, and then he began to dig. Dirt flew from under his wagging tail, and then he did this weird shuffling along on his stomach thing, with his back legs flattened on either side. The next second, he was gone. When he escapes, he always heads to the same place, Mrs Banks' front garden.  And I mean everything. He threw up a pair of underwear onto the living room carpet once, and mum wasn't sure if she should wash them and take them back to Mrs Banks. I pointed out that if they were in the garbage in the first place, then she obviously didn't want them, did she? Mrs Banks caught monster going through her garbage for the third time this week. She arrived on our doorstep, with him tucked backward under her arm. His tail was wagging around and around, like it does when he's happy, and she had to put her head to one side to stop it from hitting her in the face. You do realise that this animal is completely out of control, don't you, Mrs Beckett? She said. Mum was a bit flustered, because she'd been in the middle of an argument with Dad when she answered the door. Monster stopped wagging and began to wriggle, but the more he wriggled, the more Mrs Banks gripped onto him. He's been going through my trash again, and he left a present on my lawn. A present, said mum, rubbing her forehead. Yes, Mrs Beckett, a present.  Monster's tail wagged again, as if he was showing us all where the present had come from. I snorted, and Mrs Banks shot a look at me. There was a high-pitched yelp, as she tightened her grip around my dog even more. You shouldn't be holding him like that, I shouted. He- Sample complete. Ready to continue?