Systems and methods for mapping and routing based on clustering

Unique identifiers (IDs) associated with a plurality of nodes may be provided. Nodes clustered within a community may be assigned numerically proximate unique IDs. A number of partitions associated with a plurality of machines may be determined. The unique IDs may be segmented into divisions based on the number of partitions. The unique IDs may be mapped to the plurality of machines based on the divisions.

FIELD OF THE INVENTION

The present invention relates to the field of clustering. More particularly, the present invention provides techniques for mapping users based on clustering.

BACKGROUND

Social networking websites provide a dynamic environment in which members can connect to and communicate with other members. These websites may commonly provide online mechanisms allowing members to interact within their preexisting social networks, as well as create new social networks. Members may include any individual or entity, such as an organization or business. Among other attributes, social networking websites allow members to effectively and efficiently communicate relevant information to their social networks.

A member of a social network may highlight or share information, news stories, relationship activities, music, video, and any other content of interest to areas of the website dedicated to the member or otherwise made available for such content. Other members of the social network may access the shared content by browsing member profiles or performing dedicated searches. Upon access to and consideration of the content, the other members may react by taking one or more responsive actions, such as providing feedback or an opinion about the content. The ability of members to interact in this manner fosters communications among them and helps to realize the goals of social networking websites.

Even routine usage of social networks may involve creation of large volumes of data over a vast array of computing resources. The ability to manage such volumes of data in a manner consistent with member expectations is important to optimal operation of social networks. For example, in their interactions with others, members who request resources of the social network desire timely presentation of information. As another example, members who may perform searches on the data maintained by the social network expect a timely return of search results.

SUMMARY

To cluster nodes and map the nodes to computing resources for optimal system performance, computer implemented methods, systems, and computer readable media, in an embodiment, may provide unique identifiers (IDs) associated with a plurality of nodes. Nodes clustered within a community may be assigned numerically proximate unique IDs. A number of partitions associated with a plurality of machines may be determined. The unique IDs may be segmented into divisions based on the number of partitions. The unique IDs may be mapped to the plurality of machines based on the divisions.

In an embodiment, the plurality of machines may include a cache layer.

In an embodiment, a query associated with a node may be received. A unique ID for the node may be determined. A machine to which the node is mapped based on the unique ID may be determined. The query may be routed to the machine.

In an embodiment, a unique ID associated with a node may be determined based on a mapping of preexisting IDs to the unique IDs.

In an embodiment, a query associated with a node may be received. A unique ID for the node may be determined. A first machine to which the node is mapped may be determined based on the unique ID. A load of the machine exceeding a threshold may be detected. The query may be routed to a second machine.

In an embodiment, two or more geographic locations with complementary traffic usage patterns may be detected. Unique IDs associated with the two or more geographic locations with complementary traffic usage patterns may be mapped to a machine.

In an embodiment, the two or more geographic locations may be countries.

In an embodiment, the complementary traffic usage patterns may include high traffic usage and low traffic usage according to time.

In an embodiment, an impact to locality may be determined. The mapping of unique IDs may be in response to the determined impact.

In an embodiment, a query associated with a unique ID associated with one of the two or more geographic locations may be received. The query may be routed to the machine.

In an embodiment, two or more geographic locations having different time zones may be detected. Unique IDs associated with the two or more geographic locations may be mapped to a machine.

In an embodiment, a machine having a load above a threshold may be detected. At least one unique ID may be mapped away from the machine.

In an embodiment, a prohibited application associated with an unused shard of a machine may be identified. The prohibited application may be unavailable to users associated with a first geographic location. Additional unique IDs may be mapped to the unused shard of the machine. The additional unique IDs may be associated with users associated with a second geographic location.

In an embodiment, the mapping of the unique IDs to the plurality of machines may include evenly distributing the unique IDs.

In an embodiment, the mapping of the unique IDs to the plurality of machines may include unevenly distributing the unique IDs.

In an embodiment, the plurality of nodes may be associated with users of a social networking system.

In an embodiment, the plurality of nodes may be associated with at least one of persons, non-persons, organizations, content, events, web pages, communications, objects, or concepts.

In an embodiment, the grouping of the classifications into first level communities may include maximizing at least one of a number of connections or a strength of connections within a community, and minimizing at least one of a number of connections or a strength of connections between communities.

Many other features and embodiments of the invention will be apparent from the accompanying drawings and from the following detailed description.

The figures depict various embodiments of the present invention for purposes of illustration only, wherein the figures use like reference numerals to identify like elements. One skilled in the art will readily recognize from the following discussion that alternative embodiments of the structures and methods illustrated in the figures may be employed without departing from the principles of the invention described herein.

DETAILED DESCRIPTION

Node graphs, such as social graphs, may include an extremely large number of nodes and connections (or edges) between the nodes. The number of nodes, for example, may be in the hundreds of millions or even billions. In many cases, such as with social networking systems implemented by a networked computer system, users are able to access and share vast amounts of information with other users. The storing and providing of such vast amounts of data present many challenges. These challenges may include, for example, the significant computational and memory requirements that are involved in determining how to partition the node graph over a distributed system. For example, performing a query (or request) over the distributed system may potentially require a query to a large number of machines. This “fanout” of queries may not only slow down the query response time, but also may place excessive strain on the network.

The partitioning of the node graph information across the distributed system can have a great impact on the computational speed of and strain on a network. For example, where user information is stored (e.g., which machine) and how the user information is accessed or stored (e.g., in persistent memory or fast memory) may significantly impact the amount and speed of computations. Embodiments of the systems and methods described herein relate to generation of unique IDs which may be used to partition a node graph across a distributed system in an optimal manner. For example, the unique IDs may be generated in a manner that clusters nodes based on their relationships, and increases the tendency of these clusters to be local to the same machine.

Computational and network performance may be affected by the amount of traffic that the machines receive. Usage patterns may vary the amounts of load put on machines. Embodiments of the systems and methods described herein also relate to managing and balancing such load across machines. This may include, for example, determining usage patterns related to clusters and their corresponding effects on loads of machines, and then reallocating clusters to machines in a manner to better balance load.

FIG. 1illustrates an example clustering module100, according to an embodiment. The clustering module100includes identification module102and mapping module104. The clustering module100may be implemented as part of a distributed system of networked computers, such as part of a social networking system. The components shown in this figure and all figures herein are exemplary only, and other implementations may include additional, fewer, or different components. Some components may not be shown so as not to obscure relevant details.

The identification module102may generate unique identifiers (IDs) to be assigned to nodes of a node graph. In an embodiment, the nodes may be associated with users of a social networking system. In an embodiment, the nodes may be associated with, for example, persons, non-persons, organizations, content (e.g., images, video, audio, etc.), events, web pages, communications, objects, concepts, or any other thing, notion, or construct, whether concrete or abstract, that can be represented as a node. The unique IDs may be generated by first determining a classification for each node. In an embodiment, the determination of a classification may be based on any attribute (or attributes). For example, the attribute may relate to geographic location (e.g., city of residence). In an embodiment, the determination of a classification is not based on edge weights between nodes, as described in more detail herein.

The classifications, in turn, may be grouped into a higher level communities based on edge weights defined between classifications. In certain embodiments, the edge weights may be based on a number of connections between classifications, the strengths of connections between the classifications, or a combination of these or other factors. Resulting communities may be iteratively grouped again into still higher level communities. These groupings into still higher level communities also may be based on edge weights between communities. The nodes may then be sorted by classifications and all levels of communities, and subsequently assigned unique IDs in a numerically sequential manner, as discussed in more detail herein.

In an embodiment, connections may represent any types of activities, interactions, common interests, or other shared characteristics between classifications and communities. The edge weights may account for shared characteristics differently. For example, a first type of shared characteristic may reflect a stronger relationship between two classifications or communities than a second type of shared characteristic. Therefore, based on their relative importance, the first type of shared characteristic may be weighted more heavily than the second type of shared characteristic. Accordingly, edge weights may reflect the relative importance of various types of shared characteristics. The value associated with shared characteristics can be represented by coefficients, as discussed in more detail herein.

The mapping module104may utilize the set of unique IDs for all nodes (also referred to as the “unique ID space”) to partition the node graph over a networked computer system. In an embodiment, the unique ID space may be used to map nodes onto database servers of a networked computer system. In another embodiment, the unique ID space may be used to map nodes onto cache systems of a networked computer system.

The mapping module104may divide (or segment) the unique ID space by the number of partitions and route nodes to machines of the networked computer system based on the divisions. In an embodiment, these divisions may be equally weighted in certain instances to have the same number of unique IDs per division. In another embodiment, the divisions may not be equally weighted. The mapping module104may map nodes to machines based on their associated unique IDs, which results in a tendency of closely connected nodes (e.g., users and their friends) to be clustered on the same machine (or closely associated group of machines, such as a machine pool for instance). In an embodiment, the mapping module104takes into account load balancing considerations to map nodes to optimize the load on machines.

FIG. 2illustrates an example identification module102, according to an embodiment. The identification module102may define a new graph of classifications (e.g., geographic location) instead of the original nodes. The identification module102may include classification determination module202, community generation module204, and ID assignment module206. The classification determination module202may identify an attribute related to the nodes of a node graph, and may determine a classification for each node based on the attribute. An attribute may be any feature or concept according to which the nodes may be grouped. In an embodiment, more than one attribute and different combinations of attributes may be selected and used to classify nodes.

In an embodiment, an attribute may be a geographic association, such as an associated city, neighborhood, county, or other geographic location. Each node may be classified by its geographic association. For example, a social graph may include users as nodes and friendships as connections (or edges) between the nodes. An attribute of the users may be an associated city (e.g., city of residence). In such case, each user may be classified based on the city that is associated with the user. The users classified based on a city or other association may constitute a community of users.

Attributes that correlate strongly with connections between nodes may facilitate determination of communities. For instance, in the example of a social graph, geographic association may correlate strongly with friendships since people often tend to live, work, and socialize within a geographic area (e.g., city) and thus have a tendency to be friends with others in the same geographic area. Accordingly, the friends in a common geographic area may form a community, as described in more detail herein. As another example, any one or a number of demographic considerations (e.g., age, ethnicity, gender, religion, etc.) may be attributes that often correlate strongly with connections between nodes. In this regard, persons having similar demographic profiles are often friends. Accordingly, demographic considerations may be used to classify persons in the determination of communities. The classification of users in the determination of communities may be based on attributes other than those expressly described herein as examples.

The example regarding a social graph is used to provide exemplary context and to illustrate operative principles of various embodiments. Discussion of this example of a social graph should not be viewed as limiting. The underlying principles and concepts of this example regarding the social graph may be applicable to other types of graphs, nodes, connections, attributes, etc. in other embodiments.

The classification determination module202may represent the classifications (e.g., cities) as nodes of a new graph, and define edge weights (or values) between classifications. In certain embodiments, the edge weights may be based on a number of connections between classifications, the strength or type of connection between classifications, or a combination of these or other factors. In an embodiment, edge weights may be determined based on the total number of connections between classifications. For example, the edge weight may be proportional to the number of connections between any two classifications, such that that the more connections between two classifications, the larger the edge weight that represents their connections. For instance, the edge weight may be represented by the number of connections between the two classifications—e.g., 100 connections resulting in an edge weight of 100, 200 connections resulting in an edge weight of 200, etc. Other techniques to assign values to edge weights between classifications may be used in other embodiments.

In an embodiment, the edge weights may be determined based on strengths or quality of the connections (or affinity) between classifications. For example, individual connections between two classifications may have varying coefficients that are assigned based on strengths of the connections. For example, connections with trait “A” (e.g., two users are married) may be viewed as stronger (or more important) connections than connections with trait “B” (e.g., two users are colleagues). Accordingly, connections with trait “A” may be assigned a larger coefficient than connections with trait “B”. For example, in the example of a social graph, a user in San Jose may have a certain number of friendships with ordinary acquaintances in San Francisco, but have an equal number of friendships with family members, close friends, or friends with whom the user is in frequent communication, in Los Angeles. The friendships in Los Angeles with family members, close friends, or friends with whom the user is in frequent communication may be assigned larger coefficient values than the friendships in San Francisco to reflect the stronger friendships in Los Angeles.

In general, the social graph data may include information about coefficients as measures of relatedness between nodes in the social graph. Coefficients may reflect weights for connections (or paths) between nodes in the social graph. For example, coefficients may indicate that a user is closer to her best friend than to another person befriended by the user based on the respective weights of the paths that connect them. Coefficients may be based on a variety of possible interactions between nodes, whether internal or external to the social networking system. Nodes may include users, people, pages, or any object in the social graph. The determination of coefficients may be directional, and depend on many factors, such as the relationship, interaction, or closeness between nodes in the social graph. As an example, the measure of relatedness of one user (e.g., User A) to another user (e.g., User B) may be based on various considerations including but not limited to whether: User A is friends with User B; User A commented on a photo of User B; User A liked content or a status update of User B; User A posted on the wall of User B; User A was on the same thread as User B; User A appears in the same photo as User B; a certain amount of time (e.g., days) transpires with (or without) User A engaging with User B or content of User B; User A linked to a comment of User B; User A shared content of User B with others; User A mentioned User B in a wall comment; User A viewed profile or other web page of User B; etc.

In the foregoing example concerning the determination of User A's coefficient for User B, many of the possible interactions informing the coefficient are based on actions of User A. However, other interactions involving actions of User B may also be considered in the determination of User A's coefficient for User B. Such interactions may include any variety of activities, such as whether: User B viewed a photo of User A; User B viewed an album of User A; a certain amount of time (e.g., days) transpires with (or without) User B engaging with User A or content of User A, etc. Further, the interactions that inform the determination of coefficients may be based on the time duration over which the interactions occurred (e.g., the last 30 days, 60 days, 90 days, or any other suitable time interval). Coefficients may also be based on a frequency of interaction within those historical time durations as well as other factors.

Coefficients may also be asymmetric in some instances. For example, for certain reasons (e.g., privacy), coefficient scores may be based solely on the acting user's actions. In an embodiment, a two-way coefficient score may be computed such that cache sharding better reflects usage patterns.

The community generation module204may group the classifications within communities at a first level based on the edge weights between classifications. In an embodiment, a community detection algorithm may be performed with the classifications as inputs, resulting in classifications (e.g., cities) being mapped to corresponding communities. For example, in an embodiment, classifications having edge weights with relatively large values between them may be grouped together in a community so as to maximize the number of connections or the strength of connections within a community and to minimize the number of connections or the strength of connections between communities.

Communities resulting from grouping classifications at the first level may be referred to as first level communities. Iterative groupings may be performed to generate communities at higher levels. For example, a community detection algorithm may be performed with first level communities as inputs to group first level communities to a higher level of second level communities. Similarly, a community detection algorithm may be performed with the second level communities as inputs to group second level communities to a higher level of third level communities, and so on. This technique results in classifications being grouped to first level communities, the first level communities being grouped to second level communities, the second level communities being grouped to third level communities, and the third level communities being grouped to yet still other higher level of communities. A community in each successive level of communities may be determined by maximizing the number of connections or the strength of connections within the community and by minimizing the number of connections or the strength of connections with other communities.

The iterative groupings to generate successive levels of communities are not limited in number. In an embodiment, the technique may involve mapping to n community levels, where n may be any integer value selected for optimal grouping of the classifications and communities. For example, the value of n may be two, three, or other suitable number. As another example, the value of n may be a value other than two or three.

In the example of a social graph, cities may be grouped into communities based on the edge weights between the cities (e.g., number of friendships between cities, the strength of the friendships between cities, both, etc.). The resulting first level communities may be further grouped into second level communities in a similar manner. The resulting second level communities may be further grouped into third level communities in a similar manner, and so on. Any number of iterative groupings of into higher level communities may be performed. In certain embodiments, preexisting IDs (e.g., user IDs) associated with the original nodes may be mapped to classifications and the various levels of communities.

Classifying nodes by attribute and then using the classifications as a working set by which to group the nodes into communities may provide significant advantages. In the example of a social graph, a working set based on nodes associated with over one billion users can be reduced to a working set based on classifications of 750,000 cities associated with the users. Such reduction in the working set may significantly reduce computation times for determining the unique IDs from, for example, many hours to a few minutes. Furthermore, the reduced working set may significantly decrease the number of iterative groupings needed for various applications. In some instances, the number of iterative groupings based on the reduced working set to achieve optimal clustering of nodes may be five iterations or less.

In the example of a social graph, the social graph may include approximately one billion nodes, which may be classified with respect to approximately 750,000 cities. When the cities are grouped based on the edge weights (e.g., number of connections) between the cities, the number of resulting first level communities may be approximately 2,000. If the first level communities are further grouped based on the edge weights between them, the number of resulting second level communities may be approximately 60. Subsequent attempts to group communities at even higher levels may not provide significant reductions in the number of communities.

While resulting communities at various levels may have some degree of correspondence with geographic area, they may be based on friendships, which may have a strong correlation to geography. The correspondence between communities and geographic area need not be a strict correspondence. For example, some geographic areas that are close to one another may not have many or strong friendships between them, and some geographic areas that are distant from one another may have many or strong friendships. The correlation between geographic area and friendships may be based on a wide range of considerations, such as cultural factors, demographic trends, common interests or ties, etc.

The ID assignment module206may assign unique IDs to a sorted list of nodes in a numerically sequential manner. The nodes may be sorted in a manner such that friends tend to be clustered together, and tend to have the same classifications and fall within the same communities. The ID assignment module206may sort the nodes by classifications and resulting communities. In an embodiment, the nodes may be sorted by classification, and then by first level community, and then again by second level community, and so on.

The unique IDs may be a numerical sequence (e.g., from one to 1 billion) that is assigned to the sorted list of nodes. In general, clustered nodes or communities at various levels will have unique IDs that are numerically proximate to one another. For example, nodes with the same classification will have unique IDs that are numerically proximate to each other. As another example, nodes within the same first level community will have unique IDs that are numerically proximate to each other. Nodes within the same second level community will have unique IDs that are numerically proximate to each other. Nodes within the same third level community will have unique IDs that are numerically proximate to each other. It should be appreciated that the term “numerically proximate” is used broadly herein and is not limited to unique IDs having a strict sequence of successive numbers including every integer or value from the beginning to the end of a sequence. For example, numerically proximate unique IDs may be numerically sequential odd numbers—e.g., 1, 3, 5, 7, 9, and so on. As another example, numerically proximate numbers may be a series of non-successive odd and even numbers—e.g., 1, 2, 4, 5, 7, 8, and so on. As yet another example, numerically proximate numbers may indicate that the difference between values in a set of unique IDs for the nodes, as determined by the techniques described herein, is relatively smaller than the difference between values in a set of another type of preexisting IDs for the nodes.

The unique ID space may thus be structured such that friends, classifications, and communities have unique IDs that are proximate to one another. The unique IDs may be divided for mapping across a networked computer system. When the unique ID space is divided, the divisions of the unique ID space will include clusters of friends, as well as clusters of cities and communities at various levels. In some embodiments, a city or other community at a particular level may be split between partitions. In general, partitioning may improve locality and optimize system performance while reducing disadvantages associated with fan out, as discussed in more detail herein.

The identification module102may update definitions of the new graph. The definition of a new graph based on classifications instead of the original nodes by the identification module102may require fewer updates. In the example of a social graph, the number of friendships or strength of friendships between cities may be fairly static and may not change significantly over short periods of time. In contrast, changes to users may occur more frequently since people may, within a city, move, make new friends, etc. Thus, because the new graph is based on classifications instead of the original nodes, the identification module102may be required to perform relatively fewer updates to account for changes in the underlying data associated with users. In various embodiments, the identification module102may update the new graph at various intervals (e.g., every week, month, 3 months, 6 months, or other applicable time period) or upon the occurrence of certain events (e.g., a threshold change in the edge weights between cities or communities).

FIGS. 3A-3Dillustrate an example mapping table, according to an embodiment. The example mapping table is described with respect to a social graph. However, underlying concepts discussed in connection with the table are not limited to any single social graph or its particular features.

InFIG. 3A, the table300includes a column USER that lists 12 users (e.g., nodes). For the sake of clarity and brevity, only 12 users are shown for exemplary purposes. It should be appreciated that the mapping table generated may include millions, billions, or any number of users. In an embodiment, the column USER may represent a preexisting ID (e.g., user ID) previously assigned for each user, which may then be accordingly mapped to the classifications (e.g., cities) in column L1and communities in columns C1and C2.

Column L1represents the associated cities of the users. The cities may represent the residences of the users. For example, each of the users1-12is shown next to its associated cities—e.g., either New York (NY), San Francisco (SF), San Diego (SD), Los Angeles (LA), or New Jersey (NJ).

Column C1represents 1st(first) level communities that result from grouping the cities based on edge weights defined between the cities (e.g., based on the number of friendships between cities, strengths of the friendships between cities, etc.). In an embodiment, the 1stlevel communities are selected such that cities having a large number (or strength) of friendships between them are grouped together so as to maximize the number (or strength) of friendships within 1stlevel communities and to minimize the number (or strength) of friendships between 1stlevel communities. As shown, NY is listed as within 1stlevel community “1”; SF is listed as within 1stlevel community “2”; SD and LA are listed as within 1stlevel community “3”; and NJ is listed as within 1stlevel community “4”. In the embodiment shown, LA and SD may have a relatively large number of friendships between them, resulting in LA and SD being grouped within the same 1stlevel community.

Column C2represents 2ndlevel communities that result from grouping the 1stlevel communities based on edge weights defined between the 1stlevel communities (e.g., based on the number of friendships between 1stlevel communities, strengths of the friendships between 1stlevel communities, etc.). In an embodiment, the 2ndlevel communities are selected such that 1stlevel communities having a large number (or strength) of friendships between them are grouped together so as to maximize the number (or strength) of friendships within 2ndlevel communities and to minimize the number (or strength) of friendships between 2ndlevel communities. In the embodiment shown, NY and NJ fall within the same 2ndlevel community “1”; and SF, SD, and LA fall within the same 2ndlevel community “2”.

The cities and resulting levels of communities may then be sorted, resulting in a sorted list of users (or user IDs) based on cities and resulting levels of communities. For example, the users within the mapping table300may be sorted by cities (column L1), 1stlevel communities (column C1), and 2ndlevel communities (column C2). Since communities were grouped based on edge weights associated with friendships, friends are, or have a tendency to be, clustered together.

FIG. 3Bshows the mapping table300after the users have been sorted by cities (column L1). As shown, users for LA are listed first at the top of the chart, followed by cities NJ, NY, SD, and then SF.

FIG. 3Cshows the mapping table300after the users have been sorted by 1stlevel community (column C1). As shown, users in 1stlevel community “1” are listed first at the top of the chart200, followed by users in 1stlevel communities “2”, “3”, and then “4”.

FIG. 3Dshows the mapping table300after the users have been sorted based on 2ndlevel communities (column C2). As shown, users in 2ndlevel community “1” are listed first at the top of the chart200, followed by users in 2ndlevel community “2”.

As a result of the sorting procedure, the users1-12are sorted by city, 1stlevel communities, and 2ndlevel communities. For example, all users within the 2ndlevel community “2” are numerically proximate to each other (e.g., users2,6,8,11,4,7,1,3, and12). Furthermore, within the 2ndlevel community “2”, all users within the 1stlevel community “2” are numerically proximate to each other (e.g., users2,6,8, and11), and all users within the 1stlevel community “3” are proximate to each other (e.g., users4,7,1,3, and12). Still further, within 1stlevel community “2”, all users within the city “SF” are proximate to each other (e.g., users2,6,8, and11). Within 1stlevel community “3”, all users within the city “LA” are proximate to each other (e.g., users4and7), all users within the city “NY” are proximate to each other (e.g., user1), and all users within the city “SD” are proximate to each other (e.g., users3and12). This same pattern also applies to all users within 2ndlevel community “1”.

In this way, when the identification module102assigns unique IDs in a numerically sequential manner to the sorted list of users, users within the same city and resulting levels of communities will have unique IDs that are numerically proximate one another. For example, the table300inFIG. 3Dincludes a column UQ_ID that lists a unique ID that has been assigned in a numerically sequential manner to users that have been sorted by classifications, 1stlevel communities, and 2ndlevel communities. As shown, users having the same classification or falling within the same community are proximate to one another, and accordingly have unique IDs that are numerically proximate to one another. Uniquely identifying nodes in this manner may prove beneficial or advantageous from the perspective of improving system performance and optimizing computing resources, as described herein. It should be appreciated that while communities may have a geographical component in some instances, in other instances communities may not have a geographical component. InFIG. 3A-3D, for example, user1and user5are both associated with NY but are within different 1stlevel communities. User1may, for instance, have a large number of friends in 1stlevel community “3” and is then grouped within 1stlevel community “3”. On the other hand, user5may have a large number of friends in 1stlevel community “1” and is then grouped within 1stlevel community “1”.

In some embodiments, sorting techniques may differ. For example, instead of sorting on classifications and every level of communities, the users may be selectively sorted based on any combination of the classification or levels of communities. For example, the users may be sorted based on only the highest level community (e.g., the 2ndlevel community). Then, unique IDs may be assigned based on such sorting. As another example, only the two highest level communities (e.g., the 1stlevel community and the 2ndlevel community) may be sorted before unique IDs are assigned.

FIG. 4illustrates an example tree diagram400of nodes401assigned to classifications402, 1stlevel communities403, and 2ndlevel communities404, according to an embodiment. The tree diagram400may include any suitable number, x1, of nodes. In the example shown, one billion nodes401are grouped by the classifications402, as represented by the lines from each node401to a corresponding classification402. Any suitable number, x2, of classifications associated with the nodes may be determined. In the example shown, 750,000 classifications402representing geographic locations (e.g., cities) are associated with the nodes401. Each of the classifications402is grouped within 1stlevel communities403, as represented by the lines from each classification to a corresponding 1stlevel community. Any suitable number, x3, of 1stlevel communities403may be determined. In the example shown, 2,000 1stlevel communities403are associated with the classifications402. Furthermore, each of the 1stlevel communities403are grouped within 2ndlevel communities404, as represented by the lines from each 1stlevel community to a corresponding 2nd level community. Any suitable number, x4, of 2ndlevel communities may be determined. In the example shown, 60 2ndlevel communities404are associated with the 1stlevel communities403. The tree diagram400is structured such that nodes401having the same classification and falling within the same communities are clustered together, and are thus structured in a sorted manner based on the classifications402, the 1stlevel communities403, and the 2ndlevel communities404. In this way, unique IDs may be assigned to nodes401in a numerically sequential manner from beginning to end (e.g., from left to right). Nodes having the same classification or falling within the same community will have unique IDs that are numerically proximate to one another. It should be appreciated that the values shown for x1, x2, x3, and x4inFIG. 4are exemplary. Any suitable number may be implemented in different embodiments.

FIG. 5illustrates an example process of assigning unique IDs to nodes of a node graph, according to an embodiment. It should be appreciated that the discussion above forFIGS. 1-4may also apply to the process forFIG. 5. For the sake of brevity and clarity, every feature and function applicable toFIG. 5is not repeated here.

At block502, nodes in a node graph may be identified. In an embodiment, for example, the nodes may be associated with users within a social graph. At block504, one or more attributes for the nodes may be identified. The attributes may relate to the nodes, or connection between nodes. At block506, classifications for each node may be generated based on the attribute. In one embodiment, the attribute may be a geographic association (e.g., association with a city), and the nodes may be classified by the geographic location they are associated with (e.g., city of residence, city of business or operation, etc.). The classifications may be viewed as nodes of a new graph, having edge weights defined between classifications. In an embodiment, the edge weights may be based on the number of connections between nodes. In an embodiment, the edge weights may be based on strengths of the connections, which may be represented by coefficients. In an embodiment, blocks502,504, and506may be performed by the classification determination module202ofFIG. 2.

At block508, the classifications (e.g., associated cities) may be grouped into communities based on the edge weights defined between the classifications (e.g., based on the number or strength of connections between classifications). The grouping may provide a map from classifications to 1stlevel communities. At block510, it is determined if an additional grouping into another level of communities is to be performed. If an additional grouping is to be performed, the 1stlevel communities that resulted from block508are grouped based on the edge weights between the 1stlevel communities (e.g., based on the number of connections between 1stlevel communities or the strength of the connections between 1stlevel communities), as represented by the arrow from block510to block508. This process may be repeated in a similar manner for any additional groupings into higher level communities. If no additional groupings into higher level communities are to be performed, then, at block512, the nodes (from block502) are sorted based on a sorting of the classifications and resulting levels of communities. The nodes are sorted in a manner such that friends tend to be clustered together in the sorted list, and further tend to have the same classifications and fall within the same communities.

At block514, unique IDs are assigned to the sorted list of nodes in a numerically sequential manner. In this way, nodes (e.g., users) having connections (e.g., friendships) will tend to be clustered together with the same classification and within the same communities, and accordingly have unique IDs that are numerically proximate to one another. In an embodiment, blocks508and510may be performed by the community generation module204ofFIG. 2. Furthermore, in an embodiment, blocks512and514may be performed by the ID assignment module206ofFIG. 2.

The classification and higher levels of communities may not necessarily provide finer grain information within classifications. For example, a sorted list of users may not necessarily be sorted such that sub-communities of friends within a city are sequentially proximate to one another in the unique ID space. A sub-community of a city may, for instance, be associated with a suburb having a high number of connections between users.

In an embodiment, sub-communities of nodes may be identified within a classification. For example, a classification for a sub-community may be derived in a similar manner as discussed herein. Nodes may then be grouped into sub-communities within the classification based on, for example, the number or strength of connections between nodes. Additional levels of sub-communities may also be iteratively computed. A sorted list of nodes may then be generated by sorting the nodes by classifications and sub-communities (and higher level communities). The unique IDs may then be assigned in a numerically sequential manner to the sorted list of nodes. In this way, sub-communities of nodes having connections will tend to be clustered together.

Uniquely identifying nodes based on the techniques performed by identification module102may provide advantages in various situations. For example, generating and assigning unique IDs by identification module102may improve the manner in which information may be compressed for storage. Networked computer systems may include main memory that may be slow to access but have large storage capacities. For this reason, compression may not be an important consideration with respect to main memory management. However, memory hierarchies of networked computer systems also often implement faster memory that may be accessed more often to enhance performance speed. Because the faster memory technologies tend to be more expensive, the size of the memory is often limited and thus compression techniques play a more important role to maximize the amount of data that can be stored therein. Delta encoding is one compression technique that may benefit from the unique ID space generated and assigned by the identification module102.

For example, a user's friend list may include preexisting user IDs: 200; 3,000; and 30,000. Generally, to delta encode the friend list, the friends' user IDs are sorted from smallest to largest value. A preceding user ID value may be subtracted from each user ID, except the smallest user ID, which does not have a preceding user ID. The delta encoded list may include the following: 200; 2800; and 27,000. The value 2800 was derived by subtracting 200 from 3000, and the value 27,000 was derived by subtracting 3,000 from 30,000. By delta encoding, the idea is to generate smaller numbers which require less bits to store. However, as shown, when dealing with a large set of potential user ID values, the differences between user ID values may be relatively large values.

Because the unique IDs are assigned in a numerically sequential manner to a sorted list of nodes (e.g., users) that cluster the nodes based on connections, many nodes (e.g., users) that have connections (e.g., friendships) will be clustered together within the sorted list, and ultimately assigned unique IDs that are sequentially proximate to one another. Therefore, the same friends with user IDs 200; 3,000; and 30,000 may have unique IDs assigned by identification module102that sequentially proximate to one another, such as: 1,001; 1,003; and 1010. Applying delta encoding to these unique IDs results in the delta encoding values: 1,001; 2; and 7. These delta encoded values provide significantly smaller values, which require significantly less data to store in memory.

Generating and assigning unique IDs to nodes based on the techniques performed by the identification module102may prove beneficial when partitioning a massive graph at scale across networked computer systems, including disks, machines, database servers, and data centers.

FIG. 6illustrates an example networked computer system600, according to an embodiment. The networked computer system600includes n database servers602, n cache systems604associated with the database servers602, web server606, and cache system608associated with web server606, where n is any number of database servers and associated cache systems to support the computer networked system600, such as a social networking system. The database servers602include database server612, database server614, database server616, and database server618. The cache systems604include cache system622, cache system624, cache system626, and cache system628. The database server612is associated with the cache system622; the database server614is associated with the cache system624; the database server616is associated with the cache system626; and the database server618is associated with the cache system628. The database servers602, the cache systems604, and the web server606may be communicatively coupled to one another through one or more networks, such as a LAN, WAN, and the internet. Each of the database servers602may represent a single database server or a data center. Information for the graph, such as a social graph, may be stored within a persistent memory layer formed by the database servers602.

In the example of a social graph, the database servers602may include user information for all of the users in the social graph. The user information may include, for example, information related to a user profile, images, videos, posts, status updates, friends lists, feeds, or any other information associated with the user and the activities of the user on a social networking system supported by the social graph. User information for a specific user may be stored on a specific database server of the database servers602. Users may be mapped to one of the database servers602irrespective of any of the user's friendships. For instance, new users of a social networking system may be allocated to one of the database servers602based on which of the database servers602has capacity to maintain data about the user at the time the user joined the social networking system.

In certain embodiments, a user ID associated with a user may be used to indicate which of the database servers602a user's information is to be stored on. If user information is desired for a given user, then the specific database server with the user's information may be queried to obtain the user's information. For example, when user A accesses the web server606of the networked computer system600, the web server606may identify the user ID for user A, and may use the user ID to determine that the user information for user A is stored on the database server614. The user information for user A may include, for example, a friend list of user A's friends or other information about user A.

User information for each of user A's friends may then be obtained by querying each database server having user information for a respective friend, as represented by queries632,636, and638to the respective database servers612,616, and618. The queries632,636, and638to each of the respective database servers612,616, and618represent fanout queries. While the example shows three additional queries632,636, and638to respective database servers612,616, and618, user A may have a significantly larger number of friends (e.g., hundreds or thousands of friends) spread out over many of the database servers602, which could potentially require a fanout query to a different database server for each friend. In this circumstance, the large number of fanout queries would be undesirable. Fanout queries may significantly decrease performance (e.g., speed with which information is obtained) and generate excessive amounts of network traffic, especially when dealing with extremely large number of nodes and queries. The problems associated with fanout queries are further compounded when queries for user information for “friends of friends” of (or for indirect friends having still larger degrees of separation from) user A are performed. Fanout queries may also contribute to excessive use of memory in the cache systems604.

The networked computer system600also includes the cache systems604implemented in association with the database servers602to provide faster memory access than the persistent memory layer of database servers602. For example, the cache systems604may implement cache layer services within RAM or other form of fast memory technology, such as Flash memory. For instance, data or computations may be cached using Alternative PHP Cache (APC), Memcache, etc. Similarly, web server606may also cache data or computations within cache system608. When a query for user information for user A is first sent to a given database server614, for example, the user information may be retrieved from the database server614and also stored in the cache system624. Thereafter, as long as the user information for user A remains in the cache system624, subsequent queries for user information for user A may be more quickly retrieved from the cache system624. However, if user information for user A's friends are stored on different database servers602, then the cache systems604may not necessarily provide significant reductions to the number of fanout queries.

Since friends tend to be part of one or more groups of friends, there is strong tendency for friends to have many friends in common. When collecting user information for friends, and friends of friends, many queries for user information of common friends may occur. If these friends are randomly scattered over different database servers and cache systems, then the fanout queries will be performed.

In certain embodiments, the cache systems604may be configured to cluster friends within the same cache system, thus increasing cache locality. Increasing the number of friends who are local to a common cache system may increase the likelihood that requested user information for common friends will already be cached by a previous query for the user information. Increasing the cache hit rate in this manner reduces fanout queries even if the user information for common friends is stored in different database servers602. Therefore, increasing cache locality and cache hit rate may produce significant benefits in performance, reduction in network traffic, etc., especially when dealing with extremely large numbers of nodes and queries.

FIG. 7illustrates a mapping module, according to an embodiment. The mapping module104is shown including partitioning module702, routing module704, load monitoring module706, and temporal balancing module708. The partitioning module702may determine the number of partitions into which the graph is to be partitioned. The number of partitions may relate to the number of physical machines (e.g., database servers602or cache systems604) across which the graph data is to be distributed. The unique ID space may then be divided (or segmented) based on the number of nodes for each partition.

For example, if a social graph of 1 billion users, represented by nodes, is to be partitioned over 100 cache systems, then the number of users (e.g., 1 billion) may be divided by the number of partitions (e.g., 100) to provide a partition size—i.e., the number of users per partition (e.g., 10 million users per partition). Accordingly, the unique ID space may be divided by the partition size, resulting in 10 million unique IDs per partition. Since the unique ID space is numerically sequential, the 10 million unique IDs in each partition are numerically proximate to one another. Therefore, the clustering of cities and communities within the unique ID space are reflected in the partitioning of the social graph over a multitude of machines. Furthermore, the tendency of friends to be clustered in the unique ID space is reflected in the partitioning of the graph to the machines. In this example, the partition sizes are equal (e.g., 10 million users per partition), resulting in the same number of unique IDs on each of the machines. In another embodiment, the partition sizes may not be equal, resulting in varying numbers of unique IDs on the machines.

The routing module704may map users to machines based on the divisions of the unique ID space and the partitions—e.g., as described for the partitioning module702. The routing module704may then route users to machines according to the mapping. For example, in some instances, the number of partitions (e.g., machines) for an application will be known, and the unique ID space may be divided, as described, to map users to the cache layer of a machine. The unique ID space may be evenly or unevenly divided in different embodiments. For example, the divisions of the unique ID space may result in splitting a city or community between two machines. Furthermore, some levels of communities may be large, and thus not all communities may fit on a single machine. In an embodiment, the partition sizes (e.g., number of users per partition) may be adjusted accordingly to maintain integrity in the localities of cities or communities.

The unique ID space may be used to map users to cache systems. The unique IDs may enable clusters of friends to be routed to the same cache system, which may significantly improve locality and thus provide benefits in the processing (or executing) of queries provided to the networked computer system. The queries may be of any type, such as “friends of friends” queries submitted to a social networking system. Queries may be directed to appropriate cache systems that are needed to execute the queries. For example, a query for User A's friends would be sent to the machine that User A is mapped to based on the unique ID of User A.

In certain instances, preexisting IDs (e.g., user IDs) may already be allocated to nodes and used to map users to database servers, but in a manner that does not account for edge weights or desired clustering of closely connected nodes. In such case, unique IDs may constitute an alternative identifier. The user IDs may be mapped to the unique IDs, and the unique IDs may be used to map the users to cache systems. In this way, user data in the persistent memory layer (e.g., database servers) may be maintained, while the benefits of the unique ID space are realized in a cache layer (e.g., cache systems). In one embodiment, the mapping of user IDs to unique IDs may be stored on a machine that is accessed whenever user IDs are to be converted to unique IDs for cache layer operations.

Another benefit of the unique IDs described herein is that the number of partitions is not required to be known in order to generate the unique IDs. For example, if multiple services require different numbers of partitions, then the same unique ID space may be divided accordingly based on the corresponding number of partitions. For instance, in the example of a social graph, the networked computer system may include a persistent memory layer (or tier) of database servers and a cache layer (or tier) of cache systems. One cache layer service may be an index service implemented over 100 cache systems (e.g., 100 partitions). Another cache layer service may be a newsfeed service implemented over 200 cache systems (e.g., 200 partitions). Yet another cache layer service may be a graph service that is implemented over 300 cache systems (e.g., 300 partitions). In this way, the persistent memory layer may be kept fairly static, but the cache layer may be dynamically configured.

Routing users based on the unique IDs may significantly improve fanout issues. If users on a machine tend to access similar data, then the data will be cached after an initial query for the data and available for subsequent queries that need the same data. Take for instance a “friends of friends” query. Friends or communities may be clustered onto the same cache system. Therefore, when User A submits a query about her friends, the data for all User A's friends is fetched and stored in cache, if not already in cache. If User B is friends with User A, then it is likely that User A and User B have some number of friends in common, especially if User A and User B are living in the same city. Thus, when User B submits a query about his friends, any data for common friends of User A and User B will be already cached from the time when User A submitted her query. The greater number of friends in common, the greater the efficiency that results. Furthermore, when applied over a large number of users (e.g., 500 million users, a billion users, etc.), tremendous gains in performance and network traffic may be realized.

Furthermore, by routing a user to the same machine over different queries, the user may take advantage of data that she has already cached. For example, when a user refreshes data, such as a newsfeed or posts on a social networking system, having the query sent to the same machine in which the previous data is cached may provide a significant improvement in the speed with which the data is obtained.

While the particular examples described herein may relate to users and their friendships, the underlying concepts and principles are applicable to other nodes and connections. As discussed herein, nodes may be of any type. Furthermore, connections may include various types of relationships. For instance, a connection may be a “follow” edge, where a user follows another entity or user. The same approach of routing nodes to machines based on unique IDs may be expanded to other entities and not just persons, for example, to determine that soccer is popular in Egypt, cricket is popular in Bangladesh, and a particular business is popular in the US. For instance, one query may be “Show me all the people who like Business A and live in San Francisco”. The query could be executed more efficiently if a web page of Business A associated with a social networking system was on the same machine as many of its fans. In particular, query execution may be enhanced by maintaining the web page of Business A and its fans in the cache layer of a machine.

While mapping users to machines based on divisions of the unique ID space improves locality on machines, the loads on each machine may vary, and, in some instances, significantly. In an embodiment, the routing module704may route users to machines based on load considerations. The load monitoring module706may monitor the loads of the machines while the machines are online, and work in conjunction with routing module704to route users to machines based on load considerations. In an embodiment, the loads may be monitored to determine if they exceed a threshold or drop below a threshold. In some instances, the amount of load (e.g., percentage of a maximum capacity) on a machine at any given time is monitored.

In an embodiment, an initial mapping is based on the divisions of the unique ID space, whether evenly distributed or not, and thereafter the routing module704may route users dynamically based on load balancing considerations. For example, a query by a user may be received along with the preexisting user ID for the user. A mapping of preexisting user IDs to the unique ID space may be used to convert the preexisting user ID to a unique ID. A shard number may then be determined based on a partition size, both of which may be determined by the example equations below:
Partition size=(number of users)/(number of partitions)
Shard number=(unique ID)/(partition size)

For example, for 2.25 billion users and 15 thousand partitions, the partition size would be 150 thousand users per partition. Dividing any single unique ID by 150 thousand may then be used to determine a corresponding shard number. The routing module704may then map the shard number to the appropriate machine after taking into account load balancing considerations identified by the load monitoring module706. After the shard number is mapped to a machine, the query may be executed on the machine.

In an embodiment, load may be determined in part by tracking the number of queries a machine has received. For example, as an application is executing queries, it may export a counter indicating the number of queries each shard is processing (e.g., application shard number100has 100 queries, application shard number101has 500 queries, etc.). The load monitoring module706may then receive the exported counter data and work in conjunction with the routing module704to, for example, determine whether or how to move users between shards of machines. For example, the load monitoring module706may monitor whether the number of queries that a machine is processing exceeds a threshold. If the threshold is exceeded, then the load monitoring module706may prevent additional queries from being routed to the machine until the number of queries being processed drops below the threshold. These additional queries may be routed to another machine until the number of queries the machine is processing drops below the threshold. Likewise, the load monitoring module706may monitor whether a number of queries that a machine is processing drops below a threshold. If the number of queries drops below the threshold, then the load monitoring module706may determine that this machine is available to receive additional queries, such as the queries prevented from being routed to machines exceeding a threshold of queries.

In one embodiment, the load monitoring module706determines if a machine is overloaded, and routes users accordingly. For example, a user may be initially mapped to a machine that is currently overloaded. The overloaded status is detected by the load monitoring module706and communicated to routing module704, which routes the user to a different and less loaded machine. The overloaded machine is thus prevented from being further loaded, and the load of the underloaded machine is increased. In one embodiment, the load monitoring module706may determine a user needs more than one machine for a query, and the routing module704accordingly may route the query to other machines. The movement of users from one shard to another shard based on load balancing considerations, such as query processing demands, may compromise locality to some degree. The load monitoring module706may continuously weigh the tradeoff between locality and query speed.

In an embodiment, a geographic location may exhibit limited usage patterns. For example, for some applications, specific users associated with certain geographic locations may not be routed to one or more machines because of, for example, legal reasons, privacy reasons, etc., creating unused computing resources. For example, a country may not use or permit a particular application to be available to its residents or citizens. For instance, the European Union and Canada may not allow a specific application for its citizens, and thus users within those borders do not have access to that application. The unused shard in the cache system allotted for the application will be unused by those users. Therefore, other users associated with other geographic locations may be routed to the machine to utilize available computing resources, such as the unused shard of the cache system.

In one embodiment, the sections of the unique ID space corresponding to geographic locations associated with prohibited applications are removed from the unique ID space. A modified unique ID space (without the unique IDs corresponding to the blacked out geographic locations) may then be divided (e.g., evenly or unevenly) based on the number of partitions to map users to a shard number and corresponding machine.

In certain embodiments, users may be mapped to machines according to usage patterns that are strongly correlated with geographic locations. Different geographic locations may exhibit different usage patterns. While the unique ID space may help to optimize locality, geographic locations may have varying usage patterns, which may lead to varying loads on machines during different times. These load swings may vary significantly by providing large loading on machines at some times and providing small loading on the same machines at other times.

The temporal balancing module708may work in conjunction with the routing module704to route users to machines in a manner that accounts for usage characteristics, such as temporal fluctuations in usage patterns. For example, loads for geographic locations may vary by time of day (e.g., work hours versus non-work hours). As another example, loads also may vary by the day (e.g., holiday versus normal day) or by other larger intervals of time (e.g., summer vacation versus basketball championship). The temporal balancing module708may use data from the load monitoring module706to determine usage patterns and, based on the usage patterns, work with the routing module704to route users to various machines to optimize load balancing.

For instance, the temporal balancing module708may identify geographic locations that have complementary usage patterns. Complementary usage patterns may refer usage exhibited by geographic locations that is not in phase. For example, one type of complementary usage pattern may involve a first geographic location having a peak in traffic usage when, at a same or overlapping time, a second geographic location has a valley in traffic usage. Likewise, another type of complementary usage pattern may involve the first geographic location having a valley in traffic usage when, at a same or overlapping time, the second geographic location has a peak in traffic usage. Instead of routing the two geographic locations on two separate machines with significant swings of high traffic and low traffic, the temporal balancing module708may pair them together on the same machine (or cluster of machines). In this way, the machine, in effect, primarily services only one geographic location during its corresponding high traffic time, thus optimizing use of computing resources and balancing the load on the machine. In an embodiment, high traffic may be determined based on whether the traffic exceeds a predetermined threshold. Similarly, in an embodiment, low traffic may be determined based on whether traffic drops below a threshold.

Within a social networking system, a geographic location (e.g., city, country, community, etc.) or associated shard may exhibit large swings in the amount of usage of the social networking system during peak times and non-peak times. This pattern may be generally exhibited, for example, by different users in a common geographic region or time zone. For example, many cities, regions, and even countries may exhibit less traffic during the night, when people tend to be sleeping, than during the day. Thus, traffic may be categorized in 12 hour periods of time or other time intervals. As another example, a first geographic location may exhibit distinct usage (e.g., heavy traffic or minimal traffic) during an eight hour interval during the day, a second geographic location may exhibit distinct usage during a six hour interval during the day, a third geographic location may exhibit little or no distinct usage pattern.

Usage patterns may be based on habits or cultures that are associated with certain geographic regions. For instance, people in one geographic location may predominantly use the social networking system at home. Another geographic location may predominantly use the social networking system at work. Yet another geographic location may predominantly use the social networking system on weekends or other special days.

Furthermore, users of a social networking system may be unevenly distributed in different geographic locations. For instance, the United States and Europe may have very large number of users that exhibit significant usage patterns over the same or overlapping time periods. The peak periods of time for these two countries may overlap, generating tremendous combined usage during the overlapping time period. Accordingly, the combination of users from these geographic locations would cause excessive swings in load on a machine. Accordingly, in an embodiment, during the time that each geographic location exhibits peak usage, the users associated with one geographic location may be routed by the temporal balancing module708to a different machine during that time to avoid excessive swings in load. The users may be returned to the original machine after the peak usage interval. Routing users to avoid such excessive swings in load in this manner may be performed for any number of geographic locations over any intervals to optimize load balancing. The temporal balancing module708may identify intervals of times associated with heavy or light usage and accordingly group or band together specific geographic locations onto the same machine to optimize load. The temporal balancing module708may implement any number of permutations which may mix and match varying number of geographic locations and variously sized time intervals to optimize the load balance for different usage patterns.

The temporal balancing module708may band geographic locations by time zones that are complementary. For example, two geographic locations may complement one another in 12 hour periods, three geographic locations may complement each other in 8 hour periods, etc. This banding of geographic locations may be performed in various combinations for geographic locations around the world. In some instances, the temporal balancing module708may treat different geographic locations as a unit for purposes of load balancing.

The temporal balancing module708may also take into account the tradeoff between load balancing and locality. For instance, while two geographic locations may complement one another with respect to usage patterns, they may not necessarily be routed to the same machine if the impact to locality is determined to be too great.

Various systems and techniques may be implemented to account for variations in load. In an embodiment, general purpose pools of machines may be implemented to accommodate excessive load demands or a decline in load processing capability, such as due to maintenance. For example, if a machine is currently overloaded or inoperative due to maintenance, then queries mapped to the machine may be temporarily routed to a general purpose pool of machines until the machine is no longer overloaded or inoperative due to maintenance.

In an embodiment, the size of a machine pool associated with a shard may be dynamically varied in response to load demands or expected load demands. For example, the number of machines allotted to the machine pool may be increased or decreased dynamically to account for higher or lower load demands, respectively. In some instance, the size of the machine pool may vary based on expected time-of-day load changes. In some instances, the size of the machine pool may vary in response to unexpected load surges, such as load surges due to a community emergency for instance.

In some instances, certain users, communities, or chards may induce unexpectedly high loads. For example, a user may be a celebrity or public figure that receives sudden nationwide attention, drawing many queries to the user's account at the same time. The sudden and excessive increase in load demand put on the machine or shard associated with the user's account may be disruptive. The size of a machine pool associated with the user or shard may be dynamically increased to accommodate the increased load demand. In an embodiment, queries may be routed to a general purpose pool of machines to help alleviate the load demand. In some instances, the queries are routed to the general purpose pool of machines until the machine pool associated with the user or shard has been dynamically resized.

In some instances, load demands may be generated by users that are not effectively linked to a community of users or that do not have an associated unique ID, such as anonymous users, users without any friends, users not logged in, search engine scrapers, etc. Because these users are not effectively associated with a community or unique ID, the load demands they generate may not necessarily benefit from, or contribute to, some of the load and performance benefits described herein. In an embodiment, queries from such users may be routed to a general purpose pool of machines, a dedicated machine pool for these types of non-social users, or load balanced across an entire set of machines in a machine pool or in multiple machine pools.

Mappings between users to communities, unique IDs, or to shards may at times change significantly, such as due to an alteration of the clustering or to the way the node graph is partitioned. To reduce the impact of deploying a new map with significant changes to the previous map, updates may be deployed gradually or at times of reduced traffic or load, such as during global off peak hours. In an embodiment, a version identifier may be used in conjunction with the unique IDs, identifiers for communities, or identifiers of shards in order to uniquely identify which map is being utilized for a current query.

FIG. 8illustrates an example process of mapping users to a machines based on load balancing considerations, according to an embodiment. At block802, loads and usage times of machines are monitored. The monitoring may be dynamic—e.g., determined as queries are received. For example, if a query is received and initially mapped to a machine (or plurality of closely associated machines, such as a machine pool), the current load on the machine may be monitored first to determine if it is overloaded. In another example, the usage patterns of geographic locations are monitored. In an embodiment, block802may be performed by the load monitoring module706ofFIG. 7.

At block804, users or geographic locations that may improve their loads by reallocation are identified. This may include identifying machines with high loads or identifying machines with low loads. These loads may, for instance, vary based on the dynamic changes in usage traffic at any given time (e.g., a machine has too many queries at once). The loads may also be identified based on any types of usage patterns. The usage patterns may be identified based on one or more time periods of usage, such as 12 hour periods, 8 hour periods, 4 hour periods, etc.

At block806, the appropriate reallocation of users or geographic locations that is beneficial to load balancing is determined. For example, with respect to execution of a query, if the initial mapping is to a machine that is overloaded, then the query may be mapped to another machine that is underloaded. As another example, two or more groups of geographic locations may be banded together based on their complementary usage patterns in order to optimize the balancing of loads. The geographic locations may be banded together in any number of permutations which mix and match various numbers of geographic locations and various time intervals to optimize the load balance for varying usage patterns. In an embodiment, blocks804and806may be performed by the load monitoring module706and temporal balancing module708ofFIG. 7.

At block808, users are mapped to machines based on the reallocation in block806. With respect to banded geographic locations, the users of the banded geographic locations are mapped and routed according to the optimized configuration determined in block806. For instance, two complementary geographic locations with opposite usage patterns may be mapped and routed to the same machine.

FIG. 9illustrates an example process of routing a query to a machine (or plurality of closely associated machines, such as a machine pool), according to an embodiment. It should be appreciated that the discussion above forFIGS. 6-8may also apply to the process forFIG. 9. For the sake of brevity and clarity, similar features and functions are not repeated here forFIG. 9, but may be equally applicable.

At block902of process900, a query (or request) is received. For example, the system may receive a query initiated by a user of a social networking system. The query may include a user ID for the user along with the query. At block904, a unique ID is determined from the user ID. For example, a mapping from the user ID to the unique ID may be used to convert the user ID to a unique ID. At block906, a shard number may be determined based on the unique ID. For example, the shard number may be determined based on a partition size, as described herein. In an embodiment, blocks902,904, and906may be performed by the shard determination module702ofFIG. 7.

At block908, the shard number may be mapped to a physical machine (or plurality of closely associated machines). In one embodiment, the shard number is mapped to a physical machine based on equal divisions of the unique ID space to physical machines. In an embodiment, the shard number is mapped to a physical machine based on unequal divisions of the unique ID space. In an embodiment, load balancing considerations, as discussed in more detail herein, may also be taken into consideration for the mapping of the shard number to a physical machine.

