Skip to content

Commit 8243205

Browse files
committed
Made like generation more memory efficient
1 parent ce45f3f commit 8243205

30 files changed

+164
-115
lines changed

src/main/java/ldbc/snb/datagen/generator/CommentGenerator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public class CommentGenerator {
2929
public CommentGenerator(TextGenerator generator, LikeGenerator likeGenerator){
3030
this.generator = generator;
3131
this.likeGenerator_ = likeGenerator;
32-
}
32+
}
3333

34-
public long createComments(RandomGeneratorFarm randomFarm, Forum forum, Post post, long numComments, long startId, PersonActivityExporter exporter){
34+
public long createComments(RandomGeneratorFarm randomFarm, final Forum forum, final Post post, long numComments, long startId, PersonActivityExporter exporter){
3535
long nextId = startId;
3636
ArrayList<Message> replyCandidates = new ArrayList<Message>();
3737
replyCandidates.add(post);
@@ -98,6 +98,7 @@ public long createComments(RandomGeneratorFarm randomFarm, Forum forum, Post pos
9898
}
9999
}
100100
}
101+
replyCandidates.clear();
101102
return nextId;
102103
}
103104

src/main/java/ldbc/snb/datagen/generator/FlashmobPostGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private void populateForumFlashmobTags( Random randomNumPost, Forum forum ) {
100100
}
101101
}
102102

