neo4j - Queries make Twitter-stream application too slow in saving data -
i have application streams twitter data stored in neo4j database. data store regard tweets, users, hashtag , relationships (user posts tweet, tweet tags hashtags, user retweets tweet). now, each time new tweet is:
- check if database contains tweet: if so, update new information (retweet count, count), else save it
- check if database contains user: if so, update new infos, else save it
- check if database contains hashtag: if doesn't, add it
and on, same process saving relationships.
here queries:
static string cqladdtweet = "merge (n:tweet{tweet_id: {2}}) on create set n.text={1}, n.location={3}, n.likecount={4}, n.retweetcount={5}, n.topic={6}, n.created_at={7} on match set n.likecount={4}, n.retweetcount={5}"; static string cqladdht = "merge (n:hashtag{text:{1}})"; static string cqlhttotweet = "match (n:tweet),(m:hashtag) n.tweet_id={1} , m.text={2} merge (n)-[:tags]->(m)"; static string cqladduser = "merge (n:user{user_id:{3}}) on create set n.name={1}, n.username={2}, n.followers={4}, n.following={5}, n.profilepic={6} on match set n.name={1}, n.username={2}, n.followers={4}, n.following={5}, n.profilepic={6}"; static string cqlusertotweet = "match (n:user),(m:tweet) m.tweet_id={2} , n.user_id={1} merge (n)-[:posts]->(m)"; static string cqluserretweets = "match (n:tweet{tweet_id:{1}}), (u:user{user_id:{2}}) create (u)-[:retweets]->(n)"; since slow in saving data, suppose system can have better performances if didn't run queries scan data each time.
do have suggestion improve application?
thank , excuse me in advance if may seem silly.
make sure have indexes (or uniqueness constraints, if appropriate) on following label/property pairs. allow queries avoid scanning through nodes same label (when starting query).
:tweet(tweet_id):hashtag(text):user(user_id)
by way, couple of queries can simplified (but should not affect performance):
static string cqladdtweet = "merge (n:tweet{tweet_id: {2}}) on create set n.text={1}, n.location={3}, n.topic={6}, n.created_at={7} set n.likecount={4}, n.retweetcount={5}"; static string cqladduser = "merge (n:user{user_id:{3}}) set n.name={1}, n.username={2}, n.followers={4}, n.following={5}, n.profilepic={6}";
Comments
Post a Comment