At block910, a machine is selected. If the shard number is mapped to a plurality of machines, such as a machine pool, then one of the machines is selected. At block912, it is determined if the selected machine dynamically rejects the query. If the query is not rejected by the selected machine, then the query is routed to the selected machine and executed by the selected machine at block914. However, if the query is rejected by the selected machine, then another machine may be selected, as represented by the arrow from block912back to block910. For example, if the first machine selected from the plurality of machine is rejected, then another machine from the plurality of machines may be selected. This selection process may continue until one of the machines from the plurality of machine accepts the query. In an embodiment, if no machine from the plurality of machines can be selected to successfully receive the query (e.g., due to overload or maintenance), then the query may be routed to a general purpose pool of machines. If the shard number was mapped to a single machine at block908, and that machine rejects the query, then an alternate machine may be selected to receive the query, such as a machine from a general purpose pool of machines. In another embodiment, if a query is rejected by a selected machine, the query may be resent to the same machine after a predetermined waiting period. In an embodiment, blocks908,910,912, and914may be performed by the routing module704, the load monitoring module706, and the temporal balancing module708ofFIG. 7.

Social Networking System—Example Implementation

FIG. 10is a network diagram of an example system1000for substituting video links within a social network in accordance with an embodiment of the invention. The system1000includes one or more user devices1010, one or more external systems1020, a social networking system1030, and a network1050. In an embodiment, the social networking system discussed in connection with the embodiments described above may be implemented as the social networking system1030. For purposes of illustration, the embodiment of the system1000, shown byFIG. 10, includes a single external system1020and a single user device1010. However, in other embodiments, the system1000may include more user devices1010and/or more external systems1020. In certain embodiments, the social networking system1030is operated by a social network provider, whereas the external systems1020are separate from the social networking system1030in that they may be operated by different entities. In various embodiments, however, the social networking system1030and the external systems1020operate in conjunction to provide social networking services to users (or members) of the social networking system1030. In this sense, the social networking system1030provides a platform or backbone, which other systems, such as external systems1020, may use to provide social networking services and functionalities to users across the Internet.

The user device1010comprises one or more computing devices that can receive input from a user and transmit and receive data via the network1050. In one embodiment, the user device1010is a conventional computer system executing, for example, a Microsoft Windows compatible operating system (OS), Apple OS X, and/or a Linux distribution. In another embodiment, the user device1010can be a device having computer functionality, such as a smart-phone, a tablet, a personal digital assistant (PDA), a mobile telephone, etc. The user device1010is configured to communicate via the network1050. The user device1010can execute an application, for example, a browser application that allows a user of the user device1010to interact with the social networking system1030. In another embodiment, the user device1010interacts with the social networking system1030through an application programming interface (API) provided by the native operating system of the user device1010, such as iOS and ANDROID. The user device1010is configured to communicate with the external system1020and the social networking system1030via the network1050, which may comprise any combination of local area and/or wide area networks, using wired and/or wireless communication systems.

In one embodiment, the user device1010may display content from the external system1020and/or from the social networking system1030by processing a markup language document1014received from the external system1020and from the social networking system1030using a browser application1012. The markup language document1014identifies content and one or more instructions describing formatting or presentation of the content. By executing the instructions included in the markup language document1014, the browser application1012displays the identified content using the format or presentation described by the markup language document1014. For example, the markup language document1014includes instructions for generating and displaying a web page having multiple frames that include text and/or image data retrieved from the external system1020and the social networking system1030. In various embodiments, the markup language document1014comprises a data file including extensible markup language (XML) data, extensible hypertext markup language (XHTML) data, or other markup language data. Additionally, the markup language document1014may include JavaScript Object Notation (JSON) data, JSON with padding (JSONP), and JavaScript data to facilitate data-interchange between the external system1020and the user device1010. The browser application1012on the user device1010may use a JavaScript compiler to decode the markup language document1014.

The markup language document1014may also include, or link to, applications or application frameworks such as FLASH™ or Unity™ applications, the SilverLight™ application framework, etc.

In one embodiment, the user device1010also includes one or more cookies1016including data indicating whether a user of the user device1010is logged into the social networking system1030, which may enable modification of the data communicated from the social networking system1030to the user device1010.

The external system1020includes one or more web servers that include one or more web pages1022a,1022b, which are communicated to the user device1010using the network1050. The external system1020is separate from the social networking system1030. For example, the external system1020is associated with a first domain, while the social networking system1030is associated with a separate social networking domain. Web pages1022a,1022b, included in the external system1020, comprise markup language documents1014identifying content and including instructions specifying formatting or presentation of the identified content.

The social networking system1030includes one or more computing devices for a social network, including a plurality of users, and providing users of the social network with the ability to communicate and interact with other users of the social network. In some instances, the social network can be represented by a graph, i.e., a data structure including edges and nodes. Other data structures can also be used to represent the social network, including but not limited to databases, objects, classes, meta elements, files, or any other data structure. The social networking system1030may be administered, managed, or controlled by an operator. The operator of the social networking system1030may be a human being, an automated application, or a series of applications for managing content, regulating policies, and collecting usage metrics within the social networking system1030. Any type of operator may be used.

Users may join the social networking system1030and then add connections to any number of other users of the social networking system1030to whom they desire to be connected. As used herein, the term “friend” refers to any other user of the social networking system1030to whom a user has formed a connection, association, or relationship via the social networking system1030. For example, in an embodiment, if users in the social networking system1030are represented as nodes in the social graph, the term “friend” can refer to an edge formed between and directly connecting two user nodes.

In addition to establishing and maintaining connections between users and allowing interactions between users, the social networking system1030provides users with the ability to take actions on various types of items supported by the social networking system1030. These items may include groups or networks (i.e., social networks of people, entities, and concepts) to which users of the social networking system1030may belong, events or calendar entries in which a user might be interested, computer-based applications that a user may use via the social networking system1030, transactions that allow users to buy or sell items via services provided by or through the social networking system1030, and interactions with advertisements that a user may perform on or off the social networking system1030. These are just a few examples of the items upon which a user may act on the social networking system1030, and many others are possible. A user may interact with anything that is capable of being represented in the social networking system1030or in the external system1020, separate from the social networking system1030, or coupled to the social networking system1030via the network1050.

The social networking system1030also includes user-generated content, which enhances a user's interactions with the social networking system1030. User-generated content may include anything a user can add, upload, send, or “post” to the social networking system1030. For example, a user communicates posts to the social networking system1030from a user device1010. Posts may include data such as status updates or other textual data, location information, images such as photos, videos, links, music or other similar data and/or media. Content may also be added to the social networking system1030by a third party. Content “items” are represented as objects in the social networking system1030. In this way, users of the social networking system1030are encouraged to communicate with each other by posting text and content items of various types of media through various communication channels. Such communication increases the interaction of users with each other and increases the frequency with which users interact with the social networking system1030.

The social networking system1030includes a web server1032, an API request server1034, a user profile store1036, a connection store1038, an action logger1040, an activity log1042, an authorization server1044, and a video substitution module1046. In an embodiment of the invention, the social networking system1030may include additional, fewer, or different components for various applications. Other components, such as network interfaces, security mechanisms, load balancers, failover servers, management and network operations consoles, and the like are not shown so as to not obscure the details of the system.

The user profile store1036maintains information about user accounts, including biographic, demographic, and other types of descriptive information, such as work experience, educational history, hobbies or preferences, location, and the like that has been declared by users or inferred by the social networking system1030. This information is stored in the user profile store1036such that each user is uniquely identified. The social networking system1030also stores data describing one or more connections between different users in the connection store1038. The connection information may indicate users who have similar or common work experience, group memberships, hobbies, or educational history. Additionally, the social networking system1030includes user-defined connections between different users, allowing users to specify their relationships with other users. For example, user-defined connections allow users to generate relationships with other users that parallel the users' real-life relationships, such as friends, co-workers, partners, and so forth. Users may select from predefined types of connections, or define their own connection types as needed. Connections with other nodes in the social networking system1030, such as non-person entities, buckets, cluster centers, images, interests, pages, external systems, concepts, and the like are also stored in the connection store1038.

The social networking system1030maintains data about objects with which a user may interact. To maintain this data, the user profile store1036and the connection store1038store instances of the corresponding type of objects maintained by the social networking system1030. Each object type has information fields that are suitable for storing information appropriate to the type of object. For example, the user profile store1036contains data structures with fields suitable for describing a user's account and information related to a user's account. When a new object of a particular type is created, the social networking system1030initializes a new data structure of the corresponding type, assigns a unique object identifier to it, and begins to add data to the object as needed. This might occur, for example, when a user becomes a user of the social networking system1030, the social networking system1030generates a new instance of a user profile in the user profile store1036, assigns a unique identifier to the user account, and begins to populate the fields of the user account with information provided by the user.

The connection store1038includes data structures suitable for describing a user's connections to other users, connections to external systems1020or connections to other entities. The connection store1038may also associate a connection type with a user's connections, which may be used in conjunction with the user's privacy setting to regulate access to information about the user. In an embodiment of the invention, the user profile store1036and the connection store1038may be implemented as a federated database.

