Skip to content

Commit a7259fb

Browse files
committed
IMproved memory usage during person activity generation
1 parent 8243205 commit a7259fb

File tree

6 files changed

+59
-8
lines changed

6 files changed

+59
-8
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ public class CommentGenerator {
2424
private String[] shortComments_ = {"ok", "good", "great", "cool", "thx", "fine", "LOL", "roflol", "no way!", "I see", "right", "yes", "no", "duh", "thanks", "maybe"};
2525
private TextGenerator generator;
2626
private LikeGenerator likeGenerator_;
27+
private Comment comment_;
2728
/* A set of random number generator for different purposes.*/
2829

2930
public CommentGenerator(TextGenerator generator, LikeGenerator likeGenerator){
3031
this.generator = generator;
3132
this.likeGenerator_ = likeGenerator;
33+
this.comment_ = new Comment();
3234
}
3335

3436
public long createComments(RandomGeneratorFarm randomFarm, final Forum forum, final Post post, long numComments, long startId, PersonActivityExporter exporter){
@@ -91,7 +93,7 @@ public long createComments(RandomGeneratorFarm randomFarm, final Forum forum, fi
9193
Dictionaries.browsers.getPostBrowserId(randomFarm.get(RandomGeneratorFarm.Aspect.DIFF_BROWSER), randomFarm.get(RandomGeneratorFarm.Aspect.BROWSER), member.person().browserId()),
9294
post.messageId(),
9395
replyTo.messageId());
94-
if(!isShort) replyCandidates.add(comment);
96+
if(!isShort) replyCandidates.add(new Comment(comment));
9597
exporter.export(comment);
9698
if( comment.content().length() > 10 && randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE).nextDouble() <= 0.1 ) {
9799
likeGenerator_.generateLikes(randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE), forum, comment, Like.LikeType.COMMENT, exporter);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
public class PhotoGenerator {
2222
private long postId = 0;
2323
private LikeGenerator likeGenerator_;
24+
private Photo photo_;
2425

2526
private static final String SEPARATOR = " ";
2627

2728
public PhotoGenerator(LikeGenerator likeGenerator) {
2829
this.likeGenerator_ = likeGenerator;
30+
this.photo_ = new Photo();
2931
}
3032
public long createPhotos(RandomGeneratorFarm randomFarm, final Forum album, final ArrayList<ForumMembership> memberships, long numPhotos, long startId, PersonActivityExporter exporter){
3133
long nextId = startId;
@@ -77,10 +79,10 @@ public long createPhotos(RandomGeneratorFarm randomFarm, final Forum album, fina
7779
long date = album.creationDate()+DatagenParams.deltaTime+1000*(i+1);
7880
if( date <= Dictionaries.dates.getEndDateTime() ) {
7981
long id = SN.formId(SN.composeId(nextId++,date));
80-
Photo photo = new Photo(id,date,album.moderator(), album.id(), "photo"+id+".jpg",tags,album.moderator().ipAddress(),album.moderator().browserId(),latt,longt);
81-
exporter.export(photo);
82+
photo_.initialize(id,date,album.moderator(), album.id(), "photo"+id+".jpg",tags,album.moderator().ipAddress(),album.moderator().browserId(),latt,longt);
83+
exporter.export(photo_);
8284
if( randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE).nextDouble() <= 0.1 ) {
83-
likeGenerator_.generateLikes(randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE), album, photo, Like.LikeType.PHOTO, exporter);
85+
likeGenerator_.generateLikes(randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE), album, photo_, Like.LikeType.PHOTO, exporter);
8486
}
8587
}
8688
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ abstract public class PostGenerator {
5454
private TextGenerator generator_;
5555
private CommentGenerator commentGenerator_;
5656
private LikeGenerator likeGenerator_;
57+
private Post post_;
5758

5859
static protected class PostInfo {
5960
public TreeSet<Integer> tags;
@@ -71,6 +72,7 @@ public PostGenerator( TextGenerator generator, CommentGenerator commentGenerator
7172
this.generator_ = generator;
7273
this.commentGenerator_ = commentGenerator;
7374
this.likeGenerator_ = likeGenerator;
75+
this.post_ = new Post();
7476
}
7577

7678
/** @brief Initializes the post generator.*/
@@ -99,7 +101,7 @@ public long createPosts(RandomGeneratorFarm randomFarm, final Forum forum, final
99101

100102
// crear properties class para passar
101103
content = this.generator_.generateText(member.person(), postInfo.tags,prop);
102-
Post post = new Post( SN.formId(SN.composeId(postId++,postInfo.date)),
104+
post_.initialize( SN.formId(SN.composeId(postId++,postInfo.date)),
103105
postInfo.date,
104106
member.person(),
105107
forum.id(),
@@ -108,15 +110,15 @@ public long createPosts(RandomGeneratorFarm randomFarm, final Forum forum, final
108110
Dictionaries.ips.getIP(randomFarm.get(RandomGeneratorFarm.Aspect.IP), randomFarm.get(RandomGeneratorFarm.Aspect.DIFF_IP), randomFarm.get(RandomGeneratorFarm.Aspect.DIFF_IP_FOR_TRAVELER), member.person().ipAddress(), postInfo.date),
109111
Dictionaries.browsers.getPostBrowserId(randomFarm.get(RandomGeneratorFarm.Aspect.DIFF_BROWSER), randomFarm.get(RandomGeneratorFarm.Aspect.BROWSER), member.person().browserId()),
110112
forum.language());
111-
exporter.export(post);
113+
exporter.export(post_);
112114

113115
if( randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE).nextDouble() <= 0.1 ) {
114-
likeGenerator_.generateLikes(randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE), forum, post, Like.LikeType.POST, exporter);
116+
likeGenerator_.generateLikes(randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE), forum, post_, Like.LikeType.POST, exporter);
115117
}
116118

117119
//// generate comments
118120
int numComments = randomFarm.get(RandomGeneratorFarm.Aspect.NUM_COMMENT).nextInt(DatagenParams.maxNumComments+1);
119-
postId = commentGenerator_.createComments(randomFarm, forum, post, numComments, postId, exporter);
121+
postId = commentGenerator_.createComments(randomFarm, forum, post_, numComments, postId, exporter);
120122
}
121123
}
122124
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public Comment() {
5050
super();
5151
}
5252

53+
public Comment( Comment comment ) {
54+
super(comment.messageId(), comment.creationDate(), comment.author(), comment.forumId(), comment.content(), comment.tags(), comment.ipAddress(), comment.browserId());
55+
postId_ = comment.postId();
56+
replyOf_ = comment.replyOf();
57+
}
58+
5359
public Comment(long commentId,
5460
long creationDate,
5561
PersonSummary author,

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public class Photo extends Message {
4545
private double latt_;
4646
private double longt_;
4747

48+
public Photo() {
49+
super();
50+
}
51+
4852
public Photo(long messageId,
4953
long creationDate,
5054
PersonSummary author,
@@ -61,6 +65,23 @@ public Photo(long messageId,
6165
longt_ = longt;
6266
}
6367

68+
public void initialize(long messageId,
69+
long creationDate,
70+
PersonSummary author,
71+
long forumId,
72+
String content,
73+
TreeSet<Integer> tags,
74+
IP ipAddress,
75+
int browserId,
76+
double latt,
77+
double longt
78+
) {
79+
super.initialize(messageId, creationDate, author, forumId, content, tags, ipAddress, browserId);
80+
latt_ = latt;
81+
longt_ = longt;
82+
}
83+
84+
6485
public double latt() {
6586
return latt_;
6687
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public class Post extends Message {
4848
* < @brief The language used in the post.
4949
*/
5050

51+
public Post() {
52+
super();
53+
}
54+
5155
public Post(long postId,
5256
long creationDate,
5357
PersonSummary author,
@@ -62,6 +66,20 @@ public Post(long postId,
6266
language_ = language;
6367
}
6468

69+
public void initialize(long postId,
70+
long creationDate,
71+
PersonSummary author,
72+
long forumId,
73+
String content,
74+
TreeSet<Integer> tags,
75+
IP ipAddress,
76+
int browserId,
77+
int language
78+
) {
79+
super.initialize(postId, creationDate, author, forumId, content, tags, ipAddress, browserId);
80+
language_ = language;
81+
}
82+
6583
public int language() {
6684
return language_;
6785
}

0 commit comments

Comments
 (0)