103-
protected PostGenerator.PostInfo generatePostInfo( Random randomTag, Random randomDate, Forum forum, ForumMembership membership ) {
103+
protected PostGenerator.PostInfo generatePostInfo( Random randomTag, Random randomDate, final Forum forum, final ForumMembership membership ) {
104104
if( currentForum != forum.id() ) {
105105
populateForumFlashmobTags(randomTag,forum);
106106
currentForum = forum.id();

src/main/java/ldbc/snb/datagen/generator/LikeGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
public class LikeGenerator {
2424
private double maxNumberOfLikes;
2525
private final PowerDistGenerator likesGenerator_;
26+
private Like like;
2627

27-
2828

2929
public LikeGenerator() {
3030
likesGenerator_ = new PowerDistGenerator(1,DatagenParams.maxNumLike,0.07);
31+
this.like = new Like();
3132
}
3233

33-
public void generateLikes(Random random, Forum forum, Message message, LikeType type, PersonActivityExporter exporter) {
34+
public void generateLikes(Random random, final Forum forum, final Message message, LikeType type, PersonActivityExporter exporter) {
3435
int numMembers = forum.memberships().size();
3536
int numLikes = likesGenerator_.getValue(random);
3637
numLikes = numLikes >= numMembers ? numMembers : numLikes;
@@ -44,7 +45,6 @@ public void generateLikes(Random random, Forum forum, Message message, LikeType
4445
long minDate = message.creationDate() > memberships.get(startIndex+i).creationDate() ? message.creationDate() : membership.creationDate();
4546
long date = Math.max(Dictionaries.dates.randomSevenDays(random),DatagenParams.deltaTime) + minDate;
4647
if( date <= Dictionaries.dates.getEndDateTime() ) {
47-
Like like = new Like();
4848
like.user = membership.person().accountId();
4949
like.userCreationDate = membership.person().creationDate();
5050
like.messageId = message.messageId();

src/main/java/ldbc/snb/datagen/generator/PersonActivityGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ public PersonActivityGenerator( PersonActivitySerializer serializer, UpdateEvent
4949
}
5050

5151
private void generateActivity( Person person, ArrayList<Person> block ) {
52+
System.out.println("Generating wall");
5253
generateWall(person, block);
54+
System.out.println("Generating groups");
5355
generateGroups(person, block);
56+
System.out.println("Generating albums");
5457
generateAlbums(person, block);
5558
if(person.creationDate() < Dictionaries.dates.getUpdateThreshold() || !DatagenParams.updateStreams ) {
5659
factorTable_.extractFactors(person);

src/main/java/ldbc/snb/datagen/generator/PhotoGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class PhotoGenerator {
2727
public PhotoGenerator(LikeGenerator likeGenerator) {
2828
this.likeGenerator_ = likeGenerator;
2929
}
30-
public long createPhotos(RandomGeneratorFarm randomFarm, Forum album, ArrayList<ForumMembership> memberships, long numPhotos, long startId, PersonActivityExporter exporter){
30+
public long createPhotos(RandomGeneratorFarm randomFarm, final Forum album, final ArrayList<ForumMembership> memberships, long numPhotos, long startId, PersonActivityExporter exporter){
3131
long nextId = startId;
3232
ArrayList<Photo> photos = new ArrayList<Photo>();
3333
int numPopularPlaces = randomFarm.get(RandomGeneratorFarm.Aspect.NUM_POPULAR).nextInt(DatagenParams.maxNumPopularPlaces + 1);

src/main/java/ldbc/snb/datagen/generator/PostGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void initialize() {
7878
}
7979

8080

81-
public long createPosts(RandomGeneratorFarm randomFarm, Forum forum, ArrayList<ForumMembership> memberships, long numPosts, long startId, PersonActivityExporter exporter){
81+
public long createPosts(RandomGeneratorFarm randomFarm, final Forum forum, final ArrayList<ForumMembership> memberships, long numPosts, long startId, PersonActivityExporter exporter){
8282
long postId = startId;
8383
Properties prop = new Properties();
8484
prop.setProperty("type","post");
@@ -123,5 +123,5 @@ public long createPosts(RandomGeneratorFarm randomFarm, Forum forum, ArrayList<F
123123
return postId;
124124
}
125125

126-
protected abstract PostInfo generatePostInfo( Random randomTag, Random randomDate, Forum forum, ForumMembership membership );
126+
protected abstract PostInfo generatePostInfo( Random randomTag, Random randomDate, final Forum forum, final ForumMembership membership );
127127
}

src/main/java/ldbc/snb/datagen/generator/UniformPostGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public UniformPostGenerator(TextGenerator generator, CommentGenerator commentGen
2525
}
2626

2727
@Override
28-
protected PostInfo generatePostInfo( Random randomTag, Random randomDate, Forum forum, ForumMembership membership ) {
28+
protected PostInfo generatePostInfo( Random randomTag, Random randomDate, final Forum forum, final ForumMembership membership ) {
2929
PostInfo postInfo = new PostInfo();
3030
postInfo.tags = new TreeSet<Integer>();
3131
Iterator<Integer> it = forum.tags().iterator();

src/main/java/ldbc/snb/datagen/hadoop/HadoopPersonActivityGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ public void run( String inputFileName ) throws Exception {
143143
job.setPartitionerClass(HadoopBlockPartitioner.class);
144144

145145
/** PROFILING OPTIONS **/
146-
job.setProfileEnabled(true);
147-
job.setProfileParams("-agentlib:hprof=cpu=samples,heap=sites,depth=4,thread=y,format=b,file=%s");
148-
job.setProfileTaskRange(true,"0-1");
149-
job.setProfileTaskRange(false,"0-1");
146+
//job.setProfileEnabled(true);
147+
//job.setProfileParams("-agentlib:hprof=cpu=samples,heap=sites,depth=4,thread=y,format=b,file=%s");
148+
//job.setProfileTaskRange(true,"0-1");
149+
//job.setProfileTaskRange(false,"0-1");
150150
/****/
151151

152152
FileInputFormat.setInputPaths(job, new Path(rankedFileName));

src/main/java/ldbc/snb/datagen/objects/Comment.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public class Comment extends Message {
4646
private long postId_;
4747
private long replyOf_;
4848

49+
public Comment() {
50+
super();
51+
}
52+
4953
public Comment(long commentId,
5054
long creationDate,
5155
PersonSummary author,
@@ -63,6 +67,21 @@ public Comment(long commentId,
6367
replyOf_ = replyOf;
6468
}
6569

70+
public void initialize(long commentId,
71+
long creationDate,
72+
PersonSummary author,
73+
long forumId,
74+
String content,
75+
TreeSet<Integer> tags,
76+
IP ipAddress,
77+
int browserId,
78+
long postId,
79+
long replyOf) {
80+
super.initialize(commentId, creationDate, author, forumId, content, tags, ipAddress, browserId);
81+
postId_ = postId;
82+
replyOf_ = replyOf;
83+
}
84+
6685
public long postId() {
6786
return postId_;
6887
}

src/main/java/ldbc/snb/datagen/objects/Message.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ abstract public class Message {
5353
private int browserId_;
5454
private int countryId_;
5555

56+
public Message() {
57+
tags_ = new TreeSet<Integer>();
58+
ipAddress_ = new IP();
59+
}
60+
5661
public Message(long messageId,
5762
long creationDate,
5863
PersonSummary author,
@@ -73,6 +78,27 @@ public Message(long messageId,
7378
countryId_ = Dictionaries.ips.getLocation(ipAddress);
7479
}
7580

81+
public void initialize(long messageId,
82+
long creationDate,
83+
PersonSummary author,
84+
long forumId,
85+
String content,
86+
TreeSet<Integer> tags,
87+
IP ipAddress,
88+
int browserId
89+
) {
90+
messageId_ = messageId;
91+
creationDate_ = creationDate;
92+
author_ = new PersonSummary(author);
93+
forumId_ = forumId;
94+
content_ = content;
95+
tags_.clear();
96+
tags_.addAll(tags);
97+
ipAddress_.copy(ipAddress);
98+
browserId_ = browserId;
99+
countryId_ = Dictionaries.ips.getLocation(ipAddress);
100+
}
101+
76102
public long messageId() {
77103
return messageId_;
78104
}

0 commit comments

Comments
 (0)