Data stored in the connection store1038, the user profile store1036, and the activity log1042enables the social networking system1030to generate the social graph that uses nodes to identify various objects and edges connecting nodes to identify relationships between different objects. For example, if a first user establishes a connection with a second user in the social networking system1030, user accounts of the first user and the second user from the user profile store1036may act as nodes in the social graph. The connection between the first user and the second user stored by the connection store1038is an edge between the nodes associated with the first user and the second user. Continuing this example, the second user may then send the first user a message within the social networking system1030. The action of sending the message, which may be stored, is another edge between the two nodes in the social graph representing the first user and the second user. Additionally, the message itself may be identified and included in the social graph as another node connected to the nodes representing the first user and the second user.

In another example, a first user may tag a second user in an image that is maintained by the social networking system1030(or, alternatively, in an image maintained by another system outside of the social networking system1030). The image may itself be represented as a node in the social networking system1030. This tagging action may create edges between the first user and the second user as well as create an edge between each of the users and the image, which is also a node in the social graph. In yet another example, if a user confirms attending an event, the user and the event are nodes obtained from the user profile store1036, where the attendance of the event is an edge between the nodes that may be retrieved from the activity log1042. By generating and maintaining the social graph, the social networking system1030includes data describing many different types of objects and the interactions and connections among those objects, providing a rich source of socially relevant information.

The web server1032links the social networking system1030to one or more user devices1010and/or one or more external systems1020via the network1050. The web server1032serves web pages, as well as other web-related content, such as Java, JavaScript, Flash, XML, and so forth. The web server1032may include a mail server or other messaging functionality for receiving and routing messages between the social networking system1030and one or more user devices1010. The messages can be instant messages, queued messages (e.g., email), text and SMS messages, or any other suitable messaging format.

The API request server1034allows one or more external systems1020and user devices1010to call access information from the social networking system1030by calling one or more API functions. The API request server1034may also allow external systems1020to send information to the social networking system1030by calling APIs. The external system1020, in one embodiment, sends an API request to the social networking system1030via the network1050, and the API request server1034receives the API request. The API request server1034processes the request by calling an API associated with the API request to generate an appropriate response, which the API request server1034communicates to the external system1020via the network1050. For example, responsive to an API request, the API request server1034collects data associated with a user, such as the user's connections that have logged into the external system1020, and communicates the collected data to the external system1020. In another embodiment, the user device1010communicates with the social networking system1030via APIs in the same manner as external systems1020.

The action logger1040is capable of receiving communications from the web server1032about user actions on and/or off the social networking system1030. The action logger1040populates the activity log1042with information about user actions, enabling the social networking system1030to discover various actions taken by its users within the social networking system1030and outside of the social networking system1030. Any action that a particular user takes with respect to another node on the social networking system1030may be associated with each user's account, through information maintained in the activity log1042or in a similar database or other data repository. Examples of actions taken by a user within the social networking system1030that are identified and stored may include, for example, adding a connection to another user, sending a message to another user, reading a message from another user, viewing content associated with another user, attending an event posted by another user, posting an image, attempting to post an image, or other actions interacting with another user or another object. When a user takes an action within the social networking system1030, the action is recorded in the activity log1042. In one embodiment, the social networking system1030maintains the activity log1042as a database of entries. When an action is taken within the social networking system1030, an entry for the action is added to the activity log1042. The activity log1042may be referred to as an action log.

Additionally, user actions may be associated with concepts and actions that occur within an entity outside of the social networking system1030, such as an external system1020that is separate from the social networking system1030. For example, the action logger1040may receive data describing a user's interaction with an external system1020from the web server1032. In this example, the external system1020reports a user's interaction according to structured actions and objects in the social graph.

Other examples of actions where a user interacts with an external system1020include a user expressing an interest in an external system1020or another entity, a user posting a comment to the social networking system1030that discusses an external system1020or a web page1022awithin the external system1020, a user posting to the social networking system1030a Uniform Resource Locator (URL) or other identifier associated with an external system1020, a user attending an event associated with an external system1020, or any other action by a user that is related to an external system1020. Thus, the activity log1042may include actions describing interactions between a user of the social networking system1030and an external system1020that is separate from the social networking system1030.

The authorization server1044contains logic to determine if certain information associated with a user can be accessed by a user's friends, external systems1020, and/or other applications and entities. The external system1020may need authorization from the authorization server1044to access the user's more private and sensitive information, such as the user's work phone number. Based on the user's privacy settings, the authorization server1044determines if another user, the external system1020, an application, or another entity is allowed to access information associated with the user, including information about actions taken by the user.

The social networking system1030may include clustering module1046. The clustering module1046may generate unique IDs and assign them to nodes of a social graph. Furthermore, the clustering module1046may utilize the unique IDs to partition the social graph over the social networking system1030. The unique ID space may be used to map users to machines (e.g., database servers or caching systems) of the social networking system1030. The clustering module1046may route users of the social networking system1030to the machines based on the mapping. The clustering module1046may map or route users to machines based on load balancing considerations, such as traffic usage patterns, or whether machines are overloaded or underloaded. In an embodiment, the clustering module1046may be implemented as the clustering module1046ofFIG. 1.

Hardware Implementation

The foregoing processes and features can be implemented by a wide variety of machine and computer system architectures and in a wide variety of network and computing environments.FIG. 11illustrates an example of a computer system1100that may be used to implement one or more of the embodiments described herein in accordance with an embodiment of the invention. The computer system1100includes sets of instructions for causing the computer system1100to perform the processes and features discussed herein. The computer system1100may be connected (e.g., networked) to other machines. In a networked deployment, the computer system1100may operate in the capacity of a server machine or a client machine in a client-server network environment, or as a peer machine in a peer-to-peer (or distributed) network environment. In an embodiment of the invention, the computer system1100may be a component of the social networking system described herein. In an embodiment of the invention, the computer system1100may be one server among many that constitutes all or part of the social networking system730.

The computer system1100includes a processor1102, a cache1104, and one or more executable modules and drivers, stored on a computer-readable medium, directed to the processes and features described herein. Additionally, the computer system1100includes a high performance input/output (I/O) bus1106and a standard I/O bus1108. A host bridge1110couples processor1102to high performance I/O bus1106, whereas I/O bus bridge1112couples the two buses1106and1108to each other. A system memory1114and one or more network interfaces1116couple to high performance I/O bus1106. The computer system1100may further include video memory and a display device coupled to the video memory (not shown). Mass storage1118and I/O ports1120couple to the standard I/O bus1108. The computer system1100may optionally include a keyboard and pointing device, a display device, or other input/output devices (not shown) coupled to the standard I/O bus1108. Collectively, these elements are intended to represent a broad category of computer hardware systems, including but not limited to computer systems based on the x86-compatible processors manufactured by Intel Corporation of Santa Clara, Calif., and the x86-compatible processors manufactured by Advanced Micro Devices (AMD), Inc., of Sunnyvale, Calif., as well as any other suitable processor.

The elements of the computer system1100are described in greater detail below. In particular, the network interface1116provides communication between the computer system1100and any of a wide range of networks, such as an Ethernet (e.g., IEEE 802.3) network, a backplane, etc. The mass storage1118provides permanent storage for the data and programming instructions to perform the above-described processes and features implemented by the respective computing systems identified above, whereas the system memory1114(e.g., DRAM) provides temporary storage for the data and programming instructions when executed by the processor1102. The I/O ports1120may be one or more serial and/or parallel communication ports that provide communication between additional peripheral devices, which may be coupled to the computer system1100.

The computer system1100may include a variety of system architectures, and various components of the computer system1100may be rearranged. For example, the cache1104may be on-chip with processor1102. Alternatively, the cache1104and the processor1102may be packed together as a “processor module”, with processor1102being referred to as the “processor core”. Furthermore, certain embodiments of the invention may neither require nor include all of the above components. For example, peripheral devices coupled to the standard I/O bus1108may couple to the high performance I/O bus1106. In addition, in some embodiments, only a single bus may exist, with the components of the computer system1100being coupled to the single bus. Furthermore, the computer system1100may include additional components, such as additional processors, storage devices, or memories.

In general, the processes and features described herein may be implemented as part of an operating system or a specific application, component, program, object, module, or series of instructions referred to as “programs”. For example, one or more programs may be used to execute specific processes described herein. The programs typically comprise one or more instructions in various memory and storage devices in the computer system1100that, when read and executed by one or more processors, cause the computer system1100to perform operations to execute the processes and features described herein. The processes and features described herein may be implemented in software, firmware, hardware (e.g., an application specific integrated circuit), or any combination thereof.

In one implementation, the processes and features described herein are implemented as a series of executable modules run by the computer system1100, individually or collectively in a distributed computing environment. The foregoing modules may be realized by hardware, executable modules stored on a computer-readable medium (or machine-readable medium), or a combination of both. For example, the modules may comprise a plurality or series of instructions to be executed by a processor in a hardware system, such as the processor1102. Initially, the series of instructions may be stored on a storage device, such as the mass storage1118. However, the series of instructions can be stored on any suitable computer readable storage medium. Furthermore, the series of instructions need not be stored locally, and could be received from a remote storage device, such as a server on a network, via the network interface1116. The instructions are copied from the storage device, such as the mass storage1118, into the system memory1114and then accessed and executed by the processor1102. In various implementations, a module or modules can be executed by a processor or multiple processors in one or multiple locations, such as multiple servers in a parallel processing